From 3ebab4d8fbb217272c1fabbf58c26edf7d1add2c Mon Sep 17 00:00:00 2001 From: Jauhar Arifin Date: Tue, 13 Aug 2024 18:53:47 +0700 Subject: [PATCH] fix clippy --- benches/db_benchmark.rs | 4 ++-- src/pager.rs | 16 ++++++++-------- src/wal.rs | 6 ++++-- tests/db_crash.rs | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/benches/db_benchmark.rs b/benches/db_benchmark.rs index ebd1141..80b6dbf 100644 --- a/benches/db_benchmark.rs +++ b/benches/db_benchmark.rs @@ -73,8 +73,8 @@ impl<'a> Profiler for FlamegraphProfiler<'a> { fn stop_profiling(&mut self, _benchmark_id: &str, benchmark_dir: &Path) { std::fs::create_dir_all(benchmark_dir).unwrap(); let flamegraph_path = benchmark_dir.join("flamegraph.svg"); - let flamegraph_file = File::create(&flamegraph_path) - .expect("File system error while creating flamegraph.svg"); + let flamegraph_file = + File::create(flamegraph_path).expect("File system error while creating flamegraph.svg"); if let Some(profiler) = self.active_profiler.take() { profiler .report() diff --git a/src/pager.rs b/src/pager.rs index a4e40fc..319c22e 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -489,7 +489,7 @@ impl Pager { let mut internal = self.internal.write(); let pgid = { internal.db_state.page_count += 1; - PageId::new((internal.db_state.page_count - 1) as u64).unwrap() + PageId::new(internal.db_state.page_count - 1).unwrap() }; let lsn = record_mutation( @@ -688,7 +688,7 @@ impl Pager { let mut f = f.lock(); let page_size = buffer.len(); - write_page(&mut *f, pgid, page_size, buffer)?; + write_page(&mut f, pgid, page_size, buffer)?; f.sync_all()?; drop(f); @@ -739,7 +739,7 @@ impl Pager { let mut f = f.lock(); for (i, pgid) in internal.flushing_pgids.iter().enumerate() { write_page( - &mut *f, + &mut f, *pgid, page_size, &internal.flushing_pages[i * page_size..(i + 1) * page_size], @@ -833,7 +833,7 @@ impl Pager { } else { drop(flush_internal); let mut f = self.f.lock(); - read_page(&mut *f, pgid, self.page_size, buff)? + read_page(&mut f, pgid, self.page_size, buff)? } }; if ok { @@ -1099,7 +1099,7 @@ impl Pager { // first, then to the actual page. // TODO: also, we need to make sure that the WAL log is already written safely before we can // write to disk. - write_page(&mut *f, *pgid, self.page_size, buffer)?; + write_page(&mut f, *pgid, self.page_size, buffer)?; } // TODO(important): this is not safe. We can get non-atomic write. @@ -1602,7 +1602,7 @@ impl<'a> InteriorPageWrite<'a> { } pub(crate) fn reset(mut self, ctx: LogContext<'_>) -> anyhow::Result> { - Pager::encode(&self.0.meta, &mut self.0.buffer)?; + Pager::encode(&self.0.meta, self.0.buffer)?; let pgid = self.id(); self.0.meta.lsn = Some(record_mutation( @@ -2211,7 +2211,7 @@ impl<'a> LeafPageWrite<'a> { } pub(crate) fn reset(mut self, ctx: LogContext<'_>) -> anyhow::Result> { - Pager::encode(&self.0.meta, &mut self.0.buffer)?; + Pager::encode(&self.0.meta, self.0.buffer)?; let pgid = self.id(); self.0.meta.lsn = Some(record_mutation( @@ -2845,7 +2845,7 @@ impl<'a> OverflowPageWrite<'a> { } pub(crate) fn reset(mut self, ctx: LogContext<'_>) -> anyhow::Result> { - Pager::encode(&self.0.meta, &mut self.0.buffer)?; + Pager::encode(&self.0.meta, self.0.buffer)?; let pgid = self.id(); self.0.meta.lsn = Some(record_mutation( diff --git a/src/wal.rs b/src/wal.rs index 8e15528..7e0870e 100644 --- a/src/wal.rs +++ b/src/wal.rs @@ -292,8 +292,10 @@ impl<'a> WalBackwardIterator<'a> { self.start_offset -= s; } - let calculated_checksum = - crc64::crc64(0x1d0f, &self.buffer[self.end_offset - size..self.end_offset - 8]); + let calculated_checksum = crc64::crc64( + 0x1d0f, + &self.buffer[self.end_offset - size..self.end_offset - 8], + ); if recorded_checksum != calculated_checksum { // TODO: maybe we can consider this entry as "uncompleted" and then skip it? but if // it's in the middle of the WAL, this entry should be considered broken. diff --git a/tests/db_crash.rs b/tests/db_crash.rs index 76164b0..121b4f4 100644 --- a/tests/db_crash.rs +++ b/tests/db_crash.rs @@ -69,7 +69,7 @@ fn main() { fn worker() { env_logger::init(); - let path = std::env::args().skip(1).next().unwrap(); + let path = std::env::args().nth(1).unwrap(); let db = Db::open( &PathBuf::from(path), Setting {