Skip to content

Commit bc888dd

Browse files
fix(storage): fix the trivial-move loop caused by config and pick_whole_level (#17721) (#17723)
Co-authored-by: Li0k <[email protected]>
1 parent f4701fb commit bc888dd

7 files changed

+58
-15
lines changed

proto/hummock.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ message CompactionConfig {
894894
bool enable_emergency_picker = 20;
895895

896896
// The limitation of the level count of l0 compaction
897-
uint32 max_l0_compact_level_count = 21;
897+
optional uint32 max_l0_compact_level_count = 21;
898898
}
899899

900900
message TableStats {

src/meta/src/hummock/compaction/compaction_config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl CompactionConfigBuilder {
6464
compaction_config::level0_overlapping_sub_level_compact_level_count(),
6565
tombstone_reclaim_ratio: compaction_config::tombstone_reclaim_ratio(),
6666
enable_emergency_picker: compaction_config::enable_emergency_picker(),
67-
max_l0_compact_level_count: compaction_config::max_l0_compact_level_count(),
67+
max_l0_compact_level_count: Some(compaction_config::max_l0_compact_level_count()),
6868
},
6969
}
7070
}

src/meta/src/hummock/compaction/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::fmt::{Debug, Formatter};
2626
use std::sync::Arc;
2727

2828
use picker::{LevelCompactionPicker, TierCompactionPicker};
29-
use risingwave_hummock_sdk::{can_concat, CompactionGroupId, HummockCompactionTaskId};
29+
use risingwave_hummock_sdk::{CompactionGroupId, HummockCompactionTaskId};
3030
use risingwave_pb::hummock::compaction_config::CompactionMode;
3131
use risingwave_pb::hummock::hummock_version::Levels;
3232
use risingwave_pb::hummock::{CompactTask, CompactionConfig, LevelType};
@@ -140,10 +140,7 @@ impl CompactStatus {
140140
return false;
141141
}
142142

