Skip to content

Commit

Permalink
Bugfix: adds missing fdatasync on atomic_write.
Browse files Browse the repository at this point in the history
In addition this PR:
- removes unnecessary flushes and fsyncs on files.
- replace all fsync by fdatasync. The latter triggers
a meta sync if a metadata required to read the file
has changed. It is therefore sufficient for us.

Closes #1195
  • Loading branch information
fulmicoton committed Dec 2, 2021
1 parent bd0f921 commit 0c6b2b0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/directory/mmap_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl MmapDirectory {
}

let fd = open_opts.open(&self.inner.root_path)?;
fd.sync_all()?;
fd.sync_data()?;
Ok(())
}

Expand Down Expand Up @@ -288,8 +288,7 @@ impl Write for SafeFileWriter {
}

fn flush(&mut self) -> io::Result<()> {
self.0.flush()?;
self.0.sync_all()
Ok(())
}
}

Expand All @@ -301,7 +300,9 @@ impl Seek for SafeFileWriter {

impl TerminatingWrite for SafeFileWriter {
fn terminate_ref(&mut self, _: AntiCallToken) -> io::Result<()> {
self.flush()
self.0.flush()?;
self.0.sync_data()?;
Ok(())
}
}

Expand Down Expand Up @@ -331,6 +332,7 @@ pub(crate) fn atomic_write(path: &Path, content: &[u8]) -> io::Result<()> {
let mut tempfile = tempfile::Builder::new().tempfile_in(&parent_path)?;
tempfile.write_all(content)?;
tempfile.flush()?;
tempfile.as_file_mut().sync_data()?;
tempfile.into_temp_path().persist(path)?;
Ok(())
}
Expand Down

0 comments on commit 0c6b2b0

Please sign in to comment.