From 868bef91bb4470bfa81a1518466c5253d74607ef Mon Sep 17 00:00:00 2001 From: Li0k Date: Tue, 19 Nov 2024 16:50:11 +0800 Subject: [PATCH] feat(config): add config for calculate max_overlapping_level_size --- proto/hummock.proto | 6 ++++++ src/common/src/config.rs | 4 ++++ src/ctl/src/cmd_impl/hummock/compaction_group.rs | 4 ++++ src/ctl/src/lib.rs | 4 ++++ src/meta/src/hummock/compaction/compaction_config.rs | 3 +++ src/meta/src/hummock/manager/commit_epoch.rs | 7 ++++++- .../hummock/manager/compaction/compaction_group_manager.rs | 3 +++ 7 files changed, 30 insertions(+), 1 deletion(-) diff --git a/proto/hummock.proto b/proto/hummock.proto index 869c5af867d4..be4f3b666228 100644 --- a/proto/hummock.proto +++ b/proto/hummock.proto @@ -660,6 +660,7 @@ message RiseCtlUpdateCompactionConfigRequest { uint64 sst_allowed_trivial_move_min_size = 19; uint32 split_weight_by_vnode = 20; bool disable_auto_group_scheduling = 21; + uint32 max_overlapping_level_size_ratio = 22; } } repeated uint64 compaction_group_ids = 1; @@ -858,6 +859,11 @@ message CompactionConfig { // The limitation of auto group scheduling optional bool disable_auto_group_scheduling = 23; + + // The limitation of the max size of the overlapping-level for the compaction + // e.g. max_overlapping_level_size = sub_level_max_compaction_bytes * max_overlapping_level_size_ratio + // hummock will reorg the commit-sstables to the multi overlapping-level if the size of the commit-sstables is larger than max_overlapping_level_size + optional uint32 max_overlapping_level_size_ratio = 24; } message TableStats { diff --git a/src/common/src/config.rs b/src/common/src/config.rs index 64d7675903ec..844e198e95cf 100644 --- a/src/common/src/config.rs +++ b/src/common/src/config.rs @@ -2230,6 +2230,10 @@ pub mod default { pub fn disable_auto_group_scheduling() -> bool { false } + + pub fn max_overlapping_level_size_ratio() -> u32 { + 4 + } } pub mod object_store_config { diff --git a/src/ctl/src/cmd_impl/hummock/compaction_group.rs b/src/ctl/src/cmd_impl/hummock/compaction_group.rs index d109d6eabda6..6ec9577d6d2b 100644 --- a/src/ctl/src/cmd_impl/hummock/compaction_group.rs +++ b/src/ctl/src/cmd_impl/hummock/compaction_group.rs @@ -68,6 +68,7 @@ pub fn build_compaction_config_vec( max_l0_compact_level: Option, sst_allowed_trivial_move_min_size: Option, disable_auto_group_scheduling: Option, + max_overlapping_level_size_ratio: Option, ) -> Vec { let mut configs = vec![]; if let Some(c) = max_bytes_for_level_base { @@ -127,6 +128,9 @@ pub fn build_compaction_config_vec( if let Some(c) = disable_auto_group_scheduling { configs.push(MutableConfig::DisableAutoGroupScheduling(c)) } + if let Some(c) = max_overlapping_level_size_ratio { + configs.push(MutableConfig::MaxOverlappingLevelSizeRatio(c)) + } configs } diff --git a/src/ctl/src/lib.rs b/src/ctl/src/lib.rs index 99de4cd9b17b..952550e1bfcb 100644 --- a/src/ctl/src/lib.rs +++ b/src/ctl/src/lib.rs @@ -191,6 +191,8 @@ enum HummockCommands { sst_allowed_trivial_move_min_size: Option, #[clap(long)] disable_auto_group_scheduling: Option, + #[clap(long)] + max_overlapping_level_size_ratio: Option, }, /// Split given compaction group into two. Moves the given tables to the new group. SplitCompactionGroup { @@ -578,6 +580,7 @@ async fn start_impl(opts: CliOpts, context: &CtlContext) -> Result<()> { max_l0_compact_level, sst_allowed_trivial_move_min_size, disable_auto_group_scheduling, + max_overlapping_level_size_ratio, }) => { cmd_impl::hummock::update_compaction_config( context, @@ -610,6 +613,7 @@ async fn start_impl(opts: CliOpts, context: &CtlContext) -> Result<()> { max_l0_compact_level, sst_allowed_trivial_move_min_size, disable_auto_group_scheduling, + max_overlapping_level_size_ratio, ), ) .await? diff --git a/src/meta/src/hummock/compaction/compaction_config.rs b/src/meta/src/hummock/compaction/compaction_config.rs index d7be9b6e6cba..97d14f161375 100644 --- a/src/meta/src/hummock/compaction/compaction_config.rs +++ b/src/meta/src/hummock/compaction/compaction_config.rs @@ -71,6 +71,9 @@ impl CompactionConfigBuilder { disable_auto_group_scheduling: Some( compaction_config::disable_auto_group_scheduling(), ), + max_overlapping_level_size_ratio: Some( + compaction_config::max_overlapping_level_size_ratio(), + ), }, } } diff --git a/src/meta/src/hummock/manager/commit_epoch.rs b/src/meta/src/hummock/manager/commit_epoch.rs index 09ac1bd271b3..7891b6ea2757 100644 --- a/src/meta/src/hummock/manager/commit_epoch.rs +++ b/src/meta/src/hummock/manager/commit_epoch.rs @@ -17,6 +17,7 @@ use std::sync::Arc; use itertools::Itertools; use risingwave_common::catalog::TableId; +use risingwave_common::config::default::compaction_config; use risingwave_common::system_param::reader::SystemParamsRead; use risingwave_hummock_sdk::change_log::ChangeLogDelta; use risingwave_hummock_sdk::compaction_group::group_split::split_sst_with_table_ids; @@ -457,7 +458,11 @@ fn rewrite_commit_sstables_to_sub_level( let mut accumulated_size = 0; let mut ssts = vec![]; - let sub_level_size_limit = config.sub_level_max_compaction_bytes * 2; // TODO: use config instead of magic number + let sub_level_size_limit = config.sub_level_max_compaction_bytes + * config + .max_overlapping_level_size_ratio + .unwrap_or(compaction_config::max_overlapping_level_size_ratio()) + as u64; let level = overlapping_sstables.entry(group_id).or_default(); diff --git a/src/meta/src/hummock/manager/compaction/compaction_group_manager.rs b/src/meta/src/hummock/manager/compaction/compaction_group_manager.rs index 02b63ab47de6..360931d866b0 100644 --- a/src/meta/src/hummock/manager/compaction/compaction_group_manager.rs +++ b/src/meta/src/hummock/manager/compaction/compaction_group_manager.rs @@ -588,6 +588,9 @@ fn update_compaction_config(target: &mut CompactionConfig, items: &[MutableConfi MutableConfig::DisableAutoGroupScheduling(c) => { target.disable_auto_group_scheduling = Some(*c); } + MutableConfig::MaxOverlappingLevelSizeRatio(c) => { + target.max_overlapping_level_size_ratio = Some(*c); + } } } }