refactor: move iterator trait to parent mod

Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
Alex Chi
2022-12-24 18:25:41 -05:00
parent 7a571a7c7d
commit d8cc9b2cf8
22 changed files with 79 additions and 49 deletions

View File

@@ -1,6 +1,19 @@
pub mod impls;
pub mod merge_iterator;
pub mod two_merge_iterator;
pub trait StorageIterator {
/// Get the current value.
fn value(&self) -> &[u8];
/// Get the current key.
fn key(&self) -> &[u8];
/// Check if the current iterator is valid.
fn is_valid(&self) -> bool;
/// Move to the next position.
fn next(&mut self) -> anyhow::Result<()>;
}
#[cfg(test)]
mod tests;

View File

@@ -1,15 +0,0 @@
use anyhow::Result;
pub trait StorageIterator {
/// Get the current value.
fn value(&self) -> &[u8];
/// Get the current key.
fn key(&self) -> &[u8];
/// Check if the current iterator is valid.
fn is_valid(&self) -> bool;
/// Move to the next position.
fn next(&mut self) -> Result<()>;
}

View File

@@ -4,7 +4,7 @@ use std::collections::BinaryHeap;
use anyhow::Result;
use super::impls::StorageIterator;
use super::StorageIterator;
struct HeapWrapper<I: StorageIterator>(pub usize, pub Box<I>);

View File

@@ -1,7 +1,7 @@
use anyhow::Result;
use bytes::Bytes;
use super::impls::StorageIterator;
use super::StorageIterator;
pub mod merge_iterator_test;
pub mod two_merge_iterator_test;

View File

@@ -1,6 +1,6 @@
use anyhow::Result;
use super::impls::StorageIterator;
use super::StorageIterator;
/// Merges two iterators of different types into one. If the two iterators have the same key, only
/// produce the key once and prefer the entry from A.

View File

@@ -3,9 +3,9 @@ use std::ops::Bound;
use anyhow::Result;
use bytes::Bytes;
use crate::iterators::impls::StorageIterator;
use crate::iterators::merge_iterator::MergeIterator;
use crate::iterators::two_merge_iterator::TwoMergeIterator;
use crate::iterators::StorageIterator;
use crate::mem_table::MemTableIterator;
use crate::table::SsTableIterator;

View File

@@ -7,9 +7,9 @@ use bytes::Bytes;
use parking_lot::{Mutex, RwLock};
use crate::block::Block;
use crate::iterators::impls::StorageIterator;
use crate::iterators::merge_iterator::MergeIterator;
use crate::iterators::two_merge_iterator::TwoMergeIterator;
use crate::iterators::StorageIterator;
use crate::lsm_iterator::{FusedIterator, LsmIterator};
use crate::mem_table::{map_bound, MemTable};
use crate::table::{SsTable, SsTableBuilder, SsTableIterator};
@@ -126,6 +126,8 @@ impl LsmStorage {
self.path.join(format!("{:05}.sst", id))
}
/// Persist data to disk.
///
/// In day 3: flush the current memtable to disk as L0 SST.
/// In day 6: call `fsync` on WAL.
pub fn sync(&self) -> Result<()> {

View File

@@ -7,7 +7,7 @@ use crossbeam_skiplist::map::Entry;
use crossbeam_skiplist::SkipMap;
use ouroboros::self_referencing;
use crate::iterators::impls::StorageIterator;
use crate::iterators::StorageIterator;
use crate::table::SsTableBuilder;
/// A basic mem-table based on crossbeam-skiplist

View File

@@ -1,7 +1,7 @@
use tempfile::tempdir;
use super::MemTable;
use crate::iterators::impls::StorageIterator;
use crate::iterators::StorageIterator;
use crate::table::{SsTableBuilder, SsTableIterator};
#[test]

View File

@@ -4,7 +4,7 @@ use anyhow::Result;
use super::SsTable;
use crate::block::BlockIterator;
use crate::iterators::impls::StorageIterator;
use crate::iterators::StorageIterator;
/// An iterator over the contents of an SSTable.
pub struct SsTableIterator {

View File

@@ -4,7 +4,7 @@ use bytes::Bytes;
use tempfile::{tempdir, TempDir};
use super::*;
use crate::iterators::impls::StorageIterator;
use crate::iterators::StorageIterator;
use crate::table::SsTableBuilder;
#[test]

View File

@@ -3,7 +3,7 @@ use std::ops::Bound;
use bytes::Bytes;
use tempfile::tempdir;
use crate::iterators::impls::StorageIterator;
use crate::iterators::StorageIterator;
fn as_bytes(x: &[u8]) -> Bytes {
Bytes::copy_from_slice(x)