From 108bdbaa730f000a43e2ffcaa12555dcce75afaa Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Tue, 9 Apr 2019 12:03:19 +0100 Subject: [PATCH] Only flush leaf_set if we have a prunable backend. (#2735) --- store/src/pmmr.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/store/src/pmmr.rs b/store/src/pmmr.rs index f57867c462..8d4c3caffd 100644 --- a/store/src/pmmr.rs +++ b/store/src/pmmr.rs @@ -261,10 +261,10 @@ impl PMMRBackend { /// 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, @@ -273,11 +273,19 @@ impl PMMRBackend { }) } + // 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 @@ -344,8 +352,7 @@ impl PMMRBackend { 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()?;