Make max_subcompactions dynamically changeable
close tikv/tikv#13145
Make max_subcompactions dynamically changeable
@@ -1239,6 +1239,15 @@ impl DbConfig {
)
.into());
}
+ if self.max_sub_compactions == 0
+ || self.max_sub_compactions as i32 > self.max_background_jobs
+ {
+ return Err(format!(
+ "max_sub_compactions should be greater than 0 and less than or equal to {:?}",
+ self.max_background_jobs,
+ )
+ .into());
+ }
if self.max_background_flushes <= 0 || self.max_background_flushes > limit {
return Err(format!(
"max_background_flushes should be greater than 0 and less than or equal to {:?}",
@@ -1375,7 +1384,6 @@ pub struct RaftDbConfig {
pub info_log_dir: String,
#[online_config(skip)]
pub info_log_level: RocksLogLevel,
- #[online_config(skip)]
pub max_sub_compactions: u32,
pub writable_file_max_buffer_size: ReadableSize,
#[online_config(skip)]
@@ -1678,6 +1686,11 @@ impl<T: TabletAccessor<RocksEngine>> DbConfigManger<T> {
Ok(())
}
+ fn set_max_subcompactions(&self, max_subcompactions: u32) -> Result<(), Box<dyn Error>> {
+ self.set_db_config(&[("max_subcompactions", &max_subcompactions.to_string())])?;
+ Ok(())
+ }
+
fn validate_cf(&self, cf: &str) -> Result<(), Box<dyn Error>> {
match (self.db_type, cf) {
(DbType::Kv, CF_DEFAULT)
@@ -1740,6 +1753,14 @@ impl<T: TabletAccessor<RocksEngine> + Send + Sync> ConfigManager for DbConfigMan
self.set_max_background_jobs(max_background_jobs)?;
}
+ if let Some(background_subcompactions_config) = change
+ .drain_filter(|(name, _)| name == "max_sub_compactions")
+ .next()
+ {
+ let max_subcompactions = background_subcompactions_config.1.into();
+ self.set_max_subcompactions(max_subcompactions)?;
+ }
+
if let Some(background_flushes_config) = change
.drain_filter(|(name, _)| name == "max_background_flushes")
.next()
