Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Mar 13, 2024
1 parent d599e9a commit 0f049a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
9 changes: 1 addition & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BTreeMap<Arc<[u8]>, ValueHandle>>);
Expand All @@ -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<DebugIndex>);

impl IndexWriter for DebugIndexWriter {
Expand Down
1 change: 1 addition & 0 deletions src/segment/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl Ord for IteratorValue {
}
}

#[allow(clippy::module_name_repetitions)]
pub struct MergeReader {
readers: Vec<SegmentReader>,
heap: MinMaxHeap<IteratorValue>,
Expand Down
58 changes: 30 additions & 28 deletions src/value_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl ValueLog {

pub(crate) fn recover<P: Into<PathBuf>>(
path: P,
index: Arc<dyn Index + Send + Sync>,
_index: Arc<dyn Index + Send + Sync>,
) -> crate::Result<()> {
let path = path.into();
log::info!("Recovering value-log at {}", path.display());
Expand Down Expand Up @@ -238,7 +238,7 @@ impl ValueLog {
pub fn rollover<W: IndexWriter + Send + Sync>(
&self,
ids: &[Arc<str>],
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");
Expand All @@ -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::<std::io::Result<Vec<_>>>()?;
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::<std::io::Result<Vec<_>>>()?;

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(())
Expand Down
2 changes: 1 addition & 1 deletion tests/basic_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0f049a6

Please sign in to comment.