diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-12 13:03:55 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-12 13:03:55 +0200 |
commit | 5967c5a5af430855fbd73f380041d63bd82f5ce1 (patch) | |
tree | 2e0063e418e2f93c56402570b341506691716239 /src/block_ref_table.rs | |
parent | 419c70e50613faf5b450b9555aec32cb19226153 (diff) | |
download | garage-5967c5a5af430855fbd73f380041d63bd82f5ce1.tar.gz garage-5967c5a5af430855fbd73f380041d63bd82f5ce1.zip |
Refactor a bit
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); } |