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

Function fsync_directory

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

Fsync a directory to ensure file creation/deletion metadata is durable. On ext4/XFS, creating or deleting a file writes the file data to disk but the directory entry may only be in the page cache. A power loss before the directory entry is persisted causes the file to "disappear" on reboot. Calling fsync on the directory fd ensures the metadata (filename, inode pointer) is on stable storage.

(dir: &Path)

Source from the content-addressed store, hash-verified

32/// on reboot. Calling fsync on the directory fd ensures the metadata
33/// (filename, inode pointer) is on stable storage.
34pub fn fsync_directory(dir: &Path) -> Result<()> {
35 let dir_file = fs::File::open(dir).map_err(WalError::Io)?;
36 dir_file.sync_all().map_err(WalError::Io)?;
37 Ok(())
38}
39
40/// Atomically write `bytes` to `dst` via a `tmp` file with full durability.
41///

Callers 4

roll_segmentMethod · 0.85
atomic_write_fsyncFunction · 0.85
atomic_swap_dirs_fsyncFunction · 0.85
truncate_segmentsFunction · 0.85

Calls 1

openFunction · 0.50

Tested by

no test coverage detected