MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / atomic_swap_dirs_fsync

Function atomic_swap_dirs_fsync

nodedb-wal/src/segment/atomic_io.rs:76–88  ·  view source on GitHub ↗

Atomically swap a directory: `rename(live, backup); rename(staged, live)`, fsyncing the parent directory once both renames have completed. `live`, `backup`, and `staged` MUST share the same parent directory. The caller is responsible for removing the backup directory once the new state is proven good — this helper does not delete anything.

(live: &Path, backup: &Path, staged: &Path)

Source from the content-addressed store, hash-verified

74/// caller is responsible for removing the backup directory once the new
75/// state is proven good — this helper does not delete anything.
76pub fn atomic_swap_dirs_fsync(live: &Path, backup: &Path, staged: &Path) -> Result<()> {
77 let parent = live.parent().ok_or_else(|| {
78 WalError::Io(std::io::Error::new(
79 std::io::ErrorKind::InvalidInput,
80 "atomic_swap_dirs_fsync: live has no parent directory",
81 ))
82 })?;
83
84 fs::rename(live, backup).map_err(WalError::Io)?;
85 fs::rename(staged, live).map_err(WalError::Io)?;
86 fsync_directory(parent)?;
87 Ok(())
88}
89
90/// Read a checkpoint file and advise the kernel to drop its pages from the
91/// page cache.

Callers 3

rewrite_partitionsFunction · 0.85
merge_o3_into_partitionFunction · 0.85

Calls 1

fsync_directoryFunction · 0.85

Tested by 1