Skip to content

Commit

Permalink
util: rename fsync_by_path to sync_dir
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Pig Chu <benpichu@gmail.com>
  • Loading branch information
benpigchu committed Jun 6, 2019
1 parent 4870bad commit d2f00d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 5 additions & 5 deletions components/tikv_util/src/file.rs
Expand Up @@ -46,8 +46,8 @@ pub fn create_dir_if_not_exist<P: AsRef<Path>>(dir: P) -> io::Result<bool> {
}
}

/// Call fsync on file or directory by its path
pub fn fsync_by_path<P: AsRef<Path>>(path: P) -> io::Result<()> {
/// Call fsync on directory by its path
pub fn sync_dir<P: AsRef<Path>>(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()
Expand Down Expand Up @@ -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();
}
}
12 changes: 5 additions & 7 deletions src/raftstore/store/snap.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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(())
}
Expand Down Expand Up @@ -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)?;
Expand All @@ -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(())
}
Expand Down

0 comments on commit d2f00d9

Please sign in to comment.