diff options
Diffstat (limited to 'src/block_ref_table.rs')
-rw-r--r-- | src/block_ref_table.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/block_ref_table.rs b/src/block_ref_table.rs index f3a14d81..3e5fb0a1 100644 --- a/src/block_ref_table.rs +++ b/src/block_ref_table.rs @@ -1,11 +1,11 @@ use async_trait::async_trait; use serde::{Deserialize, Serialize}; use std::sync::Arc; -use tokio::sync::RwLock; use crate::data::*; -use crate::server::Garage; use crate::table::*; +use crate::background::*; +use crate::block::*; #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub struct BlockRef { @@ -35,7 +35,8 @@ impl Entry<Hash, UUID> for BlockRef { } pub struct BlockRefTable { - pub garage: RwLock<Option<Arc<Garage>>>, + pub background: Arc<BackgroundRunner>, + pub block_manager: Arc<BlockManager>, } #[async_trait] @@ -45,19 +46,17 @@ impl TableFormat for BlockRefTable { type E = BlockRef; async fn updated(&self, old: Option<Self::E>, new: Self::E) { - 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) { + if let Err(e) = self.block_manager.block_incref(&new.block) { eprintln!("Failed to incref block {:?}: {}", &new.block, e); } } if was_before && !is_after { - if let Err(e) = garage + if let Err(e) = self .block_manager - .block_decref(&new.block, &garage.background) + .block_decref(&new.block, &self.background) { eprintln!("Failed to decref block {:?}: {}", &new.block, e); } |