Skip to content

Commit

Permalink
simplify delete_metadata trait method (#232) (#233)
Browse files Browse the repository at this point in the history
Signed-off-by: tabokie <[email protected]>
  • Loading branch information
tabokie authored Jun 24, 2022
1 parent 605d329 commit 229b996
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,8 +1637,10 @@ mod tests {
Ok(())
}

fn delete_metadata<P: AsRef<Path>>(&self, path: P) -> std::io::Result<bool> {
Ok(self.inner.delete_metadata(&path)? | self.update_metadata(path.as_ref(), true))
fn delete_metadata<P: AsRef<Path>>(&self, path: P) -> std::io::Result<()> {
self.inner.delete_metadata(&path)?;
self.update_metadata(path.as_ref(), true);
Ok(())
}

fn exists_metadata<P: AsRef<Path>>(&self, path: P) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub trait FileSystem: Send + Sync {
/// going through user implemented cleanup procedure. This method is used to
/// detect and cleanup the user metadata that is no longer mapped to a
/// physical file.
fn delete_metadata<P: AsRef<Path>>(&self, _path: P) -> Result<bool> {
Ok(false)
fn delete_metadata<P: AsRef<Path>>(&self, _path: P) -> Result<()> {
Ok(())
}

/// Returns whether there is any user metadata associated with given `path`.
Expand Down
11 changes: 4 additions & 7 deletions src/file_pipe_log/pipe_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,11 @@ impl<F: FileSystem> DualPipesBuilder<F> {
for seq in start..min_id {
let file_id = FileId { queue, seq };
let path = file_id.build_file_path(dir);
match self.file_system.delete_metadata(&path) {
Err(e) => {
error!("failed to delete metadata of {}: {}.", path.display(), e);
break;
}
Ok(true) => success += 1,
_ => {}
if let Err(e) = self.file_system.delete_metadata(&path) {
error!("failed to delete metadata of {}: {}.", path.display(), e);
break;
}
success += 1;
}
warn!(
"deleted {} stale files of {:?} in range [{}, {}).",
Expand Down

0 comments on commit 229b996

Please sign in to comment.