Skip to content

Commit

Permalink
allow &mut on index writer
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed May 11, 2024
1 parent d1eb7d4 commit 5ba50dc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ pub trait Writer {
/// # Errors
///
/// Will return `Err` if an IO error occurs.
fn insert_indirection(&self, key: &[u8], value: ValueHandle) -> std::io::Result<()>;
fn insert_indirection(&mut self, key: &[u8], value: ValueHandle) -> std::io::Result<()>;

/// Finishes the write batch.
///
/// # Errors
///
/// Will return `Err` if an IO error occurs.
fn finish(&self) -> std::io::Result<()>;
fn finish(&mut self) -> std::io::Result<()>;
}
4 changes: 2 additions & 2 deletions src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ impl From<MockIndex> for MockIndexWriter {
}

impl IndexWriter for MockIndexWriter {
fn insert_indirection(&self, key: &[u8], value: ValueHandle) -> std::io::Result<()> {
fn insert_indirection(&mut self, key: &[u8], value: ValueHandle) -> std::io::Result<()> {
self.0.insert_indirection(key, value)
}

fn finish(&self) -> std::io::Result<()> {
fn finish(&mut self) -> std::io::Result<()> {
Ok(())
}
}
2 changes: 1 addition & 1 deletion src/value_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl<I: ExternalIndex + Clone + Send + Sync> ValueLog<I> {
/// # Errors
///
/// Will return `Err` if an IO error occurs.
pub fn rollover<W: IndexWriter>(&self, ids: &[u64], index_writer: &W) -> crate::Result<()> {
pub fn rollover<W: IndexWriter>(&self, ids: &[u64], index_writer: &mut W) -> crate::Result<()> {
// IMPORTANT: Only allow 1 rollover at any given time
let _guard = self.rollover_guard.lock().expect("lock is poisoned");

Expand Down
4 changes: 2 additions & 2 deletions tests/basic_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ fn basic_gc() -> value_log::Result<()> {

let ids = value_log.manifest.list_segment_ids();

let writer: MockIndexWriter = index.into();
value_log.rollover(&ids, &writer)?;
let mut writer: MockIndexWriter = index.into();
value_log.rollover(&ids, &mut writer)?;
value_log.drop_stale_segments()?;

{
Expand Down
7 changes: 4 additions & 3 deletions tests/rollover_index_fail_finish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ impl From<DebugIndex> for DebugIndexWriter {
}

impl IndexWriter for DebugIndexWriter {
fn insert_indirection(&self, key: &[u8], value: ValueHandle) -> std::io::Result<()> {
fn insert_indirection(&mut self, key: &[u8], value: ValueHandle) -> std::io::Result<()> {
self.0.insert_indirection(key, value)
}

fn finish(&self) -> std::io::Result<()> {
fn finish(&mut self) -> std::io::Result<()> {
Err(std::io::Error::new(std::io::ErrorKind::Other, "Oh no"))
}
}
Expand Down Expand Up @@ -94,7 +94,8 @@ fn rollover_index_fail_finish() -> value_log::Result<()> {
0.0
);

let result = value_log.rollover(&[0], &DebugIndexWriter(index.clone()));
let mut writer = DebugIndexWriter(index.clone());
let result = value_log.rollover(&[0], &mut writer);
assert!(result.is_err());

assert_eq!(
Expand Down

0 comments on commit 5ba50dc

Please sign in to comment.