diff options
Diffstat (limited to 'src/block_ref_table.rs')
-rw-r--r-- | src/block_ref_table.rs | 16 |
1 files changed, 14 insertions, 2 deletions
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<Self::E>, 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); + } + } } } |