fix clippy warnings

Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
Alex Chi
2024-01-24 14:39:00 +08:00
parent 4d676a451a
commit 0d995dff19
9 changed files with 50 additions and 51 deletions

View File

@@ -70,6 +70,12 @@ pub struct MockStorage {
total_writes: usize, total_writes: usize,
} }
impl Default for MockStorage {
fn default() -> Self {
Self::new()
}
}
impl MockStorage { impl MockStorage {
pub fn new() -> Self { pub fn new() -> Self {
let snapshot = LsmStorageState { let snapshot = LsmStorageState {
@@ -206,8 +212,8 @@ fn generate_random_split(
let ne = begin + len * (i + 1) / split - 1; let ne = begin + len * (i + 1) / split - 1;
let mut begin_bytes = BytesMut::new(); let mut begin_bytes = BytesMut::new();
let mut end_bytes = BytesMut::new(); let mut end_bytes = BytesMut::new();
begin_bytes.put_u64(nb as u64); begin_bytes.put_u64(nb);
end_bytes.put_u64(ne as u64); end_bytes.put_u64(ne);
result.push((begin_bytes.into(), end_bytes.into())); result.push((begin_bytes.into(), end_bytes.into()));
} }
result result

View File

@@ -51,13 +51,13 @@ impl CompactionController {
pub fn generate_compaction_task(&self, snapshot: &LsmStorageState) -> Option<CompactionTask> { pub fn generate_compaction_task(&self, snapshot: &LsmStorageState) -> Option<CompactionTask> {
match self { match self {
CompactionController::Leveled(ctrl) => ctrl CompactionController::Leveled(ctrl) => ctrl
.generate_compaction_task(&snapshot) .generate_compaction_task(snapshot)
.map(CompactionTask::Leveled), .map(CompactionTask::Leveled),
CompactionController::Simple(ctrl) => ctrl CompactionController::Simple(ctrl) => ctrl
.generate_compaction_task(&snapshot) .generate_compaction_task(snapshot)
.map(CompactionTask::Simple), .map(CompactionTask::Simple),
CompactionController::Tiered(ctrl) => ctrl CompactionController::Tiered(ctrl) => ctrl
.generate_compaction_task(&snapshot) .generate_compaction_task(snapshot)
.map(CompactionTask::Tiered), .map(CompactionTask::Tiered),
CompactionController::NoCompaction => unreachable!(), CompactionController::NoCompaction => unreachable!(),
} }
@@ -71,13 +71,13 @@ impl CompactionController {
) -> (LsmStorageState, Vec<usize>) { ) -> (LsmStorageState, Vec<usize>) {
match (self, task) { match (self, task) {
(CompactionController::Leveled(ctrl), CompactionTask::Leveled(task)) => { (CompactionController::Leveled(ctrl), CompactionTask::Leveled(task)) => {
ctrl.apply_compaction_result(&snapshot, task, output) ctrl.apply_compaction_result(snapshot, task, output)
} }
(CompactionController::Simple(ctrl), CompactionTask::Simple(task)) => { (CompactionController::Simple(ctrl), CompactionTask::Simple(task)) => {
ctrl.apply_compaction_result(&snapshot, task, output) ctrl.apply_compaction_result(snapshot, task, output)
} }
(CompactionController::Tiered(ctrl), CompactionTask::Tiered(task)) => { (CompactionController::Tiered(ctrl), CompactionTask::Tiered(task)) => {
ctrl.apply_compaction_result(&snapshot, task, output) ctrl.apply_compaction_result(snapshot, task, output)
} }
_ => unreachable!(), _ => unreachable!(),
} }
@@ -86,11 +86,10 @@ impl CompactionController {
impl CompactionController { impl CompactionController {
pub fn flush_to_l0(&self) -> bool { pub fn flush_to_l0(&self) -> bool {
if let Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction = self { matches!(
true self,
} else { Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction
false )
}
} }
} }
@@ -164,6 +163,6 @@ impl LsmStorageInner {
} }
} }
}); });
return Ok(Some(handle)); Ok(Some(handle))
} }
} }

View File

