Skip to content

Commit

Permalink
Only flush leaf_set if we have a prunable backend. (#2735)
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp authored Apr 9, 2019
1 parent 94732b0 commit 108bdba
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions store/src/pmmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ impl<T: PMMRable> PMMRBackend<T> {
/// Syncs all files to disk. A call to sync is required to ensure all the
/// data has been successfully written to disk.
pub fn sync(&mut self) -> io::Result<()> {
self.hash_file
.flush()
Ok(())
.and(self.hash_file.flush())
.and(self.data_file.flush())
.and(self.leaf_set.flush())
.and(self.sync_leaf_set())
.map_err(|e| {
io::Error::new(
io::ErrorKind::Interrupted,
Expand All @@ -273,11 +273,19 @@ impl<T: PMMRable> PMMRBackend<T> {
})
}

// Sync the leaf_set if this is a prunable backend.
fn sync_leaf_set(&mut self) -> io::Result<()> {
if !self.prunable {
return Ok(());
}
self.leaf_set.flush()
}

/// Discard the current, non synced state of the backend.
pub fn discard(&mut self) {
self.hash_file.discard();
self.leaf_set.discard();
self.data_file.discard();
self.leaf_set.discard();
}

/// Takes the leaf_set at a given cutoff_pos and generates an updated
Expand Down Expand Up @@ -344,8 +352,7 @@ impl<T: PMMRable> PMMRBackend<T> {
self.data_file.replace(Path::new(&tmp_prune_file_data))?;

// 6. Write the leaf_set to disk.
// Optimize the bitmap storage in the process.
self.leaf_set.flush()?;
self.sync_leaf_set()?;

// 7. cleanup rewind files
self.clean_rewind_files()?;
Expand Down

0 comments on commit 108bdba

Please sign in to comment.