diff --git a/src/common/src/config.rs b/src/common/src/config.rs index 5c8c91db2a3a6..a1e5d5fde7574 100644 --- a/src/common/src/config.rs +++ b/src/common/src/config.rs @@ -583,6 +583,13 @@ pub struct StorageConfig { pub enable_fast_compaction: bool, #[serde(default = "default::storage::max_preload_io_retry_times")] pub max_preload_io_retry_times: usize, + + #[serde(default = "default::storage::compactor_fast_max_compact_delete_ratio")] + pub compactor_fast_max_compact_delete_ratio: u32, + + #[serde(default = "default::storage::compactor_fast_max_compact_task_size")] + pub compactor_fast_max_compact_task_size: u64, + #[serde(default, flatten)] pub unrecognized: Unrecognized, @@ -1150,6 +1157,14 @@ pub mod default { pub fn mem_table_spill_threshold() -> usize { 4 << 20 } + + pub fn compactor_fast_max_compact_delete_ratio() -> u32 { + 40 + } + + pub fn compactor_fast_max_compact_task_size() -> u64 { + 2 * 1024 * 1024 * 1024 // 2g + } } pub mod streaming { diff --git a/src/config/example.toml b/src/config/example.toml index f142c90eef750..fddd8f34bb79a 100644 --- a/src/config/example.toml +++ b/src/config/example.toml @@ -110,6 +110,8 @@ compact_iter_recreate_timeout_ms = 600000 compactor_max_sst_size = 536870912 enable_fast_compaction = true max_preload_io_retry_times = 3 +compactor_fast_max_compact_delete_ratio = 40 +compactor_fast_max_compact_task_size = 2147483648 mem_table_spill_threshold = 4194304 [storage.data_file_cache] diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/mod.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/mod.rs index 2c783039a1abd..401ce0b3b6c24 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/mod.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/mod.rs @@ -22,9 +22,9 @@ mod rw_event_logs; mod rw_fragments; mod rw_functions; mod rw_hummock_branched_objects; +mod rw_hummock_compact_task_assignment; mod rw_hummock_compact_task_progress; mod rw_hummock_compaction_group_configs; -mod rw_hummock_compaction_status; mod rw_hummock_meta_configs; mod rw_hummock_pinned_snapshots; mod rw_hummock_pinned_versions; @@ -60,9 +60,9 @@ pub use rw_event_logs::*; pub use rw_fragments::*; pub use rw_functions::*; pub use rw_hummock_branched_objects::*; +pub use rw_hummock_compact_task_assignment::*; pub use rw_hummock_compact_task_progress::*; pub use rw_hummock_compaction_group_configs::*; -pub use rw_hummock_compaction_status::*; pub use rw_hummock_meta_configs::*; pub use rw_hummock_pinned_snapshots::*; pub use rw_hummock_pinned_versions::*; diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_compaction_status.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_compact_task_assignment.rs similarity index 98% rename from src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_compaction_status.rs rename to src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_compact_task_assignment.rs index f2519c46b32af..222b9d2ca833a 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_compaction_status.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_compact_task_assignment.rs @@ -22,7 +22,7 @@ use serde_json::json; use crate::catalog::system_catalog::{BuiltinTable, SysCatalogReaderImpl}; pub const RW_HUMMOCK_COMPACT_TASK_ASSIGNMENT: BuiltinTable = BuiltinTable { - name: "RW_HUMMOCK_COMPACT_TASK_ASSIGNMENT", + name: "rw_hummock_compact_task_assignment", schema: RW_CATALOG_SCHEMA_NAME, columns: &[ (DataType::Int64, "compaction_group_id"), diff --git a/src/meta/src/hummock/manager/mod.rs b/src/meta/src/hummock/manager/mod.rs index 703470c3d6211..cd7baa4546aa8 100644 --- a/src/meta/src/hummock/manager/mod.rs +++ b/src/meta/src/hummock/manager/mod.rs @@ -2931,7 +2931,7 @@ impl HummockManager { .await; match ret { Ok((new_group_id, table_vnode_partition_count)) => { - tracing::info!("move state table [{}] from group-{} to group-{} success, Allow split by table: false", table_id, parent_group_id, new_group_id); + tracing::info!("move state table [{}] from group-{} to group-{} success table_vnode_partition_count {:?}", table_id, parent_group_id, new_group_id, table_vnode_partition_count); return TableAlignRule::SplitToDedicatedCg(( new_group_id, table_vnode_partition_count, diff --git a/src/storage/src/hummock/compactor/compactor_runner.rs b/src/storage/src/hummock/compactor/compactor_runner.rs index d4f7e95d34c05..a137b1f101a6a 100644 --- a/src/storage/src/hummock/compactor/compactor_runner.rs +++ b/src/storage/src/hummock/compactor/compactor_runner.rs @@ -53,8 +53,6 @@ use crate::hummock::{ SstableDeleteRangeIterator, SstableStoreRef, }; use crate::monitor::{CompactorMetrics, StoreLocalStatistic}; -const FAST_COMPACT_MAX_COMPACT_SIZE: u64 = 2 * 1024 * 1024 * 1024; // 2GB -const FAST_COMPACT_MAX_DELETE_RATIO: u64 = 40; // 40% pub struct CompactorRunner { compact_task: CompactTask, compactor: Compactor, @@ -372,7 +370,7 @@ pub async fn compact( let delete_key_count = sstable_infos .iter() - .map(|table_info| table_info.stale_key_count) + .map(|table_info| table_info.stale_key_count + table_info.range_tombstone_count) .sum::(); let total_key_count = sstable_infos .iter() @@ -385,8 +383,9 @@ pub async fn compact( && single_table && compact_task.target_level > 0 && compact_task.input_ssts.len() == 2 - && compaction_size < FAST_COMPACT_MAX_COMPACT_SIZE - && delete_key_count * 100 < FAST_COMPACT_MAX_DELETE_RATIO * total_key_count + && compaction_size < context.storage_opts.compactor_fast_max_compact_task_size + && delete_key_count * 100 + < context.storage_opts.compactor_fast_max_compact_delete_ratio as u64 * total_key_count && compact_task.task_type() == TaskType::Dynamic; if !optimize_by_copy_block { match generate_splits(&sstable_infos, compaction_size, context.clone()).await { diff --git a/src/storage/src/hummock/sstable/multi_builder.rs b/src/storage/src/hummock/sstable/multi_builder.rs index b90cc2239d428..89576429342a3 100644 --- a/src/storage/src/hummock/sstable/multi_builder.rs +++ b/src/storage/src/hummock/sstable/multi_builder.rs @@ -198,11 +198,7 @@ where if switch_builder { need_seal_current = true; } else if builder.reach_capacity() { - let is_split_table = self - .table_partition_vnode - .contains_key(&full_key.user_key.table_id.table_id()); - - if !is_split_table || builder.reach_max_sst_size() { + if !self.is_target_level_l0_or_lbase || builder.reach_max_sst_size() { need_seal_current = true; } else { need_seal_current = self.is_target_level_l0_or_lbase && vnode_changed; diff --git a/src/storage/src/opts.rs b/src/storage/src/opts.rs index 4cbefd7da24e8..5650fc48ce197 100644 --- a/src/storage/src/opts.rs +++ b/src/storage/src/opts.rs @@ -128,6 +128,8 @@ pub struct StorageOpts { /// enable FastCompactorRunner. pub enable_fast_compaction: bool, pub max_preload_io_retry_times: usize, + pub compactor_fast_max_compact_delete_ratio: u32, + pub compactor_fast_max_compact_task_size: u64, pub mem_table_spill_threshold: usize, @@ -248,6 +250,10 @@ impl From<(&RwConfig, &SystemParamsReader, &StorageMemoryConfig)> for StorageOpt enable_fast_compaction: c.storage.enable_fast_compaction, mem_table_spill_threshold: c.storage.mem_table_spill_threshold, object_store_config: c.storage.object_store.clone(), + compactor_fast_max_compact_delete_ratio: c + .storage + .compactor_fast_max_compact_delete_ratio, + compactor_fast_max_compact_task_size: c.storage.compactor_fast_max_compact_task_size, } } }