From 5967c5a5af430855fbd73f380041d63bd82f5ce1 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 12 Apr 2020 13:03:55 +0200 Subject: Refactor a bit --- src/server.rs | 63 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 29 deletions(-) (limited to 'src/server.rs') diff --git a/src/server.rs b/src/server.rs index e38e8580..29a2dbcb 100644 --- a/src/server.rs +++ b/src/server.rs @@ -6,7 +6,6 @@ use std::net::SocketAddr; use std::path::PathBuf; use std::sync::Arc; use tokio::sync::watch; -use tokio::sync::RwLock; use crate::api_server; use crate::background::*; @@ -36,12 +35,21 @@ pub struct Config { #[serde(default = "default_replication_factor")] pub data_replication_factor: usize, + + pub tls: TlsConfig, +} + +#[derive(Deserialize, Debug)] +pub struct TlsConfig { + pub ca_cert: Option, + pub node_cert: Option, + pub node_key: Option, } pub struct Garage { pub db: sled::Db, pub system: Arc, - pub block_manager: BlockManager, + pub block_manager: Arc, pub background: Arc, pub table_rpc_handlers: HashMap>, @@ -58,10 +66,17 @@ impl Garage { db: sled::Db, background: Arc, ) -> Arc { - let block_manager = BlockManager::new(&db, config.data_dir.clone()); + let block_manager = Arc::new(BlockManager::new(&db, config.data_dir.clone())); let system = Arc::new(System::new(config, id, background.clone())); + let data_rep_param = TableReplicationParams { + replication_factor: system.config.data_replication_factor, + write_quorum: (system.config.data_replication_factor + 1) / 2, + read_quorum: 1, + timeout: DEFAULT_TIMEOUT, + }; + let meta_rep_param = TableReplicationParams { replication_factor: system.config.meta_replication_factor, write_quorum: (system.config.meta_replication_factor + 1) / 2, @@ -69,42 +84,38 @@ impl Garage { timeout: DEFAULT_TIMEOUT, }; - let object_table = Arc::new(Table::new( - ObjectTable { - garage: RwLock::new(None), + let block_ref_table = Arc::new(Table::new( + BlockRefTable { + background: background.clone(), + block_manager: block_manager.clone(), }, system.clone(), &db, - "object".to_string(), - meta_rep_param.clone(), + "block_ref".to_string(), + data_rep_param.clone(), )); let version_table = Arc::new(Table::new( VersionTable { - garage: RwLock::new(None), + background: background.clone(), + block_ref_table: block_ref_table.clone(), }, system.clone(), &db, "version".to_string(), meta_rep_param.clone(), )); - - let data_rep_param = TableReplicationParams { - replication_factor: system.config.data_replication_factor, - write_quorum: (system.config.data_replication_factor + 1) / 2, - read_quorum: 1, - timeout: DEFAULT_TIMEOUT, - }; - - let block_ref_table = Arc::new(Table::new( - BlockRefTable { - garage: RwLock::new(None), + let object_table = Arc::new(Table::new( + ObjectTable { + background: background.clone(), + version_table: version_table.clone(), }, system.clone(), &db, - "block_ref".to_string(), - data_rep_param.clone(), + "object".to_string(), + meta_rep_param.clone(), )); + let mut garage = Self { db, system: system.clone(), @@ -129,13 +140,7 @@ impl Garage { garage.block_ref_table.clone().rpc_handler(), ); - let garage = Arc::new(garage); - - *garage.object_table.instance.garage.write().await = Some(garage.clone()); - *garage.version_table.instance.garage.write().await = Some(garage.clone()); - *garage.block_ref_table.instance.garage.write().await = Some(garage.clone()); - - garage + Arc::new(garage) } } -- cgit v1.2.3