From 5dd59e437d5af84dfa2cf5dcc2c15807b971002d Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 11 Apr 2020 23:00:26 +0200 Subject: Local refcounting of blocks --- src/block_ref_table.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/block_ref_table.rs') diff --git a/src/block_ref_table.rs b/src/block_ref_table.rs index b4bff937..e2310f74 100644 --- a/src/block_ref_table.rs +++ b/src/block_ref_table.rs @@ -45,7 +45,19 @@ impl TableFormat for BlockRefTable { type E = BlockRef; async fn updated(&self, old: Option, new: Self::E) { - //unimplemented!() - // TODO + let garage = self.garage.read().await.as_ref().cloned().unwrap(); + + let was_before = old.map(|x| !x.deleted).unwrap_or(false); + let is_after = !new.deleted; + if is_after && !was_before { + if let Err(e) = garage.block_manager.block_incref(&new.block) { + eprintln!("Failed to incref block {:?}: {}", &new.block, e); + } + } + if was_before && !is_after { + if let Err(e) = garage.block_manager.block_decref(&new.block, &garage.background) { + eprintln!("Failed to decref or delete block {:?}: {}", &new.block, e); + } + } } } -- cgit v1.2.3