mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
Only flush leaf_set if we have a prunable backend. (#2735)
This commit is contained in:
parent
94732b0d58
commit
108bdbaa73
1 changed files with 13 additions and 6 deletions
|
@ -261,10 +261,10 @@ impl<T: PMMRable> PMMRBackend<T> {
|
||||||
/// Syncs all files to disk. A call to sync is required to ensure all the
|
/// Syncs all files to disk. A call to sync is required to ensure all the
|
||||||
/// data has been successfully written to disk.
|
/// data has been successfully written to disk.
|
||||||
pub fn sync(&mut self) -> io::Result<()> {
|
pub fn sync(&mut self) -> io::Result<()> {
|
||||||
self.hash_file
|
Ok(())
|
||||||
.flush()
|
.and(self.hash_file.flush())
|
||||||
.and(self.data_file.flush())
|
.and(self.data_file.flush())
|
||||||
.and(self.leaf_set.flush())
|
.and(self.sync_leaf_set())
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
io::Error::new(
|
io::Error::new(
|
||||||
io::ErrorKind::Interrupted,
|
io::ErrorKind::Interrupted,
|
||||||
|
@ -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.
|
/// Discard the current, non synced state of the backend.
|
||||||
pub fn discard(&mut self) {
|
pub fn discard(&mut self) {
|
||||||
self.hash_file.discard();
|
self.hash_file.discard();
|
||||||
self.leaf_set.discard();
|
|
||||||
self.data_file.discard();
|
self.data_file.discard();
|
||||||
|
self.leaf_set.discard();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes the leaf_set at a given cutoff_pos and generates an updated
|
/// Takes the leaf_set at a given cutoff_pos and generates an updated
|
||||||
|
@ -344,8 +352,7 @@ impl<T: PMMRable> PMMRBackend<T> {
|
||||||
self.data_file.replace(Path::new(&tmp_prune_file_data))?;
|
self.data_file.replace(Path::new(&tmp_prune_file_data))?;
|
||||||
|
|
||||||
// 6. Write the leaf_set to disk.
|
// 6. Write the leaf_set to disk.
|
||||||
// Optimize the bitmap storage in the process.
|
self.sync_leaf_set()?;
|
||||||
self.leaf_set.flush()?;
|
|
||||||
|
|
||||||
// 7. cleanup rewind files
|
// 7. cleanup rewind files
|
||||||
self.clean_rewind_files()?;
|
self.clean_rewind_files()?;
|
||||||
|
|
Loading…
Reference in a new issue