diff --git a/crates/fluvio-storage/src/checkpoint.rs b/crates/fluvio-storage/src/checkpoint.rs index 2ba1202c9bb..8c5cf83b7b2 100644 --- a/crates/fluvio-storage/src/checkpoint.rs +++ b/crates/fluvio-storage/src/checkpoint.rs @@ -3,6 +3,8 @@ use std::io::Cursor; use std::io::Error as IoError; use std::io::ErrorKind; use std::io::SeekFrom; +use std::os::fd::AsFd; +use std::os::fd::FromRawFd; use std::path::PathBuf; use std::sync::Arc; @@ -72,6 +74,15 @@ pub struct CheckPoint { file: File, } +impl Drop for CheckPoint { + fn drop(&mut self) { + let raw_fd = self.file.as_fd().as_raw_fd(); + let std_file = unsafe { std::fs::File::from_raw_fd(raw_fd) }; + std_file.sync_all().expect("sync checkpoint"); + std::mem::forget(std_file); + } +} + impl CheckPoint where T: Display + ReadToBuf + Clone + Sized + 'static, @@ -151,7 +162,6 @@ where self.offset = pos; self.offset.write_to(&mut contents); self.file.write_all(&contents).await?; - self.file.sync_all().await?; Ok(()) } }