Skip to content

Commit eb2a946

Browse files
fix(meta): fix pick a single level and repeated compact task (#8141) (#8187)
Approved-By: Li0k Co-authored-by: Wallace <[email protected]>
1 parent 6f5c29e commit eb2a946

File tree

1 file changed

+48
-19
lines changed

1 file changed

+48
-19
lines changed

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

+48-19
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl TierCompactionPicker {
6868

6969
let max_compaction_bytes = std::cmp::min(
7070
self.config.max_compaction_bytes,
71-
self.config.max_bytes_for_level_base * 2,
71+
self.config.sub_level_max_compaction_bytes,
7272
);
7373

7474
let mut compaction_bytes = level.total_file_size;
@@ -77,7 +77,7 @@ impl TierCompactionPicker {
7777
let mut waiting_enough_files = true;
7878

7979
for other in &l0.sub_levels[idx + 1..] {
80-
if compaction_bytes >= max_compaction_bytes {
80+
if compaction_bytes > max_compaction_bytes {
8181
waiting_enough_files = false;
8282
break;
8383
}
@@ -122,12 +122,11 @@ impl TierCompactionPicker {
122122
// compact task never be trigger.
123123
if level.level_type == non_overlapping_type
124124
&& is_write_amp_large
125-
&& waiting_enough_files
125+
&& select_level_inputs.len() < self.config.level0_tier_compact_file_number as usize
126126
{
127127
stats.skip_by_write_amp_limit += 1;
128128
continue;
129129
}
130-
131130
select_level_inputs.reverse();
132131

133132
return Some(CompactionInput {
@@ -217,8 +216,9 @@ impl CompactionPicker for TierCompactionPicker {
217216
pub mod tests {
218217
use std::sync::Arc;
219218

219+
use risingwave_hummock_sdk::compaction_group::hummock_version_ext::new_sub_level;
220220
use risingwave_pb::hummock::hummock_version::Levels;
221-
use risingwave_pb::hummock::LevelType;
221+
use risingwave_pb::hummock::{LevelType, OverlappingLevel};
222222

223223
use crate::hummock::compaction::compaction_config::CompactionConfigBuilder;
224224
use crate::hummock::compaction::level_selector::tests::{
@@ -362,10 +362,10 @@ pub mod tests {
362362
let l0 = generate_l0_overlapping_sublevels(vec![
363363
vec![
364364
generate_table(4, 1, 10, 90, 1),
365-
generate_table(5, 1, 210, 220, 1),
365+
generate_table(5, 1, 200, 220, 1),
366366
],
367-
vec![generate_table(6, 1, 0, 100, 1)],
368-
vec![generate_table(7, 1, 0, 100, 1)],
367+
vec![generate_table(6, 1, 1, 100, 1)],
368+
vec![generate_table(7, 1, 1, 100, 1)],
369369
]);
370370
let mut levels = Levels {
371371
l0: Some(l0),
@@ -377,7 +377,7 @@ pub mod tests {
377377
let config = Arc::new(
378378
CompactionConfigBuilder::new()
379379
.level0_tier_compact_file_number(2)
380-
.sub_level_max_compaction_bytes(1)
380+
.sub_level_max_compaction_bytes(100)
381381
.max_compaction_bytes(500000)
382382
.build(),
383383
);
@@ -386,24 +386,53 @@ pub mod tests {
386386
// sub-level 0 is excluded because it's nonoverlapping and violating
387387
// sub_level_max_compaction_bytes.
388388
let mut picker =
389-
TierCompactionPicker::new(config.clone(), Arc::new(RangeOverlapStrategy::default()));
389+
TierCompactionPicker::new(config, Arc::new(RangeOverlapStrategy::default()));
390390
let ret = picker
391391
.pick_compaction(&levels, &levels_handler, &mut local_stats)
392392
.unwrap();
393393
assert_eq!(ret.input_levels.len(), 2);
394394
assert_eq!(ret.target_level, 0);
395395
assert_eq!(ret.target_sub_level_id, 1);
396+
}
396397

397-
// sub-level 0 is included because it's overlapping even if violating
398-
// sub_level_max_compaction_bytes.
399-
levels.l0.as_mut().unwrap().sub_levels[0].level_type = LevelType::Overlapping as i32;
398+
#[test]
399+
fn test_write_amp_bug_skip() {
400+
let l1 = new_sub_level(
401+
1,
402+
LevelType::Nonoverlapping,
403+
vec![
404+
generate_table(3, 1, 1, 50, 1),
405+
generate_table(4, 1, 51, 100, 1),
406+
],
407+
);
408+
let l2 = new_sub_level(
409+
2,
410+
LevelType::Nonoverlapping,
411+
vec![
412+
generate_table(3, 1, 1, 50, 1),
413+
generate_table(4, 1, 51, 200, 1),
414+
],
415+
);
416+
let levels = Levels {
417+
l0: Some(OverlappingLevel {
418+
total_file_size: l1.total_file_size + l2.total_file_size,
419+
sub_levels: vec![l1, l2],
420+
}),
421+
levels: vec![],
422+
..Default::default()
423+
};
424+
let config = Arc::new(
425+
CompactionConfigBuilder::new()
426+
.level0_tier_compact_file_number(4)
427+
.sub_level_max_compaction_bytes(100)
428+
.max_compaction_bytes(500000)
429+
.build(),
430+
);
431+
let levels_handler = vec![LevelHandler::new(0), LevelHandler::new(1)];
432+
let mut local_stats = LocalPickerStatistic::default();
400433
let mut picker =
401434
TierCompactionPicker::new(config, Arc::new(RangeOverlapStrategy::default()));
402-
let ret = picker
403-
.pick_compaction(&levels, &levels_handler, &mut local_stats)
404-
.unwrap();
405-
assert_eq!(ret.input_levels.len(), 3);
406-
assert_eq!(ret.target_level, 0);
407-
assert_eq!(ret.target_sub_level_id, 0);
435+
let ret = picker.pick_compaction(&levels, &levels_handler, &mut local_stats);
436+
assert!(ret.is_none());
408437
}
409438
}

0 commit comments

Comments
 (0)