in src/columnar_storage/src/compaction/picker.rs [202:236]
fn test_pick_candidate() {
let segment_duration = Duration::from_millis(20);
let strategy = TimeWindowCompactionStrategy::new(segment_duration, 9999, 10, 2);
let ssts = (0_i64..5_i64)
.map(|i| {
SstFile::new(
i as u64,
FileMeta {
max_sequence: i as u64,
num_rows: i as u32,
size: (100 - i) as u32, // size desc
time_range: (i * 10..(i * 10 + 10)).into(),
},
)
})
.collect_vec();
let task = strategy
.pick_candidate(ssts.clone(), Some(15.into()))
.unwrap();
// ssts should be grouped into three segments:
// | 0 1 | 2 3 | 4 |
let excepted_task = Task {
inputs: vec![ssts[3].clone(), ssts[2].clone()],
expireds: vec![ssts[0].clone()],
};
assert_eq!(task, excepted_task);
// sst1, sst3, ss4 are in compaction, so it should not be picked again.
// sst2, sst5 are in different segment, so it also should not be picked.
let task = strategy.pick_candidate(ssts, None);
assert!(task.is_none());
}