Skip to content

Commit 0d995df

Browse files
committed
fix clippy warnings
Signed-off-by: Alex Chi <iskyzh@gmail.com>
1 parent 4d676a4 commit 0d995df

File tree

9 files changed

+50
-51
lines changed

9 files changed

+50
-51
lines changed

mini-lsm-starter/src/bin/compaction-simulator.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ pub struct MockStorage {
7070
total_writes: usize,
7171
}
7272

73+
impl Default for MockStorage {
74+
fn default() -> Self {
75+
Self::new()
76+
}
77+
}
78+
7379
impl MockStorage {
7480
pub fn new() -> Self {
7581
let snapshot = LsmStorageState {
@@ -206,8 +212,8 @@ fn generate_random_split(
206212
let ne = begin + len * (i + 1) / split - 1;
207213
let mut begin_bytes = BytesMut::new();
208214
let mut end_bytes = BytesMut::new();
209-
begin_bytes.put_u64(nb as u64);
210-
end_bytes.put_u64(ne as u64);
215+
begin_bytes.put_u64(nb);
216+
end_bytes.put_u64(ne);
211217
result.push((begin_bytes.into(), end_bytes.into()));
212218
}
213219
result

mini-lsm-starter/src/compact.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ impl CompactionController {
5151
pub fn generate_compaction_task(&self, snapshot: &LsmStorageState) -> Option<CompactionTask> {
5252
match self {
5353
CompactionController::Leveled(ctrl) => ctrl
54-
.generate_compaction_task(&snapshot)
54+
.generate_compaction_task(snapshot)
5555
.map(CompactionTask::Leveled),
5656
CompactionController::Simple(ctrl) => ctrl
57-
.generate_compaction_task(&snapshot)
57+
.generate_compaction_task(snapshot)
5858
.map(CompactionTask::Simple),
5959
CompactionController::Tiered(ctrl) => ctrl
60-
.generate_compaction_task(&snapshot)
60+
.generate_compaction_task(snapshot)
6161
.map(CompactionTask::Tiered),
6262
CompactionController::NoCompaction => unreachable!(),
6363
}
@@ -71,13 +71,13 @@ impl CompactionController {
7171
) -> (LsmStorageState, Vec<usize>) {
7272
match (self, task) {
7373
(CompactionController::Leveled(ctrl), CompactionTask::Leveled(task)) => {
74-
ctrl.apply_compaction_result(&snapshot, task, output)
74+
ctrl.apply_compaction_result(snapshot, task, output)
7575
}
7676
(CompactionController::Simple(ctrl), CompactionTask::Simple(task)) => {
77-
ctrl.apply_compaction_result(&snapshot, task, output)
77+
ctrl.apply_compaction_result(snapshot, task, output)
7878
}
7979
(CompactionController::Tiered(ctrl), CompactionTask::Tiered(task)) => {
80-
ctrl.apply_compaction_result(&snapshot, task, output)
80+
ctrl.apply_compaction_result(snapshot, task, output)
8181
}
8282
_ => unreachable!(),
8383
}
@@ -86,11 +86,10 @@ impl CompactionController {
8686

8787
impl CompactionController {
8888
pub fn flush_to_l0(&self) -> bool {
89-
if let Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction = self {
90-
true
91-
} else {
92-
false
93-
}
89+
matches!(
90+
self,
91+
Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction
92+
)
9493
}
9594
}
9695

@@ -164,6 +163,6 @@ impl LsmStorageInner {
164163
}
165164
}
166165
});
167-
return Ok(Some(handle));
166+
Ok(Some(handle))
168167
}
169168
}

mini-lsm/src/compact.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ impl CompactionController {
5757
pub fn generate_compaction_task(&self, snapshot: &LsmStorageState) -> Option<CompactionTask> {
5858
match self {
5959
CompactionController::Leveled(ctrl) => ctrl
60-
.generate_compaction_task(&snapshot)
60+
.generate_compaction_task(snapshot)
6161
.map(CompactionTask::Leveled),
6262
CompactionController::Simple(ctrl) => ctrl
63-
.generate_compaction_task(&snapshot)
63+
.generate_compaction_task(snapshot)
6464
.map(CompactionTask::Simple),
6565
CompactionController::Tiered(ctrl) => ctrl
66-
.generate_compaction_task(&snapshot)
66+
.generate_compaction_task(snapshot)
6767
.map(CompactionTask::Tiered),
6868
CompactionController::NoCompaction => unreachable!(),
6969
}
@@ -77,13 +77,13 @@ impl CompactionController {
7777
) -> (LsmStorageState, Vec<usize>) {
7878
match (self, task) {
7979
(CompactionController::Leveled(ctrl), CompactionTask::Leveled(task)) => {
80-
ctrl.apply_compaction_result(&snapshot, task, output)
80+
ctrl.apply_compaction_result(snapshot, task, output)
8181
}
8282
(CompactionController::Simple(ctrl), CompactionTask::Simple(task)) => {
83-
ctrl.apply_compaction_result(&snapshot, task, output)
83+
ctrl.apply_compaction_result(snapshot, task, output)
8484
}
8585
(CompactionController::Tiered(ctrl), CompactionTask::Tiered(task)) => {
86-
ctrl.apply_compaction_result(&snapshot, task, output)
86+
ctrl.apply_compaction_result(snapshot, task, output)
8787
}
8888
_ => unreachable!(),
8989
}
@@ -92,11 +92,10 @@ impl CompactionController {
9292

9393
impl CompactionController {
9494
pub fn flush_to_l0(&self) -> bool {
95-
if let Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction = self {
96-
true
97-
} else {
98-
false
99-
}
95+
matches!(
96+
self,
97+
Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction
98+
)
10099
}
101100
}
102101

@@ -379,10 +378,11 @@ impl LsmStorageInner {
379378
}
380379

381380
fn trigger_flush(&self) -> Result<()> {
382-
if {
381+
let res = {
383382
let state = self.state.read();
384383
state.imm_memtables.len() >= self.options.num_memtable_limit
385-
} {
384+
};
385+
if res {
386386
self.force_flush_next_imm_memtable()?;
387387
}
388388

@@ -405,6 +405,6 @@ impl LsmStorageInner {
405405
}
406406
}
407407
});
408-
return Ok(Some(handle));
408+
Ok(Some(handle))
409409
}
410410
}

mini-lsm/src/compact/leveled.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl LeveledCompactionController {
7878
.sum::<u64>() as usize,
7979
);
8080
}
81-
let base_level_size_bytes = self.options.base_level_size_mb as usize * 1024 * 1024;
81+
let base_level_size_bytes = self.options.base_level_size_mb * 1024 * 1024;
8282

8383
// select base level and compute target level size
8484
target_level_size[self.options.max_levels - 1] =

mini-lsm/src/iterators/concat_iterator.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,18 @@ impl SstConcatIterator {
7171
}
7272

7373
fn move_until_valid(&mut self) -> Result<()> {
74-
loop {
75-
if let Some(iter) = self.current.as_mut() {
76-
if iter.is_valid() {
77-
break;
78-
}
79-
if self.next_sst_idx >= self.sstables.len() {
80-
self.current = None;
81-
} else {
82-
self.current = Some(SsTableIterator::create_and_seek_to_first(
83-
self.sstables[self.next_sst_idx].clone(),
84-
)?);
85-
self.next_sst_idx += 1;
86-
}
87-
} else {
74+
while let Some(iter) = self.current.as_mut() {
75+
if iter.is_valid() {
8876
break;
8977
}
78+
if self.next_sst_idx >= self.sstables.len() {
79+
self.current = None;
80+
} else {
81+
self.current = Some(SsTableIterator::create_and_seek_to_first(
82+
self.sstables[self.next_sst_idx].clone(),
83+
)?);
84+
self.next_sst_idx += 1;
85+
}
9086
}
9187
Ok(())
9288
}

mini-lsm/src/iterators/two_merge_iterator.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ impl<A: StorageIterator, B: StorageIterator> TwoMergeIterator<A, B> {
2222
}
2323

2424
fn skip_b(&mut self) -> Result<()> {
25-
if self.a.is_valid() {
26-
if self.b.is_valid() && self.b.key() == self.a.key() {
27-
self.b.next()?;
28-
}
25+
if self.a.is_valid() && self.b.is_valid() && self.b.key() == self.a.key() {
26+
self.b.next()?;
2927
}
3028
Ok(())
3129
}

mini-lsm/src/lsm_storage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl LsmStorageInner {
336336
for table_id in state
337337
.l0_sstables
338338
.iter()
339-
.chain(state.levels.iter().map(|(_, files)| files).flatten())
339+
.chain(state.levels.iter().flat_map(|(_, files)| files))
340340
{
341341
let table_id = *table_id;
342342
let sst = SsTable::open(

mini-lsm/src/manifest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ impl Manifest {
4343
.context("failed to recover manifest")?;
4444
let mut buf = Vec::new();
4545
file.read_to_end(&mut buf)?;
46-
let mut stream = Deserializer::from_slice(&buf).into_iter::<ManifestRecord>();
46+
let stream = Deserializer::from_slice(&buf).into_iter::<ManifestRecord>();
4747
let mut records = Vec::new();
48-
while let Some(x) = stream.next() {
48+
for x in stream {
4949
records.push(x?);
5050
}
5151
Ok((

mini-lsm/src/tests/week1_day7.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn test_task3_block_key_compression() {
7171
}
7272
let dir = tempdir().unwrap();
7373
let path = dir.path().join("1.sst");
74-
let sst = builder.build_for_test(&path).unwrap();
74+
let sst = builder.build_for_test(path).unwrap();
7575
assert!(
7676
sst.block_meta.len() <= 25,
7777
"you have {} blocks, expect 25",

0 commit comments

Comments
 (0)