Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only flush leaf_set if we have a prunable backend #2735

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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