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/server.rs | |
parent | 419c70e50613faf5b450b9555aec32cb19226153 (diff) | |
download | garage-5967c5a5af430855fbd73f380041d63bd82f5ce1.tar.gz garage-5967c5a5af430855fbd73f380041d63bd82f5ce1.zip |
Refactor a bit
Diffstat (limited to 'src/server.rs')
-rw-r--r-- | src/server.rs | 63 |
1 files changed, 34 insertions, 29 deletions
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<String>, + pub node_cert: Option<String>, + pub node_key: Option<String>, } pub struct Garage { pub db: sled::Db, pub system: Arc<System>, - pub block_manager: BlockManager, + pub block_manager: Arc<BlockManager>, pub background: Arc<BackgroundRunner>, pub table_rpc_handlers: HashMap<String, Box<dyn TableRpcHandler + Sync + Send>>, @@ -58,10 +66,17 @@ impl Garage { db: sled::Db, background: Arc<BackgroundRunner>, ) -> Arc<Self> { - 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) } } |