diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-11 23:00:26 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-11 23:00:26 +0200 |
commit | 5dd59e437d5af84dfa2cf5dcc2c15807b971002d (patch) | |
tree | 2debd795082e810e384f765f84217d47cd158ba3 /src/block_ref_table.rs | |
parent | dcf58499a4f529e1033de65b4fca8d45458d60d2 (diff) | |
download | garage-5dd59e437d5af84dfa2cf5dcc2c15807b971002d.tar.gz garage-5dd59e437d5af84dfa2cf5dcc2c15807b971002d.zip |
Local refcounting of blocks
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); + } + } } } |