Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi <[email protected]>
  • Loading branch information
skyzh committed Nov 13, 2024
1 parent 54ecf8a commit f5e8dbc
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 13 deletions.
19 changes: 12 additions & 7 deletions mini-lsm-mvcc/src/compact/tiered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mini-lsm-mvcc/src/table/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions mini-lsm-starter/src/bin/mini-lsm-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ fn main() -> Result<()> {
max_size_amplification_percent: 200,
size_ratio: 1,
min_merge_width: 2,
max_merge_width: None,
}),
CompactionStrategy::Leveled => {
CompactionOptions::Leveled(LeveledCompactionOptions {
Expand Down
1 change: 1 addition & 0 deletions mini-lsm-starter/src/compact/tiered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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 {
Expand Down
2 changes: 1 addition & 1 deletion mini-lsm-starter/src/table/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Bloom {
true
} else {
let nbits = self.filter.bit_len();
let delta = (h >> 17) | (h << 15);
let delta = h.rotate_left(15);

// TODO: probe the bloom filter

Expand Down
2 changes: 1 addition & 1 deletion mini-lsm/src/compact/tiered.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, usize};
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

Expand Down
4 changes: 2 additions & 2 deletions mini-lsm/src/table/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions mini-lsm/src/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions mini-lsm/src/tests/week2_day3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn test_integration() {
max_size_amplification_percent: 200,
size_ratio: 1,
min_merge_width: 2,
max_merge_width: None,
},
)),
)
Expand Down
1 change: 1 addition & 0 deletions mini-lsm/src/tests/week2_day5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn test_integration_tiered() {
max_size_amplification_percent: 200,
size_ratio: 1,
min_merge_width: 3,
max_merge_width: None,
}))
}

Expand Down
1 change: 1 addition & 0 deletions mini-lsm/src/tests/week2_day6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn test_integration_tiered() {
max_size_amplification_percent: 200,
size_ratio: 1,
min_merge_width: 3,
max_merge_width: None,
}))
}

Expand Down

0 comments on commit f5e8dbc

Please sign in to comment.