143-
if task.input_ssts.len() == 1 {
144-
return task.input_ssts[0].level_idx == 0
145-
&& can_concat(&task.input_ssts[0].table_infos);
146-
} else if task.input_ssts.len() != 2
143+
if task.input_ssts.len() != 2
147144
|| task.input_ssts[0].level_type() != LevelType::Nonoverlapping
148145
{
149146
return false;

src/meta/src/hummock/compaction/picker/base_level_compaction_picker.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::cell::RefCell;
1616
use std::sync::Arc;
1717

1818
use itertools::Itertools;
19+
use risingwave_common::config::default::compaction_config;
1920
use risingwave_hummock_sdk::compaction_group::hummock_version_ext::HummockLevelsExt;
2021
use risingwave_pb::hummock::hummock_version::Levels;
2122
use risingwave_pb::hummock::{CompactionConfig, InputLevel, Level, LevelType, OverlappingLevel};
@@ -166,7 +167,9 @@ impl LevelCompactionPicker {
166167
self.config.level0_max_compact_file_number,
167168
overlap_strategy.clone(),
168169
self.developer_config.enable_check_task_level_overlap,
169-
self.config.max_l0_compact_level_count as usize,
170+
self.config
171+
.max_l0_compact_level_count
172+
.unwrap_or(compaction_config::max_l0_compact_level_count()) as usize,
170173
);
171174

172175
let mut max_vnode_partition_idx = 0;

src/meta/src/hummock/compaction/picker/compaction_task_validator.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use std::collections::HashMap;
1616
use std::sync::Arc;
1717

18+
use risingwave_common::config::default::compaction_config;
1819
use risingwave_pb::hummock::CompactionConfig;
1920

2021
use super::{CompactionInput, LocalPickerStatistic};
@@ -90,7 +91,12 @@ struct TierCompactionTaskValidationRule {
9091
impl CompactionTaskValidationRule for TierCompactionTaskValidationRule {
9192
fn validate(&self, input: &CompactionInput, stats: &mut LocalPickerStatistic) -> bool {
9293
if input.total_file_count >= self.config.level0_max_compact_file_number
93-
|| input.input_levels.len() >= self.config.max_l0_compact_level_count as usize
94+
|| input.input_levels.len()
95+
>= self
96+
.config
97+
.max_l0_compact_level_count
98+
.unwrap_or(compaction_config::max_l0_compact_level_count())
99+
as usize
94100
{
95101
return true;
96102
}
@@ -124,7 +130,12 @@ impl CompactionTaskValidationRule for IntraCompactionTaskValidationRule {
124130
fn validate(&self, input: &CompactionInput, stats: &mut LocalPickerStatistic) -> bool {
125131
if (input.total_file_count >= self.config.level0_max_compact_file_number
126132
&& input.input_levels.len() > 1)
127-
|| input.input_levels.len() >= self.config.max_l0_compact_level_count as usize
133+
|| input.input_levels.len()
134+
>= self
135+
.config
136+
.max_l0_compact_level_count
137+
.unwrap_or(compaction_config::max_l0_compact_level_count())
138+
as usize
128139
{
129140
return true;
130141
}
@@ -172,7 +183,12 @@ struct BaseCompactionTaskValidationRule {
172183
impl CompactionTaskValidationRule for BaseCompactionTaskValidationRule {
173184
fn validate(&self, input: &CompactionInput, stats: &mut LocalPickerStatistic) -> bool {
174185
if input.total_file_count >= self.config.level0_max_compact_file_number
175-
|| input.input_levels.len() >= self.config.max_l0_compact_level_count as usize
186+
|| input.input_levels.len()
187+
>= self
188+
.config
189+
.max_l0_compact_level_count
190+
.unwrap_or(compaction_config::max_l0_compact_level_count())
191+
as usize
176192
{
177193
return true;
178194
}

src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs

+30-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use std::sync::Arc;
1616

17+
use risingwave_common::config::default::compaction_config;
1718
use risingwave_pb::hummock::hummock_version::Levels;
1819
use risingwave_pb::hummock::{CompactionConfig, InputLevel, LevelType, OverlappingLevel};
1920

@@ -54,10 +55,33 @@ impl CompactionPicker for IntraCompactionPicker {
5455
if let Some(ret) =
5556
self.pick_whole_level(l0, &level_handlers[0], vnode_partition_count, stats)
5657
{
58+
if ret.input_levels.len() < 2 {
59+
tracing::error!(
60+
?ret,
61+
vnode_partition_count,
62+
"pick_whole_level failed to pick enough levels"
63+
);
64+
return None;
65+
}
66+
5767
return Some(ret);
5868
}
5969

60-
self.pick_l0_intra(l0, &level_handlers[0], vnode_partition_count, stats)
70+
if let Some(ret) = self.pick_l0_intra(l0, &level_handlers[0], vnode_partition_count, stats)
71+
{
72+
if ret.input_levels.len() < 2 {
73+
tracing::error!(
74+
?ret,
75+
vnode_partition_count,
76+
"pick_l0_intra failed to pick enough levels"
77+
);
78+
return None;
79+
}
80+
81+
return Some(ret);
82+
}
83+
84+
None
6185
}
6286
}
6387

@@ -144,7 +168,10 @@ impl IntraCompactionPicker {
144168
self.config.level0_max_compact_file_number,
145169
overlap_strategy.clone(),
146170
self.developer_config.enable_check_task_level_overlap,
147-
self.config.max_l0_compact_level_count as usize,
171+
self.config
172+
.max_l0_compact_level_count
173+
.unwrap_or(compaction_config::max_l0_compact_level_count())
174+
as usize,
148175
);
149176

150177
let l0_select_tables_vec = non_overlap_sub_level_picker
@@ -357,7 +384,7 @@ impl WholeLevelCompactionPicker {
357384
table_infos: next_level.table_infos.clone(),
358385
});
359386
}
360-
if !select_level_inputs.is_empty() {
387+
if select_level_inputs.len() > 1 {
361388
let vnode_partition_count =
362389
if select_input_size > self.config.sub_level_max_compaction_bytes / 2 {
363390
partition_count

src/meta/src/hummock/manager/compaction_group_manager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ fn update_compaction_config(target: &mut CompactionConfig, items: &[MutableConfi
758758
.clone_from(&c.compression_algorithm);
759759
}
760760
MutableConfig::MaxL0CompactLevelCount(c) => {
761-
target.max_l0_compact_level_count = *c;
761+
target.max_l0_compact_level_count = Some(*c);
762762
}
763763
}
764764
}

0 commit comments

Comments
 (0)