From 0f049a68c398b1891cba26e44b6342d783cbdd00 Mon Sep 17 00:00:00 2001 From: marvin-j97 Date: Wed, 13 Mar 2024 18:08:23 +0100 Subject: [PATCH] clippy fix --- src/main.rs | 9 +------ src/segment/merge.rs | 1 + src/value_log.rs | 58 +++++++++++++++++++++++--------------------- tests/basic_gc.rs | 2 +- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6671fca..801022d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::{ path::Path, sync::{Arc, RwLock}, }; -use value_log::{Config, Index, IndexWriter, SegmentReader, ValueHandle, ValueLog}; +use value_log::{Config, Index, IndexWriter, ValueHandle, ValueLog}; #[derive(Default)] pub struct DebugIndex(RwLock, ValueHandle>>); @@ -23,13 +23,6 @@ impl Index for DebugIndex { } } -impl DebugIndex { - fn remove(&self, key: &[u8]) -> std::io::Result<()> { - self.0.write().expect("lock is poisoned").remove(key); - Ok(()) - } -} - struct DebugIndexWriter(Arc); impl IndexWriter for DebugIndexWriter { diff --git a/src/segment/merge.rs b/src/segment/merge.rs index fbba1ca..0ae0907 100644 --- a/src/segment/merge.rs +++ b/src/segment/merge.rs @@ -33,6 +33,7 @@ impl Ord for IteratorValue { } } +#[allow(clippy::module_name_repetitions)] pub struct MergeReader { readers: Vec, heap: MinMaxHeap, diff --git a/src/value_log.rs b/src/value_log.rs index 4b6e048..fd5984b 100644 --- a/src/value_log.rs +++ b/src/value_log.rs @@ -114,7 +114,7 @@ impl ValueLog { pub(crate) fn recover>( path: P, - index: Arc, + _index: Arc, ) -> crate::Result<()> { let path = path.into(); log::info!("Recovering value-log at {}", path.display()); @@ -238,7 +238,7 @@ impl ValueLog { pub fn rollover( &self, ids: &[Arc], - index_writer: W, + index_writer: &W, ) -> crate::Result<()> { // IMPORTANT: Only allow 1 rollover at any given time let _guard = self.semaphore.lock().expect("lock is poisoned"); @@ -252,40 +252,42 @@ impl ValueLog { drop(lock); - if let Some(segments) = segments { - let readers = segments - .into_iter() - .map(|x| SegmentReader::new(&x.path, x.id.clone())) - .collect::>>()?; + let Some(segments) = segments else { + return Ok(()); + }; - let reader = MergeReader::new(readers); + let readers = segments + .into_iter() + .map(|x| SegmentReader::new(&x.path, x.id.clone())) + .collect::>>()?; - let mut writer = self.get_writer()?; + let reader = MergeReader::new(readers); - for item in reader { - let (k, v, _) = item?; - eprintln!("{k:?} => {:?}", String::from_utf8_lossy(&v)); + let mut writer = self.get_writer()?; - let segment_id = writer.segment_id(); - let offset = writer.offset(&k); + for item in reader { + let (k, v, _) = item?; + eprintln!("{k:?} => {:?}", String::from_utf8_lossy(&v)); - log::trace!( - "GC: inserting indirection: {segment_id:?}:{offset:?} => {:?}", - String::from_utf8_lossy(&k) - ); + let segment_id = writer.segment_id(); + let offset = writer.offset(&k); - index_writer.insert_indirection(&k, ValueHandle { segment_id, offset })?; - writer.write(&k, &v)?; - } + log::trace!( + "GC: inserting indirection: {segment_id:?}:{offset:?} => {:?}", + String::from_utf8_lossy(&k) + ); - self.register(writer)?; - index_writer.finish()?; + index_writer.insert_indirection(&k, ValueHandle { segment_id, offset })?; + writer.write(&k, &v)?; + } - let mut lock = self.segments.write().expect("lock is poisoned"); - for id in ids { - std::fs::remove_dir_all(self.path.join("segments").join(&**id))?; - lock.remove(id); - } + self.register(writer)?; + index_writer.finish()?; + + let mut lock = self.segments.write().expect("lock is poisoned"); + for id in ids { + std::fs::remove_dir_all(self.path.join("segments").join(&**id))?; + lock.remove(id); } Ok(()) diff --git a/tests/basic_gc.rs b/tests/basic_gc.rs index f4c9e9b..a077296 100644 --- a/tests/basic_gc.rs +++ b/tests/basic_gc.rs @@ -139,7 +139,7 @@ fn basic_kv() -> value_log::Result<()> { assert_eq!(item, key.repeat(1_000).into()); } - value_log.rollover(&value_log.list_segments(), DebugIndexWriter(index.clone()))?; + value_log.rollover(&value_log.list_segments(), &DebugIndexWriter(index.clone()))?; { let lock = value_log.segments.read().unwrap();