Make background tranquility a configurable parameter

This commit is contained in:
Alex Auvolat 2022-03-15 12:31:23 +01:00
parent 8fd6745745
commit e480aaf338
No known key found for this signature in database
GPG key ID: 0E496D15096376BE
4 changed files with 25 additions and 16 deletions

View file

@ -29,15 +29,13 @@ use garage_rpc::*;
use garage_table::replication::{TableReplication, TableShardedReplication}; use garage_table::replication::{TableReplication, TableShardedReplication};
use crate::metrics::*;
use crate::block::*; use crate::block::*;
use crate::metrics::*;
use crate::rc::*; use crate::rc::*;
/// Size under which data will be stored inlined in database instead of as files /// Size under which data will be stored inlined in database instead of as files
pub const INLINE_THRESHOLD: usize = 3072; pub const INLINE_THRESHOLD: usize = 3072;
pub const BACKGROUND_TRANQUILITY: u32 = 2;
// Timeout for RPCs that read and write blocks to remote nodes // Timeout for RPCs that read and write blocks to remote nodes
const BLOCK_RW_TIMEOUT: Duration = Duration::from_secs(30); const BLOCK_RW_TIMEOUT: Duration = Duration::from_secs(30);
// Timeout for RPCs that ask other nodes whether they need a copy // Timeout for RPCs that ask other nodes whether they need a copy
@ -82,8 +80,9 @@ pub struct BlockManager {
pub replication: TableShardedReplication, pub replication: TableShardedReplication,
/// Directory in which block are stored /// Directory in which block are stored
pub data_dir: PathBuf, pub data_dir: PathBuf,
/// Zstd compression level
compression_level: Option<i32>, compression_level: Option<i32>,
background_tranquility: u32,
mutation_lock: Mutex<BlockManagerLocked>, mutation_lock: Mutex<BlockManagerLocked>,
@ -109,6 +108,7 @@ impl BlockManager {
db: &sled::Db, db: &sled::Db,
data_dir: PathBuf, data_dir: PathBuf,
compression_level: Option<i32>, compression_level: Option<i32>,
background_tranquility: u32,
replication: TableShardedReplication, replication: TableShardedReplication,
system: Arc<System>, system: Arc<System>,
) -> Arc<Self> { ) -> Arc<Self> {
@ -139,6 +139,7 @@ impl BlockManager {
replication, replication,
data_dir, data_dir,
compression_level, compression_level,
background_tranquility,
mutation_lock: Mutex::new(manager_locked), mutation_lock: Mutex::new(manager_locked),
rc, rc,
resync_queue, resync_queue,
@ -440,7 +441,7 @@ impl BlockManager {
while !*must_exit.borrow() { while !*must_exit.borrow() {
match self.resync_iter(&mut must_exit).await { match self.resync_iter(&mut must_exit).await {
Ok(true) => { Ok(true) => {
tranquilizer.tranquilize(BACKGROUND_TRANQUILITY).await; tranquilizer.tranquilize(self.background_tranquility).await;
} }
Ok(false) => { Ok(false) => {
tranquilizer.reset(); tranquilizer.reset();

View file

@ -1,7 +1,7 @@
use std::convert::TryInto; use std::convert::TryInto;
use garage_util::error::*;
use garage_util::data::*; use garage_util::data::*;
use garage_util::error::*;
use garage_util::time::*; use garage_util::time::*;
use crate::manager::BLOCK_GC_DELAY; use crate::manager::BLOCK_GC_DELAY;
@ -12,9 +12,7 @@ pub struct BlockRc {
impl BlockRc { impl BlockRc {
pub(crate) fn new(rc: sled::Tree) -> Self { pub(crate) fn new(rc: sled::Tree) -> Self {
Self { Self { rc }
rc
}
} }
/// Increment the reference counter associated to a hash. /// Increment the reference counter associated to a hash.

View file

@ -7,11 +7,11 @@ use garage_util::config::*;
use garage_rpc::system::System; use garage_rpc::system::System;
use garage_block::manager::*;
use garage_table::replication::ReplicationMode; use garage_table::replication::ReplicationMode;
use garage_table::replication::TableFullReplication; use garage_table::replication::TableFullReplication;
use garage_table::replication::TableShardedReplication; use garage_table::replication::TableShardedReplication;
use garage_table::*; use garage_table::*;
use garage_block::manager::*;
use crate::block_ref_table::*; use crate::block_ref_table::*;
use crate::bucket_alias_table::*; use crate::bucket_alias_table::*;
@ -86,11 +86,14 @@ impl Garage {
}; };
info!("Initialize block manager..."); info!("Initialize block manager...");
let block_manager = let block_manager = BlockManager::new(
BlockManager::new(&db, &db,
config.data_dir.clone(), config.data_dir.clone(),
config.compression_level, config.compression_level,
data_rep_param, system.clone()); config.block_manager_background_tranquility,
data_rep_param,
system.clone(),
);
info!("Initialize block_ref_table..."); info!("Initialize block_ref_table...");
let block_ref_table = Table::new( let block_ref_table = Table::new(

View file

@ -23,6 +23,10 @@ pub struct Config {
#[serde(default = "default_block_size")] #[serde(default = "default_block_size")]
pub block_size: usize, pub block_size: usize,
/// Size of data blocks to save to disk
#[serde(default = "default_block_manager_background_tranquility")]
pub block_manager_background_tranquility: u32,
/// Replication mode. Supported values: /// Replication mode. Supported values:
/// - none, 1 -> no replication /// - none, 1 -> no replication
/// - 2 -> 2-way replication /// - 2 -> 2-way replication
@ -118,6 +122,9 @@ fn default_sled_flush_every_ms() -> u64 {
fn default_block_size() -> usize { fn default_block_size() -> usize {
1048576 1048576
} }
fn default_block_manager_background_tranquility() -> u32 {
2
}
/// Read and parse configuration /// Read and parse configuration
pub fn read_config(config_file: PathBuf) -> Result<Config, Error> { pub fn read_config(config_file: PathBuf) -> Result<Config, Error> {