Skip to content

Commit

Permalink
fix: BufferedBlockstore#flush should not reset the write buffer. (#1096)
Browse files Browse the repository at this point in the history
Resetting the buffer was never advertised as a behaviour of this method.

This makes it possible to call flush multiple times to selectively flush
roots during its lifetime. Selective flushes are used to flush the event
AMTs as they are being produced.
  • Loading branch information
raulk committed Nov 16, 2022
1 parent b60e83c commit 82de096
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions fvm/src/blockstore/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ where
{
/// Flushes the buffered cache based on the root node.
/// This will recursively traverse the cache and write all data connected by links to this
/// root Cid.
/// root Cid. Calling flush will not reset the write buffer.
fn flush(&self, root: &Cid) -> Result<()> {
let mut buffer = Vec::new();
let mut s = self.write.borrow_mut();
let s = self.write.borrow();
copy_rec(&s, *root, &mut buffer)?;

self.base.put_many_keyed(buffer)?;
*s = Default::default();

Ok(())
}
Expand Down Expand Up @@ -290,7 +289,6 @@ mod tests {
buf_store.flush(&cid).unwrap();
assert_eq!(buf_store.get_cbor::<u8>(&cid).unwrap(), Some(8));
assert_eq!(mem.get_cbor::<u8>(&cid).unwrap(), Some(8));
assert!(buf_store.write.borrow().get(&cid).is_none());
}

#[test]
Expand Down Expand Up @@ -361,6 +359,5 @@ mod tests {
assert_eq!(buf_store.get(&unsealed_comm_cid).unwrap(), None);
assert_eq!(buf_store.get(&sealed_comm_cid).unwrap(), None);
assert_eq!(mem.get_cbor::<u8>(&unconnected).unwrap(), None);
assert_eq!(buf_store.get_cbor::<u8>(&unconnected).unwrap(), None);
}
}

0 comments on commit 82de096

Please sign in to comment.