From c3cc93406d9656a5674c2f62159f00516034710d Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Thu, 2 Dec 2021 13:39:06 +0900 Subject: [PATCH] Bugfix: adds missing fdatasync on atomic_write. 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 #1224 --- src/directory/mmap_directory.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/directory/mmap_directory.rs b/src/directory/mmap_directory.rs index 3d11b0334..51c16ed87 100644 --- a/src/directory/mmap_directory.rs +++ b/src/directory/mmap_directory.rs @@ -234,7 +234,7 @@ impl MmapDirectory { } let fd = open_opts.open(&self.inner.root_path)?; - fd.sync_all()?; + fd.sync_data()?; Ok(()) } @@ -288,8 +288,7 @@ impl Write for SafeFileWriter { } fn flush(&mut self) -> io::Result<()> { - self.0.flush()?; - self.0.sync_all() + Ok(()) } } @@ -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(()) } } @@ -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(()) }