@@ -68,7 +68,7 @@ impl TierCompactionPicker {
68
68
69
69
let max_compaction_bytes = std:: cmp:: min (
70
70
self . config . max_compaction_bytes ,
71
- self . config . max_bytes_for_level_base * 2 ,
71
+ self . config . sub_level_max_compaction_bytes ,
72
72
) ;
73
73
74
74
let mut compaction_bytes = level. total_file_size ;
@@ -77,7 +77,7 @@ impl TierCompactionPicker {
77
77
let mut waiting_enough_files = true ;
78
78
79
79
for other in & l0. sub_levels [ idx + 1 ..] {
80
- if compaction_bytes >= max_compaction_bytes {
80
+ if compaction_bytes > max_compaction_bytes {
81
81
waiting_enough_files = false ;
82
82
break ;
83
83
}
@@ -122,12 +122,11 @@ impl TierCompactionPicker {
122
122
// compact task never be trigger.
123
123
if level. level_type == non_overlapping_type
124
124
&& is_write_amp_large
125
- && waiting_enough_files
125
+ && select_level_inputs . len ( ) < self . config . level0_tier_compact_file_number as usize
126
126
{
127
127
stats. skip_by_write_amp_limit += 1 ;
128
128
continue ;
129
129
}
130
-
131
130
select_level_inputs. reverse ( ) ;
132
131
133
132
return Some ( CompactionInput {
@@ -217,8 +216,9 @@ impl CompactionPicker for TierCompactionPicker {
217
216
pub mod tests {
218
217
use std:: sync:: Arc ;
219
218
219
+ use risingwave_hummock_sdk:: compaction_group:: hummock_version_ext:: new_sub_level;
220
220
use risingwave_pb:: hummock:: hummock_version:: Levels ;
221
- use risingwave_pb:: hummock:: LevelType ;
221
+ use risingwave_pb:: hummock:: { LevelType , OverlappingLevel } ;
222
222
223
223
use crate :: hummock:: compaction:: compaction_config:: CompactionConfigBuilder ;
224
224
use crate :: hummock:: compaction:: level_selector:: tests:: {
@@ -362,10 +362,10 @@ pub mod tests {
362
362
let l0 = generate_l0_overlapping_sublevels ( vec ! [
363
363
vec![
364
364
generate_table( 4 , 1 , 10 , 90 , 1 ) ,
365
- generate_table( 5 , 1 , 210 , 220 , 1 ) ,
365
+ generate_table( 5 , 1 , 200 , 220 , 1 ) ,
366
366
] ,
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 ) ] ,
369
369
] ) ;
370
370
let mut levels = Levels {
371
371
l0 : Some ( l0) ,
@@ -377,7 +377,7 @@ pub mod tests {
377
377
let config = Arc :: new (
378
378
CompactionConfigBuilder :: new ( )
379
379
. level0_tier_compact_file_number ( 2 )
380
- . sub_level_max_compaction_bytes ( 1 )
380
+ . sub_level_max_compaction_bytes ( 100 )
381
381
. max_compaction_bytes ( 500000 )
382
382
. build ( ) ,
383
383
) ;
@@ -386,24 +386,53 @@ pub mod tests {
386
386
// sub-level 0 is excluded because it's nonoverlapping and violating
387
387
// sub_level_max_compaction_bytes.
388
388
let mut picker =
389
- TierCompactionPicker :: new ( config. clone ( ) , Arc :: new ( RangeOverlapStrategy :: default ( ) ) ) ;
389
+ TierCompactionPicker :: new ( config, Arc :: new ( RangeOverlapStrategy :: default ( ) ) ) ;
390
390
let ret = picker
391
391
. pick_compaction ( & levels, & levels_handler, & mut local_stats)
392
392
. unwrap ( ) ;
393
393
assert_eq ! ( ret. input_levels. len( ) , 2 ) ;
394
394
assert_eq ! ( ret. target_level, 0 ) ;
395
395
assert_eq ! ( ret. target_sub_level_id, 1 ) ;
396
+ }
396
397
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 ( ) ;
400
433
let mut picker =
401
434
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( ) ) ;
408
437
}
409
438
}
0 commit comments