garage/src/model/garage.rs

166 lines
4.3 KiB
Rust
Raw Normal View History

use std::sync::Arc;
2021-10-14 09:50:12 +00:00
use netapp::NetworkKey;
2020-04-24 10:10:01 +00:00
use garage_util::background::*;
use garage_util::config::*;
2021-10-14 09:50:12 +00:00
use garage_rpc::system::System;
use garage_block::manager::*;
use garage_table::replication::ReplicationMode;
2021-03-26 18:41:46 +00:00
use garage_table::replication::TableFullReplication;
use garage_table::replication::TableShardedReplication;
2020-04-24 10:10:01 +00:00
use garage_table::*;
2020-04-24 10:10:01 +00:00
use crate::block_ref_table::*;
2021-12-14 12:55:11 +00:00
use crate::bucket_alias_table::*;
2020-04-24 10:10:01 +00:00
use crate::bucket_table::*;
use crate::helper;
2020-04-24 10:10:01 +00:00
use crate::key_table::*;
use crate::object_table::*;
use crate::version_table::*;
2021-03-26 20:53:28 +00:00
/// An entire Garage full of data
2020-04-08 20:00:41 +00:00
pub struct Garage {
2021-03-26 20:53:28 +00:00
/// The parsed configuration Garage is running
2020-04-23 17:05:46 +00:00
pub config: Config,
2021-03-26 20:53:28 +00:00
/// The local database
2020-04-08 20:00:41 +00:00
pub db: sled::Db,
2021-03-26 20:53:28 +00:00
/// A background job runner
pub background: Arc<BackgroundRunner>,
2021-03-26 20:53:28 +00:00
/// The membership manager
2020-04-08 20:00:41 +00:00
pub system: Arc<System>,
2021-03-26 20:53:28 +00:00
/// The block manager
2020-04-12 11:03:55 +00:00
pub block_manager: Arc<BlockManager>,
2020-04-08 20:00:41 +00:00
2021-03-26 20:53:28 +00:00
/// Table containing informations about buckets
pub bucket_table: Arc<Table<BucketTable, TableFullReplication>>,
2021-12-14 12:55:11 +00:00
/// Table containing informations about bucket aliases
pub bucket_alias_table: Arc<Table<BucketAliasTable, TableFullReplication>>,
2021-03-26 20:53:28 +00:00
/// Table containing informations about api keys
2020-04-23 20:25:45 +00:00
pub key_table: Arc<Table<KeyTable, TableFullReplication>>,
pub object_table: Arc<Table<ObjectTable, TableShardedReplication>>,
pub version_table: Arc<Table<VersionTable, TableShardedReplication>>,
pub block_ref_table: Arc<Table<BlockRefTable, TableShardedReplication>>,
2020-04-08 20:00:41 +00:00
}
impl Garage {
2021-03-26 20:53:28 +00:00
/// Create and run garage
2021-10-14 09:50:12 +00:00
pub fn new(config: Config, db: sled::Db, background: Arc<BackgroundRunner>) -> Arc<Self> {
let network_key = NetworkKey::from_slice(
&hex::decode(&config.rpc_secret).expect("Invalid RPC secret key")[..],
)
.expect("Invalid RPC secret key");
let replication_mode = ReplicationMode::parse(&config.replication_mode)
.expect("Invalid replication_mode in config file.");
2020-04-21 12:54:55 +00:00
info!("Initialize membership management system...");
2020-04-23 17:05:46 +00:00
let system = System::new(
2021-10-14 09:50:12 +00:00
network_key,
2020-04-23 17:05:46 +00:00
background.clone(),
replication_mode.replication_factor(),
&config,
2020-04-23 17:05:46 +00:00
);
2020-04-08 20:00:41 +00:00
let data_rep_param = TableShardedReplication {
2021-03-16 10:14:27 +00:00
system: system.clone(),
replication_factor: replication_mode.replication_factor(),
write_quorum: replication_mode.write_quorum(),
2020-04-12 11:03:55 +00:00
read_quorum: 1,
};
let meta_rep_param = TableShardedReplication {
2021-03-16 10:14:27 +00:00
system: system.clone(),
replication_factor: replication_mode.replication_factor(),
write_quorum: replication_mode.write_quorum(),
read_quorum: replication_mode.read_quorum(),
2020-04-08 20:00:41 +00:00
};
2021-03-16 10:14:27 +00:00
let control_rep_param = TableFullReplication {
system: system.clone(),
max_faults: replication_mode.control_write_max_faults(),
2021-03-16 10:14:27 +00:00
};
2020-04-23 17:05:46 +00:00
info!("Initialize block manager...");
let block_manager = BlockManager::new(
&db,
config.data_dir.clone(),
config.compression_level,
config.block_manager_background_tranquility,
data_rep_param,
system.clone(),
);
2020-04-21 12:54:55 +00:00
info!("Initialize block_ref_table...");
2020-04-12 20:24:53 +00:00
let block_ref_table = Table::new(
2020-04-12 11:03:55 +00:00
BlockRefTable {
block_manager: block_manager.clone(),
},
meta_rep_param.clone(),
2020-04-08 20:00:41 +00:00
system.clone(),
&db,
);
2020-04-21 12:54:55 +00:00
info!("Initialize version_table...");
2020-04-12 20:24:53 +00:00
let version_table = Table::new(
VersionTable {
2020-04-12 11:03:55 +00:00
background: background.clone(),
block_ref_table: block_ref_table.clone(),
},
meta_rep_param.clone(),
2020-04-09 21:45:07 +00:00
system.clone(),
&db,
);
2020-04-21 12:54:55 +00:00
info!("Initialize object_table...");
2020-04-12 20:24:53 +00:00
let object_table = Table::new(
2020-04-12 11:03:55 +00:00
ObjectTable {
background: background.clone(),
version_table: version_table.clone(),
2020-04-10 21:11:52 +00:00
},
2021-04-23 19:57:32 +00:00
meta_rep_param,
2020-04-10 21:11:52 +00:00
system.clone(),
&db,
);
2020-04-08 20:00:41 +00:00
2020-04-21 12:54:55 +00:00
info!("Initialize bucket_table...");
2021-12-14 11:34:01 +00:00
let bucket_table = Table::new(BucketTable, control_rep_param.clone(), system.clone(), &db);
2021-12-14 12:55:11 +00:00
info!("Initialize bucket_alias_table...");
let bucket_alias_table = Table::new(
BucketAliasTable,
control_rep_param.clone(),
system.clone(),
&db,
);
2020-04-23 20:25:45 +00:00
info!("Initialize key_table_table...");
2021-12-14 11:34:01 +00:00
let key_table = Table::new(KeyTable, control_rep_param, system.clone(), &db);
2020-04-23 20:25:45 +00:00
2020-04-21 12:54:55 +00:00
info!("Initialize Garage...");
2020-04-18 17:21:34 +00:00
let garage = Arc::new(Self {
2020-04-23 17:05:46 +00:00
config,
2020-04-08 20:00:41 +00:00
db,
background,
2021-04-23 19:57:32 +00:00
system,
block_manager,
bucket_table,
2021-12-14 12:55:11 +00:00
bucket_alias_table,
2020-04-23 20:25:45 +00:00
key_table,
2020-04-09 15:32:28 +00:00
object_table,
2020-04-09 21:45:07 +00:00
version_table,
2020-04-10 21:11:52 +00:00
block_ref_table,
2020-04-18 17:21:34 +00:00
});
garage
2020-04-08 20:00:41 +00:00
}
pub fn bucket_helper(&self) -> helper::bucket::BucketHelper {
helper::bucket::BucketHelper(self)
2021-12-14 12:55:11 +00:00
}
2020-04-08 20:00:41 +00:00
}