fix: universal compaction condition (#97)
Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
@@ -16,6 +16,7 @@ pub struct TieredCompactionOptions {
|
||||
pub max_size_amplification_percent: usize,
|
||||
pub size_ratio: usize,
|
||||
pub min_merge_width: usize,
|
||||
pub max_merge_width: Option<usize>,
|
||||
}
|
||||
|
||||
pub struct TieredCompactionController {
|
||||
@@ -61,25 +62,29 @@ impl TieredCompactionController {
|
||||
for id in 0..(snapshot.levels.len() - 1) {
|
||||
size += snapshot.levels[id].1.len();
|
||||
let next_level_size = snapshot.levels[id + 1].1.len();
|
||||
let current_size_ratio = size as f64 / next_level_size as f64;
|
||||
if current_size_ratio >= size_ratio_trigger && id + 2 >= self.options.min_merge_width {
|
||||
let current_size_ratio = next_level_size as f64 / size as f64;
|
||||
if current_size_ratio > size_ratio_trigger && id + 1 >= self.options.min_merge_width {
|
||||
println!(
|
||||
"compaction triggered by size ratio: {}",
|
||||
current_size_ratio * 100.0
|
||||
"compaction triggered by size ratio: {} > {}",
|
||||
current_size_ratio * 100.0,
|
||||
size_ratio_trigger * 100.0
|
||||
);
|
||||
return Some(TieredCompactionTask {
|
||||
tiers: snapshot
|
||||
.levels
|
||||
.iter()
|
||||
.take(id + 2)
|
||||
.take(id + 1)
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
bottom_tier_included: id + 2 >= snapshot.levels.len(),
|
||||
bottom_tier_included: id + 1 >= snapshot.levels.len(),
|
||||
});
|
||||
}
|
||||
}
|
||||
// trying to reduce sorted runs without respecting size ratio
|
||||
let num_tiers_to_take = snapshot.levels.len() - self.options.num_tiers + 2;
|
||||
let num_tiers_to_take = snapshot
|
||||
.levels
|
||||
.len()
|
||||
.min(self.options.max_merge_width.unwrap_or(usize::MAX));
|
||||
println!("compaction triggered by reducing sorted runs");
|
||||
return Some(TieredCompactionTask {
|
||||
tiers: snapshot
|
||||
|
||||
Reference in New Issue
Block a user