mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-26 04:16:51 +00:00
Refactor a bit
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user