diff --git a/components/tikv_util/src/file.rs b/components/tikv_util/src/file.rs index 342a4403688..4b9e06f9e69 100644 --- a/components/tikv_util/src/file.rs +++ b/components/tikv_util/src/file.rs @@ -46,8 +46,8 @@ pub fn create_dir_if_not_exist>(dir: P) -> io::Result { } } -/// Call fsync on file or directory by its path -pub fn fsync_by_path>(path: P) -> io::Result<()> { +/// Call fsync on directory by its path +pub fn sync_dir>(path: P) -> io::Result<()> { // File::open will not error when opening a directory // because it just call libc::open and do not do the file or dir check fs::File::open(path)?.sync_all() @@ -199,10 +199,10 @@ mod tests { } #[test] - fn test_fsync_by_path() { + fn test_sync_dir() { let tmp_dir = TempDir::new("").unwrap(); - fsync_by_path(tmp_dir.path()).unwrap(); + sync_dir(tmp_dir.path()).unwrap(); let non_existent_file = tmp_dir.path().join("non_existent_file"); - fsync_by_path(non_existent_file).unwrap_err(); + sync_dir(non_existent_file).unwrap_err(); } } diff --git a/src/raftstore/store/snap.rs b/src/raftstore/store/snap.rs index 03f0c6ab8e9..dc072d2553f 100644 --- a/src/raftstore/store/snap.rs +++ b/src/raftstore/store/snap.rs @@ -38,9 +38,7 @@ use crate::raftstore::Result as RaftStoreResult; use engine::rocks::util::io_limiter::{IOLimiter, LimitWriter}; use tikv_util::codec::bytes::{BytesEncoder, CompactBytesFromFileDecoder}; use tikv_util::collections::{HashMap, HashMapEntry as Entry}; -use tikv_util::file::{ - calc_crc32, delete_file_if_exist, file_exists, fsync_by_path, get_file_size, -}; +use tikv_util::file::{calc_crc32, delete_file_if_exist, file_exists, get_file_size, sync_dir}; use tikv_util::time::duration_to_sec; use tikv_util::HandyRwLock; @@ -650,7 +648,7 @@ impl Snap { // to indicate if the sst file is empty. if cf_file.kv_count > 0 { fs::rename(&cf_file.tmp_path, &cf_file.path)?; - fsync_by_path(&self.dir_path)?; + sync_dir(&self.dir_path)?; cf_file.size = size; // add size self.size_track.fetch_add(size, Ordering::SeqCst); @@ -672,7 +670,7 @@ impl Snap { f.flush()?; } fs::rename(&self.meta_file.tmp_path, &self.meta_file.path)?; - fsync_by_path(&self.dir_path)?; + sync_dir(&self.dir_path)?; self.hold_tmp_files = false; Ok(()) } @@ -963,7 +961,7 @@ impl Snapshot for Snap { fs::rename(&cf_file.tmp_path, &cf_file.path)?; self.size_track.fetch_add(cf_file.size, Ordering::SeqCst); } - fsync_by_path(&self.dir_path)?; + sync_dir(&self.dir_path)?; // write meta file let mut v = vec![]; self.meta_file.meta.write_to_vec(&mut v)?; @@ -973,7 +971,7 @@ impl Snapshot for Snap { meta_file.sync_all()?; } fs::rename(&self.meta_file.tmp_path, &self.meta_file.path)?; - fsync_by_path(&self.dir_path)?; + sync_dir(&self.dir_path)?; self.hold_tmp_files = false; Ok(()) }