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
|
||||
|
@@ -87,7 +87,7 @@ impl Bloom {
|
||||
filter.resize(nbytes, 0);
|
||||
for h in keys {
|
||||
let mut h = *h;
|
||||
let delta = (h >> 17) | (h << 15);
|
||||
let delta = h.rotate_left(15);
|
||||
for _ in 0..k {
|
||||
let bit_pos = (h as usize) % nbits;
|
||||
filter.set_bit(bit_pos, true);
|
||||
@@ -107,7 +107,7 @@ impl Bloom {
|
||||
true
|
||||
} else {
|
||||
let nbits = self.filter.bit_len();
|
||||
let delta = (h >> 17) | (h << 15);
|
||||
let delta = h.rotate_left(15);
|
||||
for _ in 0..self.k {
|
||||
let bit_pos = h % (nbits as u32);
|
||||
if !self.filter.get_bit(bit_pos as usize) {
|
||||
|
@@ -368,6 +368,7 @@ pub fn check_compaction_ratio(storage: Arc<MiniLsm>) {
|
||||
max_size_amplification_percent,
|
||||
size_ratio,
|
||||
min_merge_width,
|
||||
..
|
||||
}) => {
|
||||
let size_ratio_trigger = (100.0 + size_ratio as f64) / 100.0;
|
||||
assert_eq!(l0_sst_num, 0);
|
||||
|
@@ -18,6 +18,7 @@ fn test_integration() {
|
||||
max_size_amplification_percent: 200,
|
||||
size_ratio: 1,
|
||||
min_merge_width: 2,
|
||||
max_merge_width: None,
|
||||
},
|
||||
)),
|
||||
)
|
||||
|
@@ -29,6 +29,7 @@ fn test_integration_tiered() {
|
||||
max_size_amplification_percent: 200,
|
||||
size_ratio: 1,
|
||||
min_merge_width: 3,
|
||||
max_merge_width: None,
|
||||
}))
|
||||
}
|
||||
|
||||
|
@@ -26,6 +26,7 @@ fn test_integration_tiered() {
|
||||
max_size_amplification_percent: 200,
|
||||
size_ratio: 1,
|
||||
min_merge_width: 3,
|
||||
max_merge_width: None,
|
||||
}))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user