@@ -15,8 +15,8 @@ use snafu::Snafu;
15
15
16
16
use crate :: {
17
17
compaction:: {
18
- CompactionInputFiles , CompactionStrategy , CompactionTask , SizeTieredCompactionOptions ,
19
- TimeWindowCompactionOptions ,
18
+ CompactionInputFiles , CompactionStrategy , CompactionTask , CompactionTaskBuilder ,
19
+ SizeTieredCompactionOptions , TimeWindowCompactionOptions ,
20
20
} ,
21
21
sst:: {
22
22
file:: { FileHandle , Level } ,
@@ -60,7 +60,7 @@ pub trait CompactionPicker {
60
60
fn pick_compaction (
61
61
& self ,
62
62
ctx : PickerContext ,
63
- levels_controller : & LevelsController ,
63
+ levels_controller : & mut LevelsController ,
64
64
) -> Result < CompactionTask > ;
65
65
}
66
66
@@ -86,10 +86,10 @@ pub struct CommonCompactionPicker {
86
86
impl CommonCompactionPicker {
87
87
pub fn new ( strategy : CompactionStrategy ) -> Self {
88
88
let level_picker: LevelPickerRef = match strategy {
89
- CompactionStrategy :: SizeTiered ( _) | CompactionStrategy :: Default => {
90
- Arc :: new ( SizeTieredPicker :: default ( ) )
89
+ CompactionStrategy :: SizeTiered ( _) => Arc :: new ( SizeTieredPicker :: default ( ) ) ,
90
+ CompactionStrategy :: TimeWindow ( _) | CompactionStrategy :: Default => {
91
+ Arc :: new ( TimeWindowPicker :: default ( ) )
91
92
}
92
- CompactionStrategy :: TimeWindow ( _) => Arc :: new ( TimeWindowPicker :: default ( ) ) ,
93
93
} ;
94
94
Self { level_picker }
95
95
}
@@ -123,13 +123,11 @@ impl CompactionPicker for CommonCompactionPicker {
123
123
fn pick_compaction (
124
124
& self ,
125
125
ctx : PickerContext ,
126
- levels_controller : & LevelsController ,
126
+ levels_controller : & mut LevelsController ,
127
127
) -> Result < CompactionTask > {
128
128
let expire_time = ctx. ttl . map ( Timestamp :: expire_time) ;
129
- let mut compaction_task = CompactionTask {
130
- expired : levels_controller. expired_ssts ( expire_time) ,
131
- ..Default :: default ( )
132
- } ;
129
+ let mut builder =
130
+ CompactionTaskBuilder :: with_expired ( levels_controller. expired_ssts ( expire_time) ) ;
133
131
134
132
if let Some ( input_files) =
135
133
self . pick_compact_candidates ( & ctx, levels_controller, expire_time)
@@ -139,10 +137,10 @@ impl CompactionPicker for CommonCompactionPicker {
139
137
ctx. strategy, input_files
140
138
) ;
141
139
142
- compaction_task . compaction_inputs = vec ! [ input_files] ;
140
+ builder . add_inputs ( input_files) ;
143
141
}
144
142
145
- Ok ( compaction_task )
143
+ Ok ( builder . build ( ) )
146
144
}
147
145
}
148
146
@@ -734,39 +732,39 @@ mod tests {
734
732
} ;
735
733
let now = Timestamp :: now ( ) ;
736
734
{
737
- let lc = build_old_bucket_case ( now. as_i64 ( ) ) ;
738
- let task = twp. pick_compaction ( ctx. clone ( ) , & lc) . unwrap ( ) ;
739
- assert_eq ! ( task. compaction_inputs [ 0 ] . files. len( ) , 2 ) ;
740
- assert_eq ! ( task. compaction_inputs [ 0 ] . files[ 0 ] . id( ) , 0 ) ;
741
- assert_eq ! ( task. compaction_inputs [ 0 ] . files[ 1 ] . id( ) , 1 ) ;
735
+ let mut lc = build_old_bucket_case ( now. as_i64 ( ) ) ;
736
+ let task = twp. pick_compaction ( ctx. clone ( ) , & mut lc) . unwrap ( ) ;
737
+ assert_eq ! ( task. inputs [ 0 ] . files. len( ) , 2 ) ;
738
+ assert_eq ! ( task. inputs [ 0 ] . files[ 0 ] . id( ) , 0 ) ;
739
+ assert_eq ! ( task. inputs [ 0 ] . files[ 1 ] . id( ) , 1 ) ;
742
740
assert_eq ! ( task. expired[ 0 ] . files. len( ) , 1 ) ;
743
741
assert_eq ! ( task. expired[ 0 ] . files[ 0 ] . id( ) , 3 ) ;
744
742
}
745
743
746
744
{
747
- let lc = build_newest_bucket_case ( now. as_i64 ( ) ) ;
748
- let task = twp. pick_compaction ( ctx. clone ( ) , & lc) . unwrap ( ) ;
749
- assert_eq ! ( task. compaction_inputs [ 0 ] . files. len( ) , 4 ) ;
750
- assert_eq ! ( task. compaction_inputs [ 0 ] . files[ 0 ] . id( ) , 2 ) ;
751
- assert_eq ! ( task. compaction_inputs [ 0 ] . files[ 1 ] . id( ) , 3 ) ;
752
- assert_eq ! ( task. compaction_inputs [ 0 ] . files[ 2 ] . id( ) , 4 ) ;
753
- assert_eq ! ( task. compaction_inputs [ 0 ] . files[ 3 ] . id( ) , 5 ) ;
745
+ let mut lc = build_newest_bucket_case ( now. as_i64 ( ) ) ;
746
+ let task = twp. pick_compaction ( ctx. clone ( ) , & mut lc) . unwrap ( ) ;
747
+ assert_eq ! ( task. inputs [ 0 ] . files. len( ) , 4 ) ;
748
+ assert_eq ! ( task. inputs [ 0 ] . files[ 0 ] . id( ) , 2 ) ;
749
+ assert_eq ! ( task. inputs [ 0 ] . files[ 1 ] . id( ) , 3 ) ;
750
+ assert_eq ! ( task. inputs [ 0 ] . files[ 2 ] . id( ) , 4 ) ;
751
+ assert_eq ! ( task. inputs [ 0 ] . files[ 3 ] . id( ) , 5 ) ;
754
752
}
755
753
756
754
{
757
- let lc = build_newest_bucket_no_match_case ( now. as_i64 ( ) ) ;
758
- let task = twp. pick_compaction ( ctx. clone ( ) , & lc) . unwrap ( ) ;
759
- assert_eq ! ( task. compaction_inputs . len( ) , 0 ) ;
755
+ let mut lc = build_newest_bucket_no_match_case ( now. as_i64 ( ) ) ;
756
+ let task = twp. pick_compaction ( ctx. clone ( ) , & mut lc) . unwrap ( ) ;
757
+ assert_eq ! ( task. inputs . len( ) , 0 ) ;
760
758
}
761
759
762
760
// If ttl is None, then no file is expired.
763
761
ctx. ttl = None ;
764
762
{
765
- let lc = build_old_bucket_case ( now. as_i64 ( ) ) ;
766
- let task = twp. pick_compaction ( ctx, & lc) . unwrap ( ) ;
767
- assert_eq ! ( task. compaction_inputs [ 0 ] . files. len( ) , 2 ) ;
768
- assert_eq ! ( task. compaction_inputs [ 0 ] . files[ 0 ] . id( ) , 0 ) ;
769
- assert_eq ! ( task. compaction_inputs [ 0 ] . files[ 1 ] . id( ) , 1 ) ;
763
+ let mut lc = build_old_bucket_case ( now. as_i64 ( ) ) ;
764
+ let task = twp. pick_compaction ( ctx, & mut lc) . unwrap ( ) ;
765
+ assert_eq ! ( task. inputs [ 0 ] . files. len( ) , 2 ) ;
766
+ assert_eq ! ( task. inputs [ 0 ] . files[ 0 ] . id( ) , 0 ) ;
767
+ assert_eq ! ( task. inputs [ 0 ] . files[ 1 ] . id( ) , 1 ) ;
770
768
assert ! ( task. expired[ 0 ] . files. is_empty( ) ) ;
771
769
}
772
770
}
0 commit comments