@@ -57,13 +57,13 @@ impl CompactionController {
pub fn generate_compaction_task(&self, snapshot: &LsmStorageState) -> Option<CompactionTask> { pub fn generate_compaction_task(&self, snapshot: &LsmStorageState) -> Option<CompactionTask> {
match self { match self {
CompactionController::Leveled(ctrl) => ctrl CompactionController::Leveled(ctrl) => ctrl
.generate_compaction_task(&snapshot) .generate_compaction_task(snapshot)
.map(CompactionTask::Leveled), .map(CompactionTask::Leveled),
CompactionController::Simple(ctrl) => ctrl CompactionController::Simple(ctrl) => ctrl
.generate_compaction_task(&snapshot) .generate_compaction_task(snapshot)
.map(CompactionTask::Simple), .map(CompactionTask::Simple),
CompactionController::Tiered(ctrl) => ctrl CompactionController::Tiered(ctrl) => ctrl
.generate_compaction_task(&snapshot) .generate_compaction_task(snapshot)
.map(CompactionTask::Tiered), .map(CompactionTask::Tiered),
CompactionController::NoCompaction => unreachable!(), CompactionController::NoCompaction => unreachable!(),
} }
@@ -77,13 +77,13 @@ impl CompactionController {
) -> (LsmStorageState, Vec<usize>) { ) -> (LsmStorageState, Vec<usize>) {
match (self, task) { match (self, task) {
(CompactionController::Leveled(ctrl), CompactionTask::Leveled(task)) => { (CompactionController::Leveled(ctrl), CompactionTask::Leveled(task)) => {
ctrl.apply_compaction_result(&snapshot, task, output) ctrl.apply_compaction_result(snapshot, task, output)
} }
(CompactionController::Simple(ctrl), CompactionTask::Simple(task)) => { (CompactionController::Simple(ctrl), CompactionTask::Simple(task)) => {
ctrl.apply_compaction_result(&snapshot, task, output) ctrl.apply_compaction_result(snapshot, task, output)
} }
(CompactionController::Tiered(ctrl), CompactionTask::Tiered(task)) => { (CompactionController::Tiered(ctrl), CompactionTask::Tiered(task)) => {
ctrl.apply_compaction_result(&snapshot, task, output) ctrl.apply_compaction_result(snapshot, task, output)
} }
_ => unreachable!(), _ => unreachable!(),
} }
@@ -92,11 +92,10 @@ impl CompactionController {
impl CompactionController { impl CompactionController {
pub fn flush_to_l0(&self) -> bool { pub fn flush_to_l0(&self) -> bool {
if let Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction = self { matches!(
true self,
} else { Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction
false )
}
} }
} }
@@ -379,10 +378,11 @@ impl LsmStorageInner {
} }
fn trigger_flush(&self) -> Result<()> { fn trigger_flush(&self) -> Result<()> {
if { let res = {
let state = self.state.read(); let state = self.state.read();
state.imm_memtables.len() >= self.options.num_memtable_limit state.imm_memtables.len() >= self.options.num_memtable_limit
} { };
if res {
self.force_flush_next_imm_memtable()?; self.force_flush_next_imm_memtable()?;
} }
@@ -405,6 +405,6 @@ impl LsmStorageInner {
} }
} }
}); });
return Ok(Some(handle)); Ok(Some(handle))
} }
} }

View File

@@ -78,7 +78,7 @@ impl LeveledCompactionController {
.sum::<u64>() as usize, .sum::<u64>() as usize,
); );
} }
let base_level_size_bytes = self.options.base_level_size_mb as usize * 1024 * 1024; let base_level_size_bytes = self.options.base_level_size_mb * 1024 * 1024;
// select base level and compute target level size // select base level and compute target level size
target_level_size[self.options.max_levels - 1] = target_level_size[self.options.max_levels - 1] =

View File

@@ -71,8 +71,7 @@ impl SstConcatIterator {
} }
fn move_until_valid(&mut self) -> Result<()> { fn move_until_valid(&mut self) -> Result<()> {
loop { while let Some(iter) = self.current.as_mut() {
if let Some(iter) = self.current.as_mut() {
if iter.is_valid() { if iter.is_valid() {
break; break;
} }
@@ -84,9 +83,6 @@ impl SstConcatIterator {
)?); )?);
self.next_sst_idx += 1; self.next_sst_idx += 1;
} }
} else {
break;
}
} }
Ok(()) Ok(())
} }

View File

@@ -22,11 +22,9 @@ impl<A: StorageIterator, B: StorageIterator> TwoMergeIterator<A, B> {
} }
fn skip_b(&mut self) -> Result<()> { fn skip_b(&mut self) -> Result<()> {
if self.a.is_valid() { if self.a.is_valid() && self.b.is_valid() && self.b.key() == self.a.key() {
if self.b.is_valid() && self.b.key() == self.a.key() {
self.b.next()?; self.b.next()?;
} }
}
Ok(()) Ok(())
} }

View File

@@ -336,7 +336,7 @@ impl LsmStorageInner {
for table_id in state for table_id in state
.l0_sstables .l0_sstables
.iter() .iter()
.chain(state.levels.iter().map(|(_, files)| files).flatten()) .chain(state.levels.iter().flat_map(|(_, files)| files))
{ {
let table_id = *table_id; let table_id = *table_id;
let sst = SsTable::open( let sst = SsTable::open(

View File

@@ -43,9 +43,9 @@ impl Manifest {
.context("failed to recover manifest")?; .context("failed to recover manifest")?;
let mut buf = Vec::new(); let mut buf = Vec::new();
file.read_to_end(&mut buf)?; file.read_to_end(&mut buf)?;
let mut stream = Deserializer::from_slice(&buf).into_iter::<ManifestRecord>(); let stream = Deserializer::from_slice(&buf).into_iter::<ManifestRecord>();
let mut records = Vec::new(); let mut records = Vec::new();
while let Some(x) = stream.next() { for x in stream {
records.push(x?); records.push(x?);
} }
Ok(( Ok((

View File

@@ -71,7 +71,7 @@ fn test_task3_block_key_compression() {
} }
let dir = tempdir().unwrap(); let dir = tempdir().unwrap();
let path = dir.path().join("1.sst"); let path = dir.path().join("1.sst");
let sst = builder.build_for_test(&path).unwrap(); let sst = builder.build_for_test(path).unwrap();
assert!( assert!(
sst.block_meta.len() <= 25, sst.block_meta.len() <= 25,
"you have {} blocks, expect 25", "you have {} blocks, expect 25",