From fabbb9643912c2f71476d48810e52615c98ffcbb Mon Sep 17 00:00:00 2001 From: Little-Wallace Date: Tue, 28 May 2024 15:59:40 +0800 Subject: [PATCH] fix small table intra compact Signed-off-by: Little-Wallace --- .../picker/compaction_task_validator.rs | 4 +-- .../picker/intra_compaction_picker.rs | 4 +-- .../picker/tier_compaction_picker.rs | 2 +- src/meta/src/hummock/manager/compaction.rs | 31 +++++++------------ 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/meta/src/hummock/compaction/picker/compaction_task_validator.rs b/src/meta/src/hummock/compaction/picker/compaction_task_validator.rs index 3026bcfbb4a2e..12151244505b2 100644 --- a/src/meta/src/hummock/compaction/picker/compaction_task_validator.rs +++ b/src/meta/src/hummock/compaction/picker/compaction_task_validator.rs @@ -162,7 +162,7 @@ impl CompactionTaskValidationRule for IntraCompactionTaskValidationRule { max_level_size * self.config.level0_sub_level_compact_level_count as u64 / 2 >= input.select_input_size; - if is_write_amp_large { + if is_write_amp_large || max_level_size > self.config.sub_level_max_compaction_bytes { stats.skip_by_write_amp_limit += 1; return false; } @@ -184,7 +184,7 @@ impl CompactionTaskValidationRule for BaseCompactionTaskValidationRule { return true; } - if input.select_input_size < 2 * input.target_input_size { + if input.select_input_size < input.target_input_size { stats.skip_by_write_amp_limit += 1; return false; } diff --git a/src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs index 993ad79d59b2e..fc3abc7b0c82b 100644 --- a/src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs @@ -118,9 +118,7 @@ impl IntraCompactionPicker { } for (idx, level) in l0.sub_levels.iter().enumerate() { - if level.level_type() != LevelType::Nonoverlapping - || level.total_file_size > self.config.sub_level_max_compaction_bytes - { + if level.level_type() != LevelType::Nonoverlapping { continue; } diff --git a/src/meta/src/hummock/compaction/picker/tier_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/tier_compaction_picker.rs index 9ed22ba551fcc..c43f89ef3ed0c 100644 --- a/src/meta/src/hummock/compaction/picker/tier_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/tier_compaction_picker.rs @@ -124,9 +124,9 @@ impl TierCompactionPicker { target_level: 0, target_sub_level_id: level.sub_level_id, select_input_size: compaction_bytes, - target_input_size: 0, total_file_count: compact_file_count, vnode_partition_count, + ..Default::default() }; if !self.compaction_task_validator.valid_compact_task( diff --git a/src/meta/src/hummock/manager/compaction.rs b/src/meta/src/hummock/manager/compaction.rs index 63b87a234f6eb..fa34f45868bc4 100644 --- a/src/meta/src/hummock/manager/compaction.rs +++ b/src/meta/src/hummock/manager/compaction.rs @@ -1507,27 +1507,18 @@ impl HummockManager { compact_task .table_vnode_partition .insert(table_id, default_partition_count); + } else if (compact_table_size > compact_task_table_size_partition_threshold_low + || (write_throughput > self.env.opts.table_write_throughput_threshold + && compact_table_size > compaction_config.target_file_size_base)) + && hybrid_vnode_count > 0 + { + // partition for large write throughput table. But we also need to make sure that it can not be too small. + compact_task + .table_vnode_partition + .insert(table_id, hybrid_vnode_count); } else if compact_table_size > compaction_config.target_file_size_base { - if write_throughput > self.env.opts.table_write_throughput_threshold - && compact_table_size > compact_task_table_size_partition_threshold_low - && compact_task.base_level == compact_task.target_level - && default_partition_count > 0 - { - // Because the task to base level may be small, we shall partition it if the write throughput is high. - compact_task - .table_vnode_partition - .insert(table_id, default_partition_count); - } else if write_throughput > self.env.opts.table_write_throughput_threshold - || compact_table_size > compact_task_table_size_partition_threshold_low - { - // partition for large write throughput table. But we also need to make sure that it can not be too small. - compact_task - .table_vnode_partition - .insert(table_id, hybrid_vnode_count); - } else { - // partition for small table - compact_task.table_vnode_partition.insert(table_id, 1); - } + // partition for small table + compact_task.table_vnode_partition.insert(table_id, 1); } } compact_task