aboutsummaryrefslogtreecommitdiff
path: root/src/version_table.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-12 13:03:55 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-12 13:03:55 +0200
commit5967c5a5af430855fbd73f380041d63bd82f5ce1 (patch)
tree2e0063e418e2f93c56402570b341506691716239 /src/version_table.rs
parent419c70e50613faf5b450b9555aec32cb19226153 (diff)
downloadgarage-5967c5a5af430855fbd73f380041d63bd82f5ce1.tar.gz
garage-5967c5a5af430855fbd73f380041d63bd82f5ce1.zip
Refactor a bit
Diffstat (limited to 'src/version_table.rs')
-rw-r--r--src/version_table.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/version_table.rs b/src/version_table.rs
index 9ea0551e..cb70c645 100644
--- a/src/version_table.rs
+++ b/src/version_table.rs
@@ -1,11 +1,10 @@
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::BackgroundRunner;
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub struct Version {
@@ -54,7 +53,8 @@ impl Entry<Hash, EmptySortKey> for Version {
}
pub struct VersionTable {
- pub garage: RwLock<Option<Arc<Garage>>>,
+ pub background: Arc<BackgroundRunner>,
+ pub block_ref_table: Arc<Table<BlockRefTable>>,
}
#[async_trait]
@@ -64,8 +64,8 @@ impl TableFormat for VersionTable {
type E = Version;
async fn updated(&self, old: Option<Self::E>, new: Self::E) {
- let garage = self.garage.read().await.as_ref().cloned().unwrap();
- garage.clone().background.spawn(async move {
+ let block_ref_table = self.block_ref_table.clone();
+ self.background.spawn(async move {
// Propagate deletion of version blocks
if let Some(old_v) = old {
if new.deleted && !old_v.deleted {
@@ -78,8 +78,7 @@ impl TableFormat for VersionTable {
deleted: true,
})
.collect::<Vec<_>>();
- garage
- .block_ref_table
+ block_ref_table
.insert_many(&deleted_block_refs[..])
.await?;
}