From 49f2f57a1b5187e09fb73f9ca31eae2bc6f69ee0 Mon Sep 17 00:00:00 2001 From: marvin-j97 Date: Wed, 8 Jan 2025 20:42:15 +0100 Subject: [PATCH 1/3] simplify api removing _with_seqno variants --- examples/kv/src/main.rs | 8 +- src/abstract.rs | 168 ++++++++------------- src/blob_tree/index.rs | 17 +-- src/blob_tree/mod.rs | 157 ++++++-------------- src/lib.rs | 8 +- src/seqno.rs | 2 +- src/snapshot.rs | 16 +- src/tree/mod.rs | 82 +++-------- tests/blob_drop_after_flush.rs | 2 +- tests/blob_gc.rs | 20 +-- tests/blob_gc_watermark.rs | 10 +- tests/blob_sep_threshold.rs | 2 +- tests/blob_simple.rs | 16 +- tests/blob_tombstone.rs | 22 +-- tests/blob_tree_reload_blob.rs | 48 +++--- tests/compaction_readers_grouping.rs | 6 +- tests/major_compaction.rs | 4 +- tests/open_files.rs | 2 +- tests/segment_point_reads.rs | 4 +- tests/segment_range.rs | 18 +-- tests/segment_range_oob.rs | 21 ++- tests/segment_remove_weak.rs | 2 +- tests/snapshot_compact.rs | 8 +- tests/snapshot_len.rs | 10 +- tests/snapshot_point_read.rs | 46 +++--- tests/snapshot_zombie.rs | 20 +-- tests/tree_approx_len.rs | 104 ++++++------- tests/tree_count.rs | 38 +++-- tests/tree_delete_loop.rs | 24 +-- tests/tree_different_block_size.rs | 8 +- tests/tree_disjoint_iter.rs | 6 +- tests/tree_disjoint_point_read.rs | 8 +- tests/tree_disjoint_prefix.rs | 6 +- tests/tree_disjoint_range.rs | 12 +- tests/tree_flush_eviction.rs | 20 +-- tests/tree_iter_lifetime.rs | 2 +- tests/tree_kv.rs | 42 +++--- tests/tree_l0_point_read.rs | 14 +- tests/tree_l0_range.rs | 4 +- tests/tree_mvcc_simple.rs | 8 +- tests/tree_non_disjoint_point_read.rs | 12 +- tests/tree_range.rs | 64 +++++--- tests/tree_range_memtable_only.rs | 18 +-- tests/tree_recover_large_value.rs | 2 +- tests/tree_reload.rs | 48 +++--- tests/tree_reload_pwd.rs | 4 +- tests/tree_sealed_shadowing.rs | 10 +- tests/tree_shadowing.rs | 204 +++++++++++++++++--------- tests/tree_v2_load_fixture.rs | 2 +- tests/tree_weak_delete.rs | 46 +++--- tests/tree_weak_delete_eviction.rs | 2 +- tests/tree_weak_delete_queue.rs | 24 +-- 52 files changed, 698 insertions(+), 753 deletions(-) diff --git a/examples/kv/src/main.rs b/examples/kv/src/main.rs index 3cbda543..ae2f9320 100644 --- a/examples/kv/src/main.rs +++ b/examples/kv/src/main.rs @@ -151,7 +151,7 @@ impl KvStore { } pub fn get>(&self, key: K) -> lsm_tree::Result>> { - Ok(self.tree.get(key.as_ref())?.map(|bytes| { + Ok(self.tree.get(key.as_ref(), None)?.map(|bytes| { std::str::from_utf8(&bytes) .expect("should be valid utf-8") .into() @@ -159,15 +159,15 @@ impl KvStore { } pub fn contains_key>(&self, key: K) -> lsm_tree::Result { - self.tree.contains_key(key.as_ref()) + self.tree.contains_key(key.as_ref(), None) } pub fn is_empty(&self) -> lsm_tree::Result { - self.tree.is_empty() + self.tree.is_empty(None, None) } pub fn len(&self) -> lsm_tree::Result { - self.tree.len() + self.tree.len(None, None) } } diff --git a/src/abstract.rs b/src/abstract.rs index f4fefd86..ab069966 100644 --- a/src/abstract.rs +++ b/src/abstract.rs @@ -138,11 +138,11 @@ pub trait AbstractTree { /// let folder = tempfile::tempdir()?; /// let tree = Config::new(folder).open()?; /// - /// assert_eq!(tree.len()?, 0); + /// assert_eq!(tree.len(None, None)?, 0); /// tree.insert("1", "abc", 0); /// tree.insert("3", "abc", 1); /// tree.insert("5", "abc", 2); - /// assert_eq!(tree.len()?, 3); + /// assert_eq!(tree.len(None, None)?, 3); /// # /// # Ok::<(), TreeError>(()) /// ``` @@ -150,10 +150,10 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn len(&self) -> crate::Result { + fn len(&self, seqno: Option, index: Option>) -> crate::Result { let mut count = 0; - for item in self.iter() { + for item in self.iter(seqno, index) { let _ = item?; count += 1; } @@ -172,10 +172,10 @@ pub trait AbstractTree { /// use lsm_tree::{AbstractTree, Config, Tree}; /// /// let tree = Config::new(folder).open()?; - /// assert!(tree.is_empty()?); + /// assert!(tree.is_empty(None, None)?); /// /// tree.insert("a", "abc", 0); - /// assert!(!tree.is_empty()?); + /// assert!(!tree.is_empty(None, None)?); /// # /// # Ok::<(), lsm_tree::Error>(()) /// ``` @@ -183,8 +183,8 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn is_empty(&self) -> crate::Result { - self.first_key_value().map(|x| x.is_none()) + fn is_empty(&self, seqno: Option, index: Option>) -> crate::Result { + self.first_key_value(seqno, index).map(|x| x.is_none()) } /// Returns the first key-value pair in the tree. @@ -203,7 +203,7 @@ pub trait AbstractTree { /// tree.insert("3", "abc", 1); /// tree.insert("5", "abc", 2); /// - /// let (key, _) = tree.first_key_value()?.expect("item should exist"); + /// let (key, _) = tree.first_key_value(None, None)?.expect("item should exist"); /// assert_eq!(&*key, "1".as_bytes()); /// # /// # Ok::<(), TreeError>(()) @@ -212,8 +212,12 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn first_key_value(&self) -> crate::Result> { - self.iter().next().transpose() + fn first_key_value( + &self, + seqno: Option, + index: Option>, + ) -> crate::Result> { + self.iter(seqno, index).next().transpose() } /// Returns the last key-value pair in the tree. @@ -232,7 +236,7 @@ pub trait AbstractTree { /// tree.insert("3", "abc", 1); /// tree.insert("5", "abc", 2); /// - /// let (key, _) = tree.last_key_value()?.expect("item should exist"); + /// let (key, _) = tree.last_key_value(None, None)?.expect("item should exist"); /// assert_eq!(&*key, "5".as_bytes()); /// # /// # Ok::<(), TreeError>(()) @@ -241,8 +245,12 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn last_key_value(&self) -> crate::Result> { - self.iter().next_back().transpose() + fn last_key_value( + &self, + seqno: Option, + index: Option>, + ) -> crate::Result> { + self.iter(seqno, index).next_back().transpose() } /// Returns an iterator that scans through the entire tree. @@ -260,13 +268,16 @@ pub trait AbstractTree { /// tree.insert("a", "abc", 0); /// tree.insert("f", "abc", 1); /// tree.insert("g", "abc", 2); - /// assert_eq!(3, tree.iter().count()); + /// assert_eq!(3, tree.iter(None, None).count()); /// # /// # Ok::<(), lsm_tree::Error>(()) /// ``` - #[must_use] - fn iter(&self) -> Box> + 'static> { - self.range::(..) + fn iter( + &self, + seqno: Option, + index: Option>, + ) -> Box> + 'static> { + self.range::<&[u8], _>(.., seqno, index) } /// Returns an iterator that scans through the entire tree, returning keys only. @@ -284,11 +295,15 @@ pub trait AbstractTree { /// tree.insert("a", "abc", 0); /// tree.insert("f", "abc", 1); /// tree.insert("g", "abc", 2); - /// assert_eq!(3, tree.keys().count()); + /// assert_eq!(3, tree.keys(None, None).count()); /// # /// # Ok::<(), lsm_tree::Error>(()) /// ``` - fn keys(&self) -> Box> + 'static>; + fn keys( + &self, + seqno: Option, + index: Option>, + ) -> Box> + 'static>; /// Returns an iterator that scans through the entire tree, returning values only. /// @@ -305,53 +320,16 @@ pub trait AbstractTree { /// tree.insert("a", "abc", 0); /// tree.insert("f", "abc", 1); /// tree.insert("g", "abc", 2); - /// assert_eq!(3, tree.values().count()); + /// assert_eq!(3, tree.values(None, None).count()); /// # /// # Ok::<(), lsm_tree::Error>(()) /// ``` - fn values(&self) -> Box> + 'static>; - - /// Returns an iterator over a snapshot instant, returning keys only. - /// - /// Avoid using this function, or limit it as otherwise it may scan a lot of items. - fn keys_with_seqno( + fn values( &self, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static>; - - /// Returns an iterator over a snapshot instant, returning values only. - /// - /// Avoid using this function, or limit it as otherwise it may scan a lot of items. - fn values_with_seqno( - &self, - seqno: SeqNo, + seqno: Option, index: Option>, ) -> Box> + 'static>; - /// Creates an iterator over a snapshot instant. - fn iter_with_seqno( - &self, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static>; - - /// Creates an bounded iterator over a snapshot instant. - fn range_with_seqno, R: RangeBounds>( - &self, - range: R, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static>; - - /// Creates a prefix iterator over a snapshot instant. - fn prefix_with_seqno>( - &self, - prefix: K, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static>; - /// Returns an iterator over a range of items. /// /// Avoid using full or unbounded ranges as they may scan a lot of items (unless limited). @@ -367,13 +345,15 @@ pub trait AbstractTree { /// tree.insert("a", "abc", 0); /// tree.insert("f", "abc", 1); /// tree.insert("g", "abc", 2); - /// assert_eq!(2, tree.range("a"..="f").into_iter().count()); + /// assert_eq!(2, tree.range("a"..="f", None, None).into_iter().count()); /// # /// # Ok::<(), lsm_tree::Error>(()) /// ``` fn range, R: RangeBounds>( &self, range: R, + seqno: Option, + index: Option>, ) -> Box> + 'static>; /// Returns an iterator over a prefixed set of items. @@ -391,13 +371,15 @@ pub trait AbstractTree { /// tree.insert("a", "abc", 0); /// tree.insert("ab", "abc", 1); /// tree.insert("abc", "abc", 2); - /// assert_eq!(2, tree.prefix("ab").count()); + /// assert_eq!(2, tree.prefix("ab", None, None).count()); /// # /// # Ok::<(), lsm_tree::Error>(()) /// ``` fn prefix>( &self, prefix: K, + seqno: Option, + index: Option>, ) -> Box> + 'static>; /// Returns the size of a value if it exists. @@ -411,10 +393,10 @@ pub trait AbstractTree { /// let tree = Config::new(folder).open()?; /// tree.insert("a", "my_value", 0); /// - /// let size = tree.size_of("a")?.unwrap_or_default(); + /// let size = tree.size_of("a", None)?.unwrap_or_default(); /// assert_eq!("my_value".len() as u32, size); /// - /// let size = tree.size_of("b")?.unwrap_or_default(); + /// let size = tree.size_of("b", None)?.unwrap_or_default(); /// assert_eq!(0, size); /// # /// # Ok::<(), lsm_tree::Error>(()) @@ -423,18 +405,7 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn size_of>(&self, key: K) -> crate::Result>; - - /// Retrieves the size of a value from a snapshot instant. - /// - /// # Errors - /// - /// Will return `Err` if an IO error occurs. - fn size_of_with_seqno>( - &self, - key: K, - seqno: SeqNo, - ) -> crate::Result>; + fn size_of>(&self, key: K, seqno: Option) -> crate::Result>; /// Retrieves an item from the tree. /// @@ -447,7 +418,7 @@ pub trait AbstractTree { /// let tree = Config::new(folder).open()?; /// tree.insert("a", "my_value", 0); /// - /// let item = tree.get("a")?; + /// let item = tree.get("a", None)?; /// assert_eq!(Some("my_value".as_bytes().into()), item); /// # /// # Ok::<(), lsm_tree::Error>(()) @@ -456,18 +427,8 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn get>(&self, key: K) -> crate::Result>; - - /// Retrieves an item from a snapshot instant. - /// - /// # Errors - /// - /// Will return `Err` if an IO error occurs. - fn get_with_seqno>( - &self, - key: K, - seqno: SeqNo, - ) -> crate::Result>; + fn get>(&self, key: K, seqno: Option) + -> crate::Result>; /// Opens a read-only point-in-time snapshot of the tree /// @@ -484,11 +445,11 @@ pub trait AbstractTree { /// tree.insert("a", "abc", 0); /// /// let snapshot = tree.snapshot(1); - /// assert_eq!(snapshot.len()?, tree.len()?); + /// assert_eq!(snapshot.len()?, tree.len(None, None)?); /// /// tree.insert("b", "abc", 1); /// - /// assert_eq!(2, tree.len()?); + /// assert_eq!(2, tree.len(None, None)?); /// assert_eq!(1, snapshot.len()?); /// /// assert!(snapshot.contains_key("a")?); @@ -513,10 +474,10 @@ pub trait AbstractTree { /// # use lsm_tree::{AbstractTree, Config, Tree}; /// # /// let tree = Config::new(folder).open()?; - /// assert!(!tree.contains_key("a")?); + /// assert!(!tree.contains_key("a", None)?); /// /// tree.insert("a", "abc", 0); - /// assert!(tree.contains_key("a")?); + /// assert!(tree.contains_key("a", None)?); /// # /// # Ok::<(), lsm_tree::Error>(()) /// ``` @@ -524,17 +485,8 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn contains_key>(&self, key: K) -> crate::Result { - self.get(key).map(|x| x.is_some()) - } - - /// Returns `true` if the snapshot instant contains the specified key. - /// - /// # Errors - /// - /// Will return `Err` if an IO error occurs. - fn contains_key_with_seqno>(&self, key: K, seqno: SeqNo) -> crate::Result { - self.get_with_seqno(key, seqno).map(|x| x.is_some()) + fn contains_key>(&self, key: K, seqno: Option) -> crate::Result { + self.get(key, seqno).map(|x| x.is_some()) } /// Inserts a key-value pair into the tree. @@ -578,12 +530,12 @@ pub trait AbstractTree { /// # let tree = Config::new(folder).open()?; /// tree.insert("a", "abc", 0); /// - /// let item = tree.get("a")?.expect("should have item"); + /// let item = tree.get("a", None)?.expect("should have item"); /// assert_eq!("abc".as_bytes(), &*item); /// /// tree.remove("a", 1); /// - /// let item = tree.get("a")?; + /// let item = tree.get("a", None)?; /// assert_eq!(None, item); /// # /// # Ok::<(), lsm_tree::Error>(()) @@ -612,12 +564,12 @@ pub trait AbstractTree { /// # let tree = Config::new(folder).open()?; /// tree.insert("a", "abc", 0); /// - /// let item = tree.get("a")?.expect("should have item"); + /// let item = tree.get("a", None)?.expect("should have item"); /// assert_eq!("abc".as_bytes(), &*item); /// /// tree.remove_weak("a", 1); /// - /// let item = tree.get("a")?; + /// let item = tree.get("a", None)?; /// assert_eq!(None, item); /// # /// # Ok::<(), lsm_tree::Error>(()) diff --git a/src/blob_tree/index.rs b/src/blob_tree/index.rs index a5981145..95faeb09 100644 --- a/src/blob_tree/index.rs +++ b/src/blob_tree/index.rs @@ -19,23 +19,12 @@ impl std::ops::Deref for IndexTree { } impl IndexTree { - pub(crate) fn get_internal_with_seqno( + pub(crate) fn get_vhandle( &self, key: &[u8], - seqno: SeqNo, + seqno: Option, ) -> crate::Result> { - let Some(item) = self.get_with_seqno(key, seqno)? else { - return Ok(None); - }; - - let mut cursor = Cursor::new(item); - let item = MaybeInlineValue::decode_from(&mut cursor)?; - - Ok(Some(item)) - } - - pub(crate) fn get_internal(&self, key: &[u8]) -> crate::Result> { - let Some(item) = self.get(key)? else { + let Some(item) = self.get(key, seqno)? else { return Ok(None); }; diff --git a/src/blob_tree/mod.rs b/src/blob_tree/mod.rs index 903fd31c..c311157a 100644 --- a/src/blob_tree/mod.rs +++ b/src/blob_tree/mod.rs @@ -14,7 +14,7 @@ use crate::{ r#abstract::{AbstractTree, RangeItem}, tree::inner::MemtableId, value::InternalValue, - Config, KvPair, Memtable, Segment, SegmentId, SeqNo, Slice, Snapshot, UserKey, UserValue, + Config, KvPair, Memtable, Segment, SegmentId, SeqNo, Snapshot, UserKey, UserValue, }; use compression::MyCompressor; use gc::{reader::GcReader, writer::GcWriter}; @@ -230,26 +230,10 @@ impl BlobTree { } impl AbstractTree for BlobTree { - fn size_of>(&self, key: K) -> crate::Result> { - let vhandle = self.index.get_internal(key.as_ref())?; - - Ok(vhandle.map(|x| match x { - MaybeInlineValue::Inline(v) => v.len() as u32, - - // NOTE: We skip reading from the value log - // because the indirections already store the value size - MaybeInlineValue::Indirect { size, .. } => size, - })) - } - // NOTE: We skip reading from the value log // because the vHandles already store the value size - fn size_of_with_seqno>( - &self, - key: K, - seqno: SeqNo, - ) -> crate::Result> { - let vhandle = self.index.get_internal_with_seqno(key.as_ref(), seqno)?; + fn size_of>(&self, key: K, seqno: Option) -> crate::Result> { + let vhandle = self.index.get_vhandle(key.as_ref(), seqno)?; Ok(vhandle.map(|x| match x { MaybeInlineValue::Inline(v) => v.len() as u32, @@ -280,31 +264,20 @@ impl AbstractTree for BlobTree { Ok(index_tree_sum + vlog_sum) } - fn keys_with_seqno( + fn keys( &self, - seqno: SeqNo, + seqno: Option, index: Option>, ) -> Box> + 'static> { - self.index.keys_with_seqno(seqno, index) + self.index.keys(seqno, index) } - fn values_with_seqno( + fn values( &self, - seqno: SeqNo, + seqno: Option, index: Option>, ) -> Box> + 'static> { - Box::new( - self.iter_with_seqno(seqno, index) - .map(|x| x.map(|(_, v)| v)), - ) - } - - fn keys(&self) -> Box> + 'static> { - self.index.keys() - } - - fn values(&self) -> Box> + 'static> { - Box::new(self.iter().map(|x| x.map(|(_, v)| v))) + Box::new(self.iter(seqno, index).map(|x| x.map(|(_, v)| v))) } fn flush_memtable( @@ -496,20 +469,14 @@ impl AbstractTree for BlobTree { // NOTE: Override the default implementation to not fetch // data from the value log, so we get much faster key reads - fn contains_key>(&self, key: K) -> crate::Result { - self.index.contains_key(key) - } - - // NOTE: Override the default implementation to not fetch - // data from the value log, so we get much faster key reads - fn contains_key_with_seqno>(&self, key: K, seqno: SeqNo) -> crate::Result { - self.index.contains_key_with_seqno(key, seqno) + fn contains_key>(&self, key: K, seqno: Option) -> crate::Result { + self.index.contains_key(key, seqno) } // NOTE: Override the default implementation to not fetch // data from the value log, so we get much faster scans - fn len(&self) -> crate::Result { - self.index.len() + fn len(&self, seqno: Option, index: Option>) -> crate::Result { + self.index.len(seqno, index) } #[must_use] @@ -531,53 +498,17 @@ impl AbstractTree for BlobTree { Snapshot::new(Blob(self.clone()), seqno) } - fn iter_with_seqno( - &self, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static> { - self.range_with_seqno::(.., seqno, index) - } - - fn range_with_seqno, R: RangeBounds>( - &self, - range: R, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static> { - let vlog = self.blobs.clone(); - Box::new( - self.index - .0 - .create_range(&range, Some(seqno), index) - .map(move |item| resolve_value_handle(&vlog, item)), - ) - } - - fn prefix_with_seqno>( - &self, - prefix: K, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static> { - let vlog = self.blobs.clone(); - Box::new( - self.index - .0 - .create_prefix(prefix, Some(seqno), index) - .map(move |item| resolve_value_handle(&vlog, item)), - ) - } - fn range, R: RangeBounds>( &self, range: R, + seqno: Option, + index: Option>, ) -> Box> + 'static> { let vlog = self.blobs.clone(); Box::new( self.index .0 - .create_range(&range, None, None) + .create_range(&range, seqno, index) .map(move |item| resolve_value_handle(&vlog, item)), ) } @@ -585,12 +516,14 @@ impl AbstractTree for BlobTree { fn prefix>( &self, prefix: K, + seqno: Option, + index: Option>, ) -> Box> + 'static> { let vlog = self.blobs.clone(); Box::new( self.index .0 - .create_prefix(prefix, None, None) + .create_prefix(prefix, seqno, index) .map(move |item| resolve_value_handle(&vlog, item)), ) } @@ -613,16 +546,16 @@ impl AbstractTree for BlobTree { self.index.insert(key, value, seqno) } - fn get_with_seqno>( + fn get>( &self, key: K, - seqno: SeqNo, + seqno: Option, ) -> crate::Result> { use value::MaybeInlineValue::{Indirect, Inline}; let key = key.as_ref(); - let Some(value) = self.index.get_internal_with_seqno(key, seqno)? else { + let Some(value) = self.index.get_vhandle(key, seqno)? else { return Ok(None); }; @@ -640,29 +573,29 @@ impl AbstractTree for BlobTree { } } - fn get>(&self, key: K) -> crate::Result> { - use value::MaybeInlineValue::{Indirect, Inline}; - - let key = key.as_ref(); - - let Some(value) = self.index.get_internal(key)? else { - return Ok(None); - }; - - match value { - Inline(bytes) => Ok(Some(bytes)), - Indirect { vhandle, .. } => { - // Resolve indirection using value log - match self.blobs.get(&vhandle)? { - Some(bytes) => Ok(Some(bytes)), - None => { - panic!("value handle ({:?} => {vhandle:?}) did not match any blob - this is a bug", String::from_utf8_lossy(key)) - } - } - } - } - } - + /* fn get>(&self, key: K) -> crate::Result> { + use value::MaybeInlineValue::{Indirect, Inline}; + + let key = key.as_ref(); + + let Some(value) = self.index.get_internal(key)? else { + return Ok(None); + }; + + match value { + Inline(bytes) => Ok(Some(bytes)), + Indirect { vhandle, .. } => { + // Resolve indirection using value log + match self.blobs.get(&vhandle)? { + Some(bytes) => Ok(Some(bytes)), + None => { + panic!("value handle ({:?} => {vhandle:?}) did not match any blob - this is a bug", String::from_utf8_lossy(key)) + } + } + } + } + } + */ fn remove>(&self, key: K, seqno: SeqNo) -> (u32, u32) { self.index.remove(key, seqno) } diff --git a/src/lib.rs b/src/lib.rs index 69b2b63c..72667c3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,21 +47,21 @@ //! // So you can handle I/O errors if they occur //! tree.insert("my_key", "my_value", /* sequence number */ 0); //! -//! let item = tree.get("my_key")?; +//! let item = tree.get("my_key", None)?; //! assert_eq!(Some("my_value".as_bytes().into()), item); //! //! // Search by prefix -//! for item in tree.prefix("prefix") { +//! for item in tree.prefix("prefix", None, None) { //! // ... //! } //! //! // Search by range -//! for item in tree.range("a"..="z") { +//! for item in tree.range("a"..="z", None, None) { //! // ... //! } //! //! // Iterators implement DoubleEndedIterator, so you can search backwards, too! -//! for item in tree.prefix("prefix").rev() { +//! for item in tree.prefix("prefix", None, None).rev() { //! // ... //! } //! diff --git a/src/seqno.rs b/src/seqno.rs index 45b4c070..05e53df7 100644 --- a/src/seqno.rs +++ b/src/seqno.rs @@ -37,7 +37,7 @@ use std::sync::{ /// tree.remove("b".as_bytes(), batch_seqno); /// tree.remove("c".as_bytes(), batch_seqno); /// # -/// # assert!(tree.is_empty()?); +/// # assert!(tree.is_empty(None, None)?); /// # Ok::<(), lsm_tree::Error>(()) /// ``` #[derive(Clone, Default, Debug)] diff --git a/src/snapshot.rs b/src/snapshot.rs index 7209bfa6..f6ba9890 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -60,7 +60,7 @@ impl Snapshot { /// /// Will return `Err` if an IO error occurs. pub fn size_of>(&self, key: K) -> crate::Result> { - self.tree.size_of_with_seqno(key, self.seqno) + self.tree.size_of(key, Some(self.seqno)) } /// Retrieves an item from the snapshot. @@ -91,7 +91,7 @@ impl Snapshot { /// /// Will return `Err` if an IO error occurs. pub fn get>(&self, key: K) -> crate::Result> { - self.tree.get_with_seqno(key, self.seqno) + self.tree.get(key, Some(self.seqno)) } /// Returns an iterator that scans through the entire snapshot. @@ -118,7 +118,7 @@ impl Snapshot { /// ``` #[must_use] pub fn iter(&self) -> impl DoubleEndedIterator> + 'static { - self.tree.iter_with_seqno(self.seqno, None) + self.tree.iter(Some(self.seqno), None) } /// Returns an iterator that scans through the entire snapshot, returning keys only. @@ -145,7 +145,7 @@ impl Snapshot { /// ``` #[must_use] pub fn keys(&self) -> impl DoubleEndedIterator> + 'static { - self.tree.keys_with_seqno(self.seqno, None) + self.tree.keys(Some(self.seqno), None) } /// Returns an iterator that scans through the entire snapshot, returning values only. @@ -172,7 +172,7 @@ impl Snapshot { /// ``` #[must_use] pub fn values(&self) -> impl DoubleEndedIterator> + 'static { - self.tree.values_with_seqno(self.seqno, None) + self.tree.values(Some(self.seqno), None) } /// Returns an iterator over a range of items in the snapshot. @@ -201,7 +201,7 @@ impl Snapshot { &self, range: R, ) -> impl DoubleEndedIterator> + 'static { - self.tree.range_with_seqno(range, self.seqno, None) + self.tree.range(range, Some(self.seqno), None) } /// Returns an iterator over a prefixed set of items in the snapshot. @@ -230,7 +230,7 @@ impl Snapshot { &self, prefix: K, ) -> impl DoubleEndedIterator> + 'static { - self.tree.prefix_with_seqno(prefix, self.seqno, None) + self.tree.prefix(prefix, Some(self.seqno), None) } /// Returns the first key-value pair in the snapshot. @@ -318,7 +318,7 @@ impl Snapshot { /// /// Will return `Err` if an IO error occurs. pub fn contains_key>(&self, key: K) -> crate::Result { - self.tree.contains_key_with_seqno(key, self.seqno) + self.tree.contains_key(key, Some(self.seqno)) } /// Returns `true` if the snapshot is empty. diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 8916bb43..76d1b932 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -52,16 +52,8 @@ impl std::ops::Deref for Tree { } impl AbstractTree for Tree { - fn size_of>(&self, key: K) -> crate::Result> { - Ok(self.get(key)?.map(|x| x.len() as u32)) - } - - fn size_of_with_seqno>( - &self, - key: K, - seqno: SeqNo, - ) -> crate::Result> { - Ok(self.get_with_seqno(key, seqno)?.map(|x| x.len() as u32)) + fn size_of>(&self, key: K, seqno: Option) -> crate::Result> { + Ok(self.get(key, seqno)?.map(|x| x.len() as u32)) } #[cfg(feature = "bloom")] @@ -108,34 +100,20 @@ impl AbstractTree for Tree { Ok(sum) } - fn keys_with_seqno( + fn keys( &self, - seqno: SeqNo, + seqno: Option, index: Option>, ) -> Box> + 'static> { - Box::new( - self.create_iter(Some(seqno), index) - .map(|x| x.map(|(k, _)| k)), - ) + Box::new(self.create_iter(seqno, index).map(|x| x.map(|(k, _)| k))) } - fn values_with_seqno( + fn values( &self, - seqno: SeqNo, + seqno: Option, index: Option>, ) -> Box> + 'static> { - Box::new( - self.create_iter(Some(seqno), index) - .map(|x| x.map(|(_, v)| v)), - ) - } - - fn keys(&self) -> Box> + 'static> { - Box::new(self.create_iter(None, None).map(|x| x.map(|(k, _)| k))) - } - - fn values(&self) -> Box> + 'static> { - Box::new(self.create_iter(None, None).map(|x| x.map(|(_, v)| v))) + Box::new(self.create_iter(seqno, index).map(|x| x.map(|(_, v)| v))) } fn flush_memtable( @@ -350,56 +328,30 @@ impl AbstractTree for Tree { Snapshot::new(Standard(self.clone()), seqno) } - fn get_with_seqno>( + fn get>( &self, key: K, - seqno: SeqNo, + seqno: Option, ) -> crate::Result> { - Ok(self.get_internal_entry(key, Some(seqno))?.map(|x| x.value)) - } - - fn get>(&self, key: K) -> crate::Result> { - Ok(self.get_internal_entry(key, None)?.map(|x| x.value)) - } - - fn iter_with_seqno( - &self, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static> { - self.range_with_seqno::(.., seqno, index) - } - - fn range_with_seqno, R: RangeBounds>( - &self, - range: R, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static> { - Box::new(self.create_range(&range, Some(seqno), index)) - } - - fn prefix_with_seqno>( - &self, - prefix: K, - seqno: SeqNo, - index: Option>, - ) -> Box> + 'static> { - Box::new(self.create_prefix(prefix, Some(seqno), index)) + Ok(self.get_internal_entry(key, seqno)?.map(|x| x.value)) } fn range, R: RangeBounds>( &self, range: R, + seqno: Option, + index: Option>, ) -> Box> + 'static> { - Box::new(self.create_range(&range, None, None)) + Box::new(self.create_range(&range, seqno, index)) } fn prefix>( &self, prefix: K, + seqno: Option, + index: Option>, ) -> Box> + 'static> { - Box::new(self.create_prefix(prefix, None, None)) + Box::new(self.create_prefix(prefix, seqno, index)) } fn insert, V: Into>( diff --git a/tests/blob_drop_after_flush.rs b/tests/blob_drop_after_flush.rs index 8b0b74c8..c390c223 100644 --- a/tests/blob_drop_after_flush.rs +++ b/tests/blob_drop_after_flush.rs @@ -35,7 +35,7 @@ fn blob_drop_after_flush() -> lsm_tree::Result<()> { assert_eq!( "neptune".repeat(10_000).as_bytes(), - &*tree.get("a")?.unwrap(), + &*tree.get("a", None)?.unwrap(), ); let report = gc_report.join().unwrap()?; diff --git a/tests/blob_gc.rs b/tests/blob_gc.rs index 2366da18..ce80a771 100644 --- a/tests/blob_gc.rs +++ b/tests/blob_gc.rs @@ -35,9 +35,9 @@ fn blob_gc_1() -> lsm_tree::Result<()> { tree.gc_drop_stale()?; - assert_eq!(&*tree.get("a")?.unwrap(), b"a"); - assert_eq!(&*tree.get("b")?.unwrap(), b"b"); - assert_eq!(&*tree.get("c")?.unwrap(), b"c"); + assert_eq!(&*tree.get("a", None)?.unwrap(), b"a"); + assert_eq!(&*tree.get("b", None)?.unwrap(), b"b"); + assert_eq!(&*tree.get("c", None)?.unwrap(), b"c"); assert_eq!(0, tree.blobs.segment_count()); assert_eq!(0.0, tree.blobs.space_amp()); @@ -73,10 +73,10 @@ fn blob_gc_2() -> lsm_tree::Result<()> { let strategy = value_log::SpaceAmpStrategy::new(1.0); tree.apply_gc_strategy(&strategy, seqno.next())?; - assert_eq!(&*tree.get("a")?.unwrap(), b"a"); - assert_eq!(&*tree.get("b")?.unwrap(), b"b"); + assert_eq!(&*tree.get("a", None)?.unwrap(), b"a"); + assert_eq!(&*tree.get("b", None)?.unwrap(), b"b"); assert_eq!( - &*tree.get("c")?.unwrap(), + &*tree.get("c", None)?.unwrap(), "neptune".repeat(10_000).as_bytes() ); assert_eq!(1, tree.blobs.segment_count()); @@ -123,17 +123,17 @@ fn blob_gc_3() -> lsm_tree::Result<()> { let strategy = value_log::SpaceAmpStrategy::new(1.0); tree.apply_gc_strategy(&strategy, seqno.next())?; - assert!(tree.get("a")?.is_none()); - assert!(tree.get("b")?.is_none()); + assert!(tree.get("a", None)?.is_none()); + assert!(tree.get("b", None)?.is_none()); assert_eq!( - &*tree.get("c")?.unwrap(), + &*tree.get("c", None)?.unwrap(), "neptune".repeat(10_000).as_bytes() ); assert_eq!(1, tree.blobs.segment_count()); assert_eq!(1.0, tree.blobs.space_amp()); tree.remove("c", seqno.next()); - assert!(tree.get("c")?.is_none()); + assert!(tree.get("c", None)?.is_none()); tree.gc_scan_stats(seqno.get(), 1_000)?; diff --git a/tests/blob_gc_watermark.rs b/tests/blob_gc_watermark.rs index 8089e8ea..13d1a2e0 100644 --- a/tests/blob_gc_watermark.rs +++ b/tests/blob_gc_watermark.rs @@ -13,19 +13,19 @@ fn blob_gc_seqno_watermark() -> lsm_tree::Result<()> { tree.insert("a", "neptune".repeat(10_000), seqno.next()); let snapshot = tree.snapshot(seqno.get()); assert_eq!(&*snapshot.get("a")?.unwrap(), b"neptune".repeat(10_000)); - assert_eq!(&*tree.get("a")?.unwrap(), b"neptune".repeat(10_000)); + assert_eq!(&*tree.get("a", None)?.unwrap(), b"neptune".repeat(10_000)); tree.insert("a", "neptune2".repeat(10_000), seqno.next()); assert_eq!(&*snapshot.get("a")?.unwrap(), b"neptune".repeat(10_000)); - assert_eq!(&*tree.get("a")?.unwrap(), b"neptune2".repeat(10_000)); + assert_eq!(&*tree.get("a", None)?.unwrap(), b"neptune2".repeat(10_000)); tree.insert("a", "neptune3".repeat(10_000), seqno.next()); assert_eq!(&*snapshot.get("a")?.unwrap(), b"neptune".repeat(10_000)); - assert_eq!(&*tree.get("a")?.unwrap(), b"neptune3".repeat(10_000)); + assert_eq!(&*tree.get("a", None)?.unwrap(), b"neptune3".repeat(10_000)); tree.flush_active_memtable(0)?; assert_eq!(&*snapshot.get("a")?.unwrap(), b"neptune".repeat(10_000)); - assert_eq!(&*tree.get("a")?.unwrap(), b"neptune3".repeat(10_000)); + assert_eq!(&*tree.get("a", None)?.unwrap(), b"neptune3".repeat(10_000)); let report = tree.gc_scan_stats(seqno.get() + 1, 0)?; assert_eq!(2, report.stale_blobs); @@ -41,7 +41,7 @@ fn blob_gc_seqno_watermark() -> lsm_tree::Result<()> { assert_eq!(2, report.stale_blobs); assert_eq!(&*snapshot.get("a")?.unwrap(), b"neptune".repeat(10_000)); - assert_eq!(&*tree.get("a")?.unwrap(), b"neptune3".repeat(10_000)); + assert_eq!(&*tree.get("a", None)?.unwrap(), b"neptune3".repeat(10_000)); Ok(()) } diff --git a/tests/blob_sep_threshold.rs b/tests/blob_sep_threshold.rs index cb1b5a4f..d281fe7b 100644 --- a/tests/blob_sep_threshold.rs +++ b/tests/blob_sep_threshold.rs @@ -18,7 +18,7 @@ fn blob_tree_separation_threshold() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; assert_eq!(tree.blobs.segment_count(), 1); - assert_eq!(2, tree.len()?); + assert_eq!(2, tree.len(None, None)?); Ok(()) } diff --git a/tests/blob_simple.rs b/tests/blob_simple.rs index d4962a2e..cea117fc 100644 --- a/tests/blob_simple.rs +++ b/tests/blob_simple.rs @@ -12,39 +12,39 @@ fn blob_tree_simple() -> lsm_tree::Result<()> { { let tree = lsm_tree::Config::new(path).open_as_blob_tree()?; - assert!(tree.get("big")?.is_none()); + assert!(tree.get("big", None)?.is_none()); tree.insert("big", &big_value, 0); tree.insert("smol", "small value", 0); - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, big_value); tree.flush_active_memtable(0)?; - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, big_value); - let value = tree.get("smol")?.expect("should exist"); + let value = tree.get("smol", None)?.expect("should exist"); assert_eq!(&*value, b"small value"); tree.insert("big", &new_big_value, 1); - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, new_big_value); tree.flush_active_memtable(0)?; - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, new_big_value); } { let tree = lsm_tree::Config::new(path).open_as_blob_tree()?; - let value = tree.get("smol")?.expect("should exist"); + let value = tree.get("smol", None)?.expect("should exist"); assert_eq!(&*value, b"small value"); - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, new_big_value); } diff --git a/tests/blob_tombstone.rs b/tests/blob_tombstone.rs index a9c8834a..0c63562b 100644 --- a/tests/blob_tombstone.rs +++ b/tests/blob_tombstone.rs @@ -13,30 +13,30 @@ fn blob_tree_tombstone() -> lsm_tree::Result<()> { tree.insert("a", &big_value, 0); tree.insert("b", &big_value, 0); tree.insert("c", &big_value, 0); - assert_eq!(3, tree.len()?); + assert_eq!(3, tree.len(None, None)?); tree.flush_active_memtable(0)?; - assert_eq!(3, tree.len()?); + assert_eq!(3, tree.len(None, None)?); tree.remove("b", 1); - assert_eq!(2, tree.len()?); + assert_eq!(2, tree.len(None, None)?); tree.flush_active_memtable(0)?; - assert_eq!(2, tree.len()?); + assert_eq!(2, tree.len(None, None)?); - assert_eq!(&*tree.get("a")?.unwrap(), big_value); - assert!(tree.get("b")?.is_none()); - assert_eq!(&*tree.get("c")?.unwrap(), big_value); + assert_eq!(&*tree.get("a", None)?.unwrap(), big_value); + assert!(tree.get("b", None)?.is_none()); + assert_eq!(&*tree.get("c", None)?.unwrap(), big_value); tree.gc_scan_stats(2, 0)?; let strategy = value_log::StaleThresholdStrategy::new(0.01); tree.apply_gc_strategy(&strategy, 2)?; - assert_eq!(2, tree.len()?); + assert_eq!(2, tree.len(None, None)?); - assert_eq!(&*tree.get("a")?.unwrap(), big_value); - assert!(tree.get("b")?.is_none()); - assert_eq!(&*tree.get("c")?.unwrap(), big_value); + assert_eq!(&*tree.get("a", None)?.unwrap(), big_value); + assert!(tree.get("b", None)?.is_none()); + assert_eq!(&*tree.get("c", None)?.unwrap(), big_value); Ok(()) } diff --git a/tests/blob_tree_reload_blob.rs b/tests/blob_tree_reload_blob.rs index f35ad270..e085f4a9 100644 --- a/tests/blob_tree_reload_blob.rs +++ b/tests/blob_tree_reload_blob.rs @@ -11,18 +11,18 @@ fn blob_tree_reload_empty() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open_as_blob_tree()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); assert_eq!(tree.tree_type(), TreeType::Blob); } { let tree = Config::new(&folder).open_as_blob_tree()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); assert_eq!(tree.tree_type(), TreeType::Blob); tree.flush_active_memtable(0)?; @@ -31,9 +31,9 @@ fn blob_tree_reload_empty() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open_as_blob_tree()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); assert_eq!(tree.tree_type(), TreeType::Blob); } @@ -63,9 +63,12 @@ fn blob_tree_reload() -> lsm_tree::Result<()> { tree.insert(key, value.as_bytes(), seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.iter().flatten().count(), ITEM_COUNT * 2); - assert_eq!(tree.iter().rev().flatten().count(), ITEM_COUNT * 2); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!(tree.iter(None, None).flatten().count(), ITEM_COUNT * 2); + assert_eq!( + tree.iter(None, None).rev().flatten().count(), + ITEM_COUNT * 2 + ); tree.flush_active_memtable(0)?; } @@ -73,9 +76,12 @@ fn blob_tree_reload() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open_as_blob_tree()?; - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.iter().flatten().count(), ITEM_COUNT * 2); - assert_eq!(tree.iter().rev().flatten().count(), ITEM_COUNT * 2); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!(tree.iter(None, None).flatten().count(), ITEM_COUNT * 2); + assert_eq!( + tree.iter(None, None).rev().flatten().count(), + ITEM_COUNT * 2 + ); } Ok(()) @@ -101,18 +107,18 @@ fn blob_tree_remove_unfinished_segments() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open_as_blob_tree()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); } // Recover tree { let tree = Config::new(&folder).open_as_blob_tree()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); } assert!(!file0.try_exists()?); diff --git a/tests/compaction_readers_grouping.rs b/tests/compaction_readers_grouping.rs index 68dd9e51..f0df6fb2 100644 --- a/tests/compaction_readers_grouping.rs +++ b/tests/compaction_readers_grouping.rs @@ -15,7 +15,7 @@ fn compaction_readers_grouping() -> lsm_tree::Result<()> { tree.insert("b".as_bytes(), "abc", seqno.next()); tree.insert("c".as_bytes(), "abc", seqno.next()); tree.flush_active_memtable(0)?; - assert_eq!(3, tree.len()?); + assert_eq!(3, tree.len(None, None)?); tree.compact(Arc::new(lsm_tree::compaction::PullDown(0, 2)), 0)?; @@ -23,13 +23,13 @@ fn compaction_readers_grouping() -> lsm_tree::Result<()> { tree.insert("e".as_bytes(), "abc", seqno.next()); tree.insert("f".as_bytes(), "abc", seqno.next()); tree.flush_active_memtable(0)?; - assert_eq!(6, tree.len()?); + assert_eq!(6, tree.len(None, None)?); tree.insert("g".as_bytes(), "abc", seqno.next()); tree.insert("h".as_bytes(), "abc", seqno.next()); tree.insert("i".as_bytes(), "abc", seqno.next()); tree.flush_active_memtable(0)?; - assert_eq!(9, tree.len()?); + assert_eq!(9, tree.len(None, None)?); // NOTE: Previously, create_compaction_stream would short circuit // breaking this diff --git a/tests/major_compaction.rs b/tests/major_compaction.rs index f5f92bf5..6258fdc0 100644 --- a/tests/major_compaction.rs +++ b/tests/major_compaction.rs @@ -36,7 +36,7 @@ fn tree_major_compaction() -> lsm_tree::Result<()> { assert_eq!(item.key.seqno, 2); assert_eq!(1, tree.segment_count()); - assert_eq!(3, tree.len()?); + assert_eq!(3, tree.len(None, None)?); let batch_seqno = seqno.next(); tree.remove("a".as_bytes(), batch_seqno); @@ -49,7 +49,7 @@ fn tree_major_compaction() -> lsm_tree::Result<()> { tree.major_compact(u64::MAX, 1_000 /* NOTE: Simulate some time passing */)?; assert_eq!(0, tree.segment_count()); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); Ok(()) } diff --git a/tests/open_files.rs b/tests/open_files.rs index dac47f66..a986a170 100644 --- a/tests/open_files.rs +++ b/tests/open_files.rs @@ -19,7 +19,7 @@ fn open_file_limit() -> lsm_tree::Result<()> { } for _ in 0..5 { - assert!(tree.first_key_value()?.is_some()); + assert!(tree.first_key_value(None, None)?.is_some()); } Ok(()) diff --git a/tests/segment_point_reads.rs b/tests/segment_point_reads.rs index 107e5a95..bee3eb0e 100644 --- a/tests/segment_point_reads.rs +++ b/tests/segment_point_reads.rs @@ -21,7 +21,7 @@ fn segment_point_reads() -> lsm_tree::Result<()> { for x in 0..ITEM_COUNT as u64 { let key = x.to_be_bytes(); - assert!(tree.contains_key(key)?, "{key:?} not found"); + assert!(tree.contains_key(key, None)?, "{key:?} not found"); } Ok(()) @@ -133,7 +133,7 @@ fn blob_tree_segment_point_reads_mvcc_slab() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; for key in &keys { - let item = tree.get(key)?.unwrap(); + let item = tree.get(key, None)?.unwrap(); assert_eq!( String::from_utf8_lossy(&item).parse::().unwrap(), ITEM_COUNT as u64 - 1 diff --git a/tests/segment_range.rs b/tests/segment_range.rs index 3fa6b3ff..d240d738 100644 --- a/tests/segment_range.rs +++ b/tests/segment_range.rs @@ -19,13 +19,13 @@ fn segment_ranges() -> lsm_tree::Result<()> { } tree.flush_active_memtable(0)?; - let iter = tree.range(1_000u64.to_be_bytes()..11_000u64.to_be_bytes()); + let iter = tree.range(1_000u64.to_be_bytes()..11_000u64.to_be_bytes(), None, None); assert_eq!(10_000, iter.count()); - let iter = tree.range(1_000u64.to_be_bytes()..11_000u64.to_be_bytes()); + let iter = tree.range(1_000u64.to_be_bytes()..11_000u64.to_be_bytes(), None, None); assert_eq!(10_000, iter.rev().count()); - let mut iter = tree.range(1_000u64.to_be_bytes()..11_000u64.to_be_bytes()); + let mut iter = tree.range(1_000u64.to_be_bytes()..11_000u64.to_be_bytes(), None, None); let mut count = 0; for x in 0.. { @@ -66,13 +66,13 @@ fn segment_range_last_back() -> lsm_tree::Result<()> { } tree.flush_active_memtable(0)?; - let iter = tree.range(0u64.to_be_bytes()..10u64.to_be_bytes()); + let iter = tree.range(0u64.to_be_bytes()..10u64.to_be_bytes(), None, None); assert_eq!(10, iter.count()); - let iter = tree.range(0u64.to_be_bytes()..10u64.to_be_bytes()); + let iter = tree.range(0u64.to_be_bytes()..10u64.to_be_bytes(), None, None); assert_eq!(10, iter.rev().count()); - let mut iter = tree.range(0u64.to_be_bytes()..5u64.to_be_bytes()); + let mut iter = tree.range(0u64.to_be_bytes()..5u64.to_be_bytes(), None, None); assert_eq!(0u64.to_be_bytes(), &*iter.next().unwrap().unwrap().0); assert_eq!(1u64.to_be_bytes(), &*iter.next().unwrap().unwrap().0); @@ -103,13 +103,13 @@ fn segment_range_last_back_2() -> lsm_tree::Result<()> { tree.insert(11u64.to_be_bytes(), [], 0); tree.flush_active_memtable(0)?; - let iter = tree.range(0u64.to_be_bytes()..10u64.to_be_bytes()); + let iter = tree.range(0u64.to_be_bytes()..10u64.to_be_bytes(), None, None); assert_eq!(10, iter.count()); - let iter = tree.range(0u64.to_be_bytes()..10u64.to_be_bytes()); + let iter = tree.range(0u64.to_be_bytes()..10u64.to_be_bytes(), None, None); assert_eq!(10, iter.rev().count()); - let mut iter = tree.range(0u64.to_be_bytes()..12u64.to_be_bytes()); + let mut iter = tree.range(0u64.to_be_bytes()..12u64.to_be_bytes(), None, None); assert_eq!(0u64.to_be_bytes(), &*iter.next().unwrap().unwrap().0); assert_eq!(1u64.to_be_bytes(), &*iter.next().unwrap().unwrap().0); diff --git a/tests/segment_range_oob.rs b/tests/segment_range_oob.rs index 454fae04..f4d2cb27 100644 --- a/tests/segment_range_oob.rs +++ b/tests/segment_range_oob.rs @@ -18,11 +18,11 @@ fn segment_range_out_of_bounds_lo() -> lsm_tree::Result<()> { } tree.flush_active_memtable(0)?; - assert_eq!(4, tree.range(..="k").count()); - assert_eq!(4, tree.range(..="k").rev().count()); + assert_eq!(4, tree.range(..="k", None, None).count()); + assert_eq!(4, tree.range(..="k", None, None).rev().count()); - assert_eq!(4, tree.range("0"..="k").count()); - assert_eq!(4, tree.range("0"..="k").rev().count()); + assert_eq!(4, tree.range("0"..="k", None, None).count()); + assert_eq!(4, tree.range("0"..="k", None, None).rev().count()); Ok(()) } @@ -43,17 +43,22 @@ fn segment_range_out_of_bounds_hi() -> lsm_tree::Result<()> { } tree.flush_active_memtable(0)?; - assert_eq!(50, tree.range((50u64.to_be_bytes())..).count()); - assert_eq!(50, tree.range((50u64.to_be_bytes())..).rev().count()); + assert_eq!(50, tree.range((50u64.to_be_bytes()).., None, None).count()); + assert_eq!( + 50, + tree.range((50u64.to_be_bytes()).., None, None) + .rev() + .count() + ); assert_eq!( 50, - tree.range((50u64.to_be_bytes())..(150u64.to_be_bytes())) + tree.range((50u64.to_be_bytes())..(150u64.to_be_bytes()), None, None) .count() ); assert_eq!( 50, - tree.range((50u64.to_be_bytes())..(150u64.to_be_bytes())) + tree.range((50u64.to_be_bytes())..(150u64.to_be_bytes()), None, None) .rev() .count() ); diff --git a/tests/segment_remove_weak.rs b/tests/segment_remove_weak.rs index 614de031..e834e46f 100644 --- a/tests/segment_remove_weak.rs +++ b/tests/segment_remove_weak.rs @@ -16,7 +16,7 @@ fn segment_remove_weak_simple() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert!(tree.get("a")?.is_none()); + assert!(tree.get("a", None)?.is_none()); Ok(()) } diff --git a/tests/snapshot_compact.rs b/tests/snapshot_compact.rs index fae1878d..1002c36b 100644 --- a/tests/snapshot_compact.rs +++ b/tests/snapshot_compact.rs @@ -16,13 +16,13 @@ fn snapshot_after_compaction() -> lsm_tree::Result<()> { tree.insert(key, "abc".as_bytes(), seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); let snapshot_seqno = seqno.get(); let snapshot = tree.snapshot(snapshot_seqno); - assert_eq!(tree.len()?, snapshot.len()?); - assert_eq!(tree.len()?, snapshot.iter().rev().count()); + assert_eq!(tree.len(None, None)?, snapshot.len()?); + assert_eq!(tree.len(None, None)?, snapshot.iter().rev().count()); for x in 0..ITEM_COUNT as u64 { let key = x.to_be_bytes(); @@ -32,7 +32,7 @@ fn snapshot_after_compaction() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; tree.major_compact(u64::MAX, 0)?; - assert_eq!(tree.len()?, ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); assert_eq!(ITEM_COUNT, snapshot.len()?); assert_eq!(ITEM_COUNT, snapshot.iter().rev().count()); diff --git a/tests/snapshot_len.rs b/tests/snapshot_len.rs index 4f576220..7cbf20f4 100644 --- a/tests/snapshot_len.rs +++ b/tests/snapshot_len.rs @@ -16,26 +16,26 @@ fn snapshot_basic() -> lsm_tree::Result<()> { tree.insert(key, "abc".as_bytes(), seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); for x in 0..ITEM_COUNT as u64 { let key = x.to_be_bytes(); tree.insert(key, "abc".as_bytes(), seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); let snapshot = tree.snapshot(seqno.get()); - assert_eq!(tree.len()?, snapshot.len()?); - assert_eq!(tree.len()?, snapshot.iter().rev().count()); + assert_eq!(tree.len(None, None)?, snapshot.len()?); + assert_eq!(tree.len(None, None)?, snapshot.iter().rev().count()); for x in (ITEM_COUNT as u64)..((ITEM_COUNT * 2) as u64) { let key = x.to_be_bytes(); tree.insert(key, "abc".as_bytes(), seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT * 2); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); assert_eq!(ITEM_COUNT, snapshot.len()?); assert_eq!(ITEM_COUNT, snapshot.iter().rev().count()); diff --git a/tests/snapshot_point_read.rs b/tests/snapshot_point_read.rs index 87f1cf32..c800a1e9 100644 --- a/tests/snapshot_point_read.rs +++ b/tests/snapshot_point_read.rs @@ -16,20 +16,20 @@ fn snapshot_404() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(b"a", &*tree.get("a")?.unwrap()); - assert_eq!(b"a2", &*tree.get("a2")?.unwrap()); - assert!(tree.get("b")?.is_none()); - assert_eq!(b"c", &*tree.get("c")?.unwrap()); + assert_eq!(b"a", &*tree.get("a", None)?.unwrap()); + assert_eq!(b"a2", &*tree.get("a2", None)?.unwrap()); + assert!(tree.get("b", None)?.is_none()); + assert_eq!(b"c", &*tree.get("c", None)?.unwrap()); - assert!(tree.get_with_seqno("a", 0)?.is_none()); - assert!(tree.get_with_seqno("a2", 0)?.is_none()); - assert!(tree.get_with_seqno("b", 0)?.is_none()); - assert!(tree.get_with_seqno("c", 0)?.is_none()); + assert!(tree.get("a", Some(0))?.is_none()); + assert!(tree.get("a2", Some(0))?.is_none()); + assert!(tree.get("b", Some(0))?.is_none()); + assert!(tree.get("c", Some(0))?.is_none()); - assert_eq!(b"a", &*tree.get_with_seqno("a", 1)?.unwrap()); - assert_eq!(b"a2", &*tree.get_with_seqno("a2", 1)?.unwrap()); - assert!(tree.get_with_seqno("b", 1)?.is_none()); - assert_eq!(b"c", &*tree.get_with_seqno("c", 1)?.unwrap()); + assert_eq!(b"a", &*tree.get("a", Some(1))?.unwrap()); + assert_eq!(b"a2", &*tree.get("a2", Some(1))?.unwrap()); + assert!(tree.get("b", Some(1))?.is_none()); + assert_eq!(b"c", &*tree.get("c", Some(1))?.unwrap()); Ok(()) } @@ -56,7 +56,7 @@ fn snapshot_lots_of_versions() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 1); + assert_eq!(tree.len(None, None)?, 1); for seqno in 1..version_count { let item = tree @@ -64,7 +64,7 @@ fn snapshot_lots_of_versions() -> lsm_tree::Result<()> { .expect("should exist"); assert_eq!(format!("abc{}", version_count).as_bytes(), &*item.value); - let item = tree.get(key)?.expect("should exist"); + let item = tree.get(key, None)?.expect("should exist"); assert_eq!(format!("abc{}", version_count).as_bytes(), &*item); } @@ -94,19 +94,19 @@ fn snapshot_disk_point_reads() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); for x in 0..ITEM_COUNT as u64 { let key = x.to_be_bytes(); - let item = tree.get(key)?.expect("should exist"); + let item = tree.get(key, None)?.expect("should exist"); assert_eq!("abc9".as_bytes(), &*item); } let snapshot = tree.snapshot(seqno.get()); - assert_eq!(tree.len()?, snapshot.len()?); - assert_eq!(tree.len()?, snapshot.iter().rev().count()); + assert_eq!(tree.len(None, None)?, snapshot.len()?); + assert_eq!(tree.len(None, None)?, snapshot.iter().rev().count()); // This batch will be too new for snapshot (invisible) for batch in 0..BATCHES { @@ -125,7 +125,7 @@ fn snapshot_disk_point_reads() -> lsm_tree::Result<()> { let item = snapshot.get(key)?.expect("should exist"); assert_eq!("abc9".as_bytes(), &*item); - let item = tree.get(key)?.expect("should exist"); + let item = tree.get(key, None)?.expect("should exist"); assert_eq!("def9".as_bytes(), &*item); } @@ -154,12 +154,12 @@ fn snapshot_disk_and_memtable_reads() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); let snapshot = tree.snapshot(seqno.get()); - assert_eq!(tree.len()?, snapshot.len()?); - assert_eq!(tree.len()?, snapshot.iter().rev().count()); + assert_eq!(tree.len(None, None)?, snapshot.len()?); + assert_eq!(tree.len(None, None)?, snapshot.iter().rev().count()); // This batch will be in memtable and too new for snapshot (invisible) for batch in 0..BATCHES { @@ -177,7 +177,7 @@ fn snapshot_disk_and_memtable_reads() -> lsm_tree::Result<()> { let item = snapshot.get(key)?.expect("should exist"); assert_eq!("abc9".as_bytes(), &*item); - let item = tree.get(key)?.expect("should exist"); + let item = tree.get(key, None)?.expect("should exist"); assert_eq!("def9".as_bytes(), &*item); } diff --git a/tests/snapshot_zombie.rs b/tests/snapshot_zombie.rs index 18125bb8..ac554a9e 100644 --- a/tests/snapshot_zombie.rs +++ b/tests/snapshot_zombie.rs @@ -16,8 +16,8 @@ fn snapshot_zombie_memtable() -> lsm_tree::Result<()> { tree.insert(key, "abc".as_bytes(), seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT); - assert_eq!(tree.iter().rev().count(), ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert_eq!(tree.iter(None, None).rev().count(), ITEM_COUNT); { let snapshot = tree.snapshot(seqno.get()); @@ -30,8 +30,8 @@ fn snapshot_zombie_memtable() -> lsm_tree::Result<()> { tree.remove(key, seqno.next()); } - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().rev().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).rev().count(), 0); { let snapshot = tree.snapshot(seqno.get()); @@ -59,8 +59,8 @@ fn snapshot_zombie_segment() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT); - assert_eq!(tree.iter().rev().count(), ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert_eq!(tree.iter(None, None).rev().count(), ITEM_COUNT); { let snapshot = tree.snapshot(seqno.get()); @@ -75,8 +75,8 @@ fn snapshot_zombie_segment() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().rev().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).rev().count(), 0); { let snapshot = tree.snapshot(seqno.get()); @@ -89,8 +89,8 @@ fn snapshot_zombie_segment() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().rev().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).rev().count(), 0); { let snapshot = tree.snapshot(seqno.get()); diff --git a/tests/tree_approx_len.rs b/tests/tree_approx_len.rs index 3477ec0b..0628816c 100644 --- a/tests/tree_approx_len.rs +++ b/tests/tree_approx_len.rs @@ -8,26 +8,26 @@ fn tree_approx_len_sealed() -> lsm_tree::Result<()> { let tree = Config::new(folder).open()?; - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 0); tree.insert("a", "", 0); - assert_eq!(tree.len()?, 1); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 1); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 1); tree.insert("b", "", 0); - assert_eq!(tree.len()?, 2); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 2); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 2); let _ = tree.rotate_memtable().unwrap(); - assert_eq!(tree.len()?, 2); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 2); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 2); Ok(()) @@ -39,26 +39,26 @@ fn tree_approx_len_sealed_blob() -> lsm_tree::Result<()> { let tree = Config::new(folder).open_as_blob_tree()?; - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 0); tree.insert("a", "", 0); - assert_eq!(tree.len()?, 1); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 1); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 1); tree.insert("b", "", 0); - assert_eq!(tree.len()?, 2); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 2); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 2); let _ = tree.rotate_memtable().unwrap(); - assert_eq!(tree.len()?, 2); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 2); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 2); Ok(()) @@ -70,58 +70,58 @@ fn tree_approx_len() -> lsm_tree::Result<()> { let tree = Config::new(folder).open()?; - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 0); tree.insert("a", "", 0); - assert_eq!(tree.len()?, 1); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 1); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 1); tree.insert("b", "", 0); - assert_eq!(tree.len()?, 2); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 2); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 2); tree.insert("a", "", 1); // Approximate count diverges - assert_eq!(tree.len()?, 2); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 2); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 3); tree.remove("a", 2); - assert_eq!(tree.len()?, 1); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 1); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 4); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 1); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 1); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 4); tree.remove("b", 4); - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 5); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 5); tree.major_compact(u64::MAX, 5)?; // Approximate count converges - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 0); Ok(()) @@ -133,58 +133,58 @@ fn tree_approx_len_blob() -> lsm_tree::Result<()> { let tree = Config::new(folder).open_as_blob_tree()?; - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 0); tree.insert("a", "", 0); - assert_eq!(tree.len()?, 1); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 1); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 1); tree.insert("b", "", 0); - assert_eq!(tree.len()?, 2); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 2); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 2); tree.insert("a", "", 1); // Approximate count diverges - assert_eq!(tree.len()?, 2); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 2); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 3); tree.remove("a", 2); - assert_eq!(tree.len()?, 1); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 1); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 4); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 1); - assert!(!tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 1); + assert!(!tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 4); tree.remove("b", 4); - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 5); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 5); tree.index.major_compact(u64::MAX, 5)?; // Approximate count converges - assert_eq!(tree.len()?, 0); - assert!(tree.is_empty()?); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.is_empty(None, None)?); assert_eq!(tree.approximate_len(), 0); Ok(()) diff --git a/tests/tree_count.rs b/tests/tree_count.rs index 95e87541..ee3eea87 100644 --- a/tests/tree_count.rs +++ b/tests/tree_count.rs @@ -15,9 +15,15 @@ fn tree_memtable_count() -> lsm_tree::Result<()> { tree.insert(key, value.as_bytes(), 0); } - assert_eq!(tree.len()?, ITEM_COUNT); - assert_eq!(tree.iter().filter(|x| x.is_ok()).count(), ITEM_COUNT); - assert_eq!(tree.iter().rev().filter(|x| x.is_ok()).count(), ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert_eq!( + tree.iter(None, None).filter(|x| x.is_ok()).count(), + ITEM_COUNT + ); + assert_eq!( + tree.iter(None, None).rev().filter(|x| x.is_ok()).count(), + ITEM_COUNT + ); Ok(()) } @@ -36,9 +42,15 @@ fn tree_flushed_count() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT); - assert_eq!(tree.iter().filter(|x| x.is_ok()).count(), ITEM_COUNT); - assert_eq!(tree.iter().rev().filter(|x| x.is_ok()).count(), ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert_eq!( + tree.iter(None, None).filter(|x| x.is_ok()).count(), + ITEM_COUNT + ); + assert_eq!( + tree.iter(None, None).rev().filter(|x| x.is_ok()).count(), + ITEM_COUNT + ); Ok(()) } @@ -57,9 +69,15 @@ fn tree_flushed_count_blob() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT); - assert_eq!(tree.iter().filter(|x| x.is_ok()).count(), ITEM_COUNT); - assert_eq!(tree.iter().rev().filter(|x| x.is_ok()).count(), ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert_eq!( + tree.iter(None, None).filter(|x| x.is_ok()).count(), + ITEM_COUNT + ); + assert_eq!( + tree.iter(None, None).rev().filter(|x| x.is_ok()).count(), + ITEM_COUNT + ); Ok(()) } @@ -87,7 +105,7 @@ fn tree_non_locking_count() -> lsm_tree::Result<()> { loop { let chunk = tree - .range(range.clone()) + .range(range.clone(), None, None) .take(10) .collect::>>()?; diff --git a/tests/tree_delete_loop.rs b/tests/tree_delete_loop.rs index 6fffd2a5..80f3cc9e 100644 --- a/tests/tree_delete_loop.rs +++ b/tests/tree_delete_loop.rs @@ -22,20 +22,20 @@ fn tree_delete_by_prefix() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT * 3); - assert_eq!(tree.prefix("a:".as_bytes()).count(), ITEM_COUNT); - assert_eq!(tree.prefix("b:".as_bytes()).count(), ITEM_COUNT); - assert_eq!(tree.prefix("c:".as_bytes()).count(), ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 3); + assert_eq!(tree.prefix("a:".as_bytes(), None, None).count(), ITEM_COUNT); + assert_eq!(tree.prefix("b:".as_bytes(), None, None).count(), ITEM_COUNT); + assert_eq!(tree.prefix("c:".as_bytes(), None, None).count(), ITEM_COUNT); - for item in tree.prefix("b:".as_bytes()) { + for item in tree.prefix("b:".as_bytes(), None, None) { let (key, _) = item?; tree.remove(key, seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.prefix("a:".as_bytes()).count(), ITEM_COUNT); - assert_eq!(tree.prefix("b:".as_bytes()).count(), 0); - assert_eq!(tree.prefix("c:".as_bytes()).count(), ITEM_COUNT); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!(tree.prefix("a:".as_bytes(), None, None).count(), ITEM_COUNT); + assert_eq!(tree.prefix("b:".as_bytes(), None, None).count(), 0); + assert_eq!(tree.prefix("c:".as_bytes(), None, None).count(), ITEM_COUNT); Ok(()) } @@ -56,14 +56,14 @@ fn tree_delete_by_range() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 6); + assert_eq!(tree.len(None, None)?, 6); - for item in tree.range("c"..="e") { + for item in tree.range("c"..="e", None, None) { let (key, _) = item?; tree.remove(key, 1); } - assert_eq!(tree.len()?, 3); + assert_eq!(tree.len(None, None)?, 3); Ok(()) } diff --git a/tests/tree_different_block_size.rs b/tests/tree_different_block_size.rs index 387cee7e..e8c2929c 100644 --- a/tests/tree_different_block_size.rs +++ b/tests/tree_different_block_size.rs @@ -23,7 +23,7 @@ fn tree_block_size_after_recovery() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(ITEM_COUNT, tree.len()?); + assert_eq!(ITEM_COUNT, tree.len(None, None)?); } { @@ -31,7 +31,7 @@ fn tree_block_size_after_recovery() -> lsm_tree::Result<()> { .data_block_size(2_048) .index_block_size(2_048) .open()?; - assert_eq!(ITEM_COUNT, tree.len()?); + assert_eq!(ITEM_COUNT, tree.len(None, None)?); } { @@ -39,7 +39,7 @@ fn tree_block_size_after_recovery() -> lsm_tree::Result<()> { .data_block_size(4_096) .index_block_size(4_096) .open()?; - assert_eq!(ITEM_COUNT, tree.len()?); + assert_eq!(ITEM_COUNT, tree.len(None, None)?); } { @@ -47,7 +47,7 @@ fn tree_block_size_after_recovery() -> lsm_tree::Result<()> { .data_block_size(78_652) .index_block_size(78_652) .open()?; - assert_eq!(ITEM_COUNT, tree.len()?); + assert_eq!(ITEM_COUNT, tree.len(None, None)?); } Ok(()) diff --git a/tests/tree_disjoint_iter.rs b/tests/tree_disjoint_iter.rs index 407552c1..912e636b 100644 --- a/tests/tree_disjoint_iter.rs +++ b/tests/tree_disjoint_iter.rs @@ -30,7 +30,7 @@ fn tree_disjoint_iter() -> lsm_tree::Result<()> { // NOTE: Forwards - let mut iter = tree.iter(); + let mut iter = tree.iter(None, None); assert_eq!(Slice::from(*b"a"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"b"), iter.next().unwrap()?.0); @@ -42,7 +42,7 @@ fn tree_disjoint_iter() -> lsm_tree::Result<()> { // NOTE: Reverse - let mut iter = tree.iter().rev(); + let mut iter = tree.iter(None, None).rev(); assert_eq!(Slice::from(*b"f"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"e"), iter.next().unwrap()?.0); @@ -54,7 +54,7 @@ fn tree_disjoint_iter() -> lsm_tree::Result<()> { // NOTE: Ping Pong - let mut iter = tree.iter(); + let mut iter = tree.iter(None, None); assert_eq!(Slice::from(*b"a"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"f"), iter.next_back().unwrap()?.0); diff --git a/tests/tree_disjoint_point_read.rs b/tests/tree_disjoint_point_read.rs index 7eeed404..ed22639f 100644 --- a/tests/tree_disjoint_point_read.rs +++ b/tests/tree_disjoint_point_read.rs @@ -24,7 +24,7 @@ fn tree_disjoint_point_read() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; for key in [b"a", b"b", b"c", b"d", b"e", b"f"] { - let value = tree.get(key).unwrap().unwrap(); + let value = tree.get(key, None).unwrap().unwrap(); assert_eq!(&*value, key) } @@ -53,7 +53,7 @@ fn tree_disjoint_point_read_blob() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; for key in [b"a", b"b", b"c", b"d", b"e", b"f"] { - let value = tree.get(key).unwrap().unwrap(); + let value = tree.get(key, None).unwrap().unwrap(); assert_eq!(&*value, key) } @@ -107,7 +107,7 @@ fn tree_disjoint_point_read_multiple_levels() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; for key in [b"z", b"b", b"c", b"d", b"e", b"f"] { - let value = tree.get(key).unwrap().unwrap(); + let value = tree.get(key, None).unwrap().unwrap(); assert_eq!(&*value, key) } @@ -162,7 +162,7 @@ fn tree_disjoint_point_read_multiple_levels_blob() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; for key in [b"z", b"b", b"c", b"d", b"e", b"f"] { - let value = tree.get(key).unwrap().unwrap(); + let value = tree.get(key, None).unwrap().unwrap(); assert_eq!(&*value, key) } diff --git a/tests/tree_disjoint_prefix.rs b/tests/tree_disjoint_prefix.rs index 9fa94458..4000d8e5 100644 --- a/tests/tree_disjoint_prefix.rs +++ b/tests/tree_disjoint_prefix.rs @@ -35,7 +35,7 @@ fn tree_disjoint_prefix() -> lsm_tree::Result<()> { // NOTE: Forwards - let mut iter = tree.prefix("d"); + let mut iter = tree.prefix("d", None, None); assert_eq!(Slice::from(*b"da"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"db"), iter.next().unwrap()?.0); @@ -44,7 +44,7 @@ fn tree_disjoint_prefix() -> lsm_tree::Result<()> { // NOTE: Reverse - let mut iter = tree.prefix("d").rev(); + let mut iter = tree.prefix("d", None, None).rev(); assert_eq!(Slice::from(*b"dc"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"db"), iter.next().unwrap()?.0); @@ -53,7 +53,7 @@ fn tree_disjoint_prefix() -> lsm_tree::Result<()> { // NOTE: Ping Pong - let mut iter = tree.prefix("d"); + let mut iter = tree.prefix("d", None, None); assert_eq!(Slice::from(*b"da"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"dc"), iter.next_back().unwrap()?.0); diff --git a/tests/tree_disjoint_range.rs b/tests/tree_disjoint_range.rs index 4f751d57..e0aa43b1 100644 --- a/tests/tree_disjoint_range.rs +++ b/tests/tree_disjoint_range.rs @@ -35,7 +35,7 @@ fn tree_disjoint_range() -> lsm_tree::Result<()> { // NOTE: Forwards - let mut iter = tree.range("e".."i"); + let mut iter = tree.range("e".."i", None, None); assert_eq!(Slice::from(*b"e"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"f"), iter.next().unwrap()?.0); @@ -45,7 +45,7 @@ fn tree_disjoint_range() -> lsm_tree::Result<()> { // NOTE: Forwards inclusive - let mut iter = tree.range("e"..="i"); + let mut iter = tree.range("e"..="i", None, None); assert_eq!(Slice::from(*b"e"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"f"), iter.next().unwrap()?.0); @@ -56,7 +56,7 @@ fn tree_disjoint_range() -> lsm_tree::Result<()> { // NOTE: Reverse - let mut iter = tree.range("e".."i").rev(); + let mut iter = tree.range("e".."i", None, None).rev(); assert_eq!(Slice::from(*b"h"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"g"), iter.next().unwrap()?.0); @@ -66,7 +66,7 @@ fn tree_disjoint_range() -> lsm_tree::Result<()> { // NOTE: Reverse inclusive - let mut iter = tree.range("e"..="i").rev(); + let mut iter = tree.range("e"..="i", None, None).rev(); assert_eq!(Slice::from(*b"i"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"h"), iter.next().unwrap()?.0); @@ -77,7 +77,7 @@ fn tree_disjoint_range() -> lsm_tree::Result<()> { // NOTE: Ping Pong - let mut iter = tree.range("e".."i"); + let mut iter = tree.range("e".."i", None, None); assert_eq!(Slice::from(*b"e"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"h"), iter.next_back().unwrap()?.0); @@ -87,7 +87,7 @@ fn tree_disjoint_range() -> lsm_tree::Result<()> { // NOTE: Ping Pong inclusive - let mut iter = tree.range("e"..="i"); + let mut iter = tree.range("e"..="i", None, None); assert_eq!(Slice::from(*b"e"), iter.next().unwrap()?.0); assert_eq!(Slice::from(*b"i"), iter.next_back().unwrap()?.0); diff --git a/tests/tree_flush_eviction.rs b/tests/tree_flush_eviction.rs index 2e78e5f0..de9b883c 100644 --- a/tests/tree_flush_eviction.rs +++ b/tests/tree_flush_eviction.rs @@ -11,12 +11,12 @@ fn tree_flush_eviction_1() -> lsm_tree::Result<()> { tree.insert("a", "a", 0); tree.remove_weak("a", 1); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); // NOTE: Should not evict weak tombstone tree.flush_active_memtable(0)?; assert_eq!(1, tree.segment_count()); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); Ok(()) } @@ -30,12 +30,12 @@ fn tree_flush_eviction_2() -> lsm_tree::Result<()> { tree.insert("a", "a", 0); tree.remove_weak("a", 1); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); // NOTE: Should evict old value, thus weak tombstone too tree.flush_active_memtable(1)?; assert_eq!(0, tree.segment_count()); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); Ok(()) } @@ -49,17 +49,17 @@ fn tree_flush_eviction_3() -> lsm_tree::Result<()> { tree.insert("a", "a", 0); tree.remove("a", 1); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); // NOTE: Should evict old value, but tombstone should stay until last level tree.flush_active_memtable(1)?; assert_eq!(1, tree.segment_count()); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); // NOTE: Should evict tombstone because last level tree.compact(Arc::new(lsm_tree::compaction::PullDown(0, 6)), 0)?; assert_eq!(0, tree.segment_count()); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); Ok(()) } @@ -74,12 +74,12 @@ fn tree_flush_eviction_4() -> lsm_tree::Result<()> { tree.insert("a", "a", 0); tree.remove("a", 1); tree.insert("a", "a", 2); - assert_eq!(1, tree.len()?); + assert_eq!(1, tree.len(None, None)?); // NOTE: Tombstone should stay because of seqno threshold tree.flush_active_memtable(1)?; assert_eq!(1, tree.segment_count()); - assert_eq!(1, tree.len()?); + assert_eq!(1, tree.len(None, None)?); assert_eq!( 1, tree.levels @@ -96,7 +96,7 @@ fn tree_flush_eviction_4() -> lsm_tree::Result<()> { // NOTE: Should evict tombstone because last level tree.compact(Arc::new(lsm_tree::compaction::PullDown(0, 6)), 0)?; assert_eq!(1, tree.segment_count()); - assert_eq!(1, tree.len()?); + assert_eq!(1, tree.len(None, None)?); assert_eq!( 0, tree.levels diff --git a/tests/tree_iter_lifetime.rs b/tests/tree_iter_lifetime.rs index 8c8212e7..655de9d3 100644 --- a/tests/tree_iter_lifetime.rs +++ b/tests/tree_iter_lifetime.rs @@ -12,7 +12,7 @@ fn iterrr( tree.insert(x, x, 0); } - Ok(tree.iter()) + Ok(tree.iter(None, None)) } #[test] diff --git a/tests/tree_kv.rs b/tests/tree_kv.rs index 47558422..efb6ef8f 100644 --- a/tests/tree_kv.rs +++ b/tests/tree_kv.rs @@ -8,51 +8,51 @@ fn tree_first_last_kv() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open()?; - assert!(tree.is_empty()?); - assert_eq!(tree.first_key_value()?, None); - assert_eq!(tree.last_key_value()?, None); + assert!(tree.is_empty(None, None)?); + assert_eq!(tree.first_key_value(None, None)?, None); + assert_eq!(tree.last_key_value(None, None)?, None); tree.insert("b", "b", 0); - assert_eq!(b"b", &*tree.first_key_value()?.unwrap().0); - assert_eq!(b"b", &*tree.last_key_value()?.unwrap().0); + assert_eq!(b"b", &*tree.first_key_value(None, None)?.unwrap().0); + assert_eq!(b"b", &*tree.last_key_value(None, None)?.unwrap().0); tree.flush_active_memtable(0)?; - assert_eq!(b"b", &*tree.first_key_value()?.unwrap().0); - assert_eq!(b"b", &*tree.last_key_value()?.unwrap().0); + assert_eq!(b"b", &*tree.first_key_value(None, None)?.unwrap().0); + assert_eq!(b"b", &*tree.last_key_value(None, None)?.unwrap().0); } { let tree = Config::new(&folder).open()?; - assert_eq!(1, tree.len()?); + assert_eq!(1, tree.len(None, None)?); - assert_eq!(b"b", &*tree.first_key_value()?.unwrap().0); - assert_eq!(b"b", &*tree.last_key_value()?.unwrap().0); + assert_eq!(b"b", &*tree.first_key_value(None, None)?.unwrap().0); + assert_eq!(b"b", &*tree.last_key_value(None, None)?.unwrap().0); tree.insert("a", "a", 0); - assert_eq!(2, tree.len()?); + assert_eq!(2, tree.len(None, None)?); - assert_eq!(b"a", &*tree.first_key_value()?.unwrap().0); - assert_eq!(b"b", &*tree.last_key_value()?.unwrap().0); + assert_eq!(b"a", &*tree.first_key_value(None, None)?.unwrap().0); + assert_eq!(b"b", &*tree.last_key_value(None, None)?.unwrap().0); tree.insert("c", "c", 0); - assert_eq!(3, tree.len()?); + assert_eq!(3, tree.len(None, None)?); - assert_eq!(b"a", &*tree.first_key_value()?.unwrap().0); - assert_eq!(b"c", &*tree.last_key_value()?.unwrap().0); + assert_eq!(b"a", &*tree.first_key_value(None, None)?.unwrap().0); + assert_eq!(b"c", &*tree.last_key_value(None, None)?.unwrap().0); tree.flush_active_memtable(0)?; - assert_eq!(b"a", &*tree.first_key_value()?.unwrap().0); - assert_eq!(b"c", &*tree.last_key_value()?.unwrap().0); + assert_eq!(b"a", &*tree.first_key_value(None, None)?.unwrap().0); + assert_eq!(b"c", &*tree.last_key_value(None, None)?.unwrap().0); } { let tree = Config::new(&folder).open()?; - assert_eq!(3, tree.len()?); + assert_eq!(3, tree.len(None, None)?); - assert_eq!(b"a", &*tree.first_key_value()?.unwrap().0); - assert_eq!(b"c", &*tree.last_key_value()?.unwrap().0); + assert_eq!(b"a", &*tree.first_key_value(None, None)?.unwrap().0); + assert_eq!(b"c", &*tree.last_key_value(None, None)?.unwrap().0); } Ok(()) diff --git a/tests/tree_l0_point_read.rs b/tests/tree_l0_point_read.rs index 4d91cf3d..7a4f2efd 100644 --- a/tests/tree_l0_point_read.rs +++ b/tests/tree_l0_point_read.rs @@ -31,13 +31,13 @@ fn tree_l0_point_read() -> lsm_tree::Result<()> { tree.insert("g", "g", 3); tree.flush_active_memtable(0)?; - assert_eq!(b"A", &*tree.get("a")?.unwrap()); - assert_eq!(b"B", &*tree.get("b")?.unwrap()); - assert_eq!(b"C", &*tree.get("c")?.unwrap()); - assert_eq!(b"d", &*tree.get("d")?.unwrap()); - assert_eq!(b"e", &*tree.get("e")?.unwrap()); - assert_eq!(b"f", &*tree.get("f")?.unwrap()); - assert_eq!(b"g", &*tree.get("g")?.unwrap()); + assert_eq!(b"A", &*tree.get("a", None)?.unwrap()); + assert_eq!(b"B", &*tree.get("b", None)?.unwrap()); + assert_eq!(b"C", &*tree.get("c", None)?.unwrap()); + assert_eq!(b"d", &*tree.get("d", None)?.unwrap()); + assert_eq!(b"e", &*tree.get("e", None)?.unwrap()); + assert_eq!(b"f", &*tree.get("f", None)?.unwrap()); + assert_eq!(b"g", &*tree.get("g", None)?.unwrap()); Ok(()) } diff --git a/tests/tree_l0_range.rs b/tests/tree_l0_range.rs index 9bebaf54..22d656a4 100644 --- a/tests/tree_l0_range.rs +++ b/tests/tree_l0_range.rs @@ -31,13 +31,13 @@ fn tree_l0_range() -> lsm_tree::Result<()> { tree.insert("g", "g", 3); tree.flush_active_memtable(0)?; - let mut range = tree.range("c"..="e"); + let mut range = tree.range("c"..="e", None, None); assert_eq!(b"C", &*range.next().unwrap().unwrap().1); assert_eq!(b"d", &*range.next().unwrap().unwrap().1); assert_eq!(b"e", &*range.next().unwrap().unwrap().1); assert!(range.next().is_none()); - let mut range = tree.range("f"..="g").rev(); + let mut range = tree.range("f"..="g", None, None).rev(); assert_eq!(b"g", &*range.next().unwrap().unwrap().1); assert_eq!(b"f", &*range.next().unwrap().unwrap().1); assert!(range.next().is_none()); diff --git a/tests/tree_mvcc_simple.rs b/tests/tree_mvcc_simple.rs index 1d3e2456..e1ca3b91 100644 --- a/tests/tree_mvcc_simple.rs +++ b/tests/tree_mvcc_simple.rs @@ -22,9 +22,9 @@ fn tree_read_mvcc() -> lsm_tree::Result<()> { tree.insert("a", "a5", 5); - assert_eq!(&*tree.get("a")?.unwrap(), b"a5"); - assert_eq!(&*tree.get("b")?.unwrap(), b"b3"); - assert_eq!(&*tree.get("c")?.unwrap(), b"c4"); + assert_eq!(&*tree.get("a", None)?.unwrap(), b"a5"); + assert_eq!(&*tree.get("b", None)?.unwrap(), b"b3"); + assert_eq!(&*tree.get("c", None)?.unwrap(), b"c4"); let snapshot = tree.snapshot(1); assert_eq!(&*snapshot.get("a")?.unwrap(), b"a0"); @@ -61,7 +61,7 @@ fn tree_read_mvcc() -> lsm_tree::Result<()> { assert_eq!(&*snapshot.get("b")?.unwrap(), b"b3"); assert_eq!(&*snapshot.get("c")?.unwrap(), b"c4"); - let mut iter = tree.iter(); + let mut iter = tree.iter(None, None); assert_eq!(&*iter.next().unwrap().unwrap().1, b"a5"); assert_eq!(&*iter.next().unwrap().unwrap().1, b"b3"); diff --git a/tests/tree_non_disjoint_point_read.rs b/tests/tree_non_disjoint_point_read.rs index b829da69..f8ebb115 100644 --- a/tests/tree_non_disjoint_point_read.rs +++ b/tests/tree_non_disjoint_point_read.rs @@ -44,12 +44,12 @@ fn tree_non_disjoint_point_read() -> lsm_tree::Result<()> { tree.insert("z", "z", 0); tree.flush_active_memtable(0)?; - tree.get("c").unwrap().unwrap(); - tree.get("d").unwrap().unwrap(); - tree.get("e").unwrap().unwrap(); - tree.get("f").unwrap().unwrap(); - tree.get("g").unwrap().unwrap(); - tree.get("h").unwrap().unwrap(); + tree.get("c", None).unwrap().unwrap(); + tree.get("d", None).unwrap().unwrap(); + tree.get("e", None).unwrap().unwrap(); + tree.get("f", None).unwrap().unwrap(); + tree.get("g", None).unwrap().unwrap(); + tree.get("h", None).unwrap().unwrap(); Ok(()) } diff --git a/tests/tree_range.rs b/tests/tree_range.rs index f3d57c91..dc99ec3d 100644 --- a/tests/tree_range.rs +++ b/tests/tree_range.rs @@ -17,33 +17,45 @@ fn tree_range_count() -> lsm_tree::Result<()> { tree.insert("f".as_bytes(), nanoid::nanoid!().as_bytes(), 4); tree.insert("g".as_bytes(), nanoid::nanoid!().as_bytes(), 5); - assert_eq!(2, tree.range("a"..="f").count()); - assert_eq!(2, tree.range("f"..="g").count()); + assert_eq!(2, tree.range("a"..="f", None, None).count()); + assert_eq!(2, tree.range("f"..="g", None, None).count()); assert_eq!( 1, - tree.range::, (Bound>, Bound>)>((Excluded("f".into()), Unbounded)) - .count() + tree.range::, (Bound>, Bound>)>( + (Excluded("f".into()), Unbounded), + None, + None + ) + .count() ); tree.flush_active_memtable(0)?; - assert_eq!(2, tree.range("a"..="f").count()); + assert_eq!(2, tree.range("a"..="f", None, None).count(),); assert_eq!( 1, - tree.range::, (Bound>, Bound>)>((Excluded("f".into()), Unbounded)) - .count() + tree.range::, (Bound>, Bound>)>( + (Excluded("f".into()), Unbounded), + None, + None + ) + .count() ); tree.insert("a".as_bytes(), nanoid::nanoid!().as_bytes(), 6); tree.insert("f".as_bytes(), nanoid::nanoid!().as_bytes(), 7); tree.insert("g".as_bytes(), nanoid::nanoid!().as_bytes(), 8); - assert_eq!(2, tree.range("a"..="f").count()); + assert_eq!(2, tree.range("a"..="f", None, None).count()); assert_eq!( 1, - tree.range::, (Bound>, Bound>)>((Excluded("f".into()), Unbounded)) - .count() + tree.range::, (Bound>, Bound>)>( + (Excluded("f".into()), Unbounded), + None, + None + ) + .count() ); Ok(()) @@ -65,33 +77,45 @@ fn blob_tree_range_count() -> lsm_tree::Result<()> { tree.insert("f".as_bytes(), b"neptune!".repeat(128_000), 4); tree.insert("g".as_bytes(), nanoid::nanoid!().as_bytes(), 5); - assert_eq!(2, tree.range("a"..="f").count()); - assert_eq!(2, tree.range("f"..="g").count()); + assert_eq!(2, tree.range("a"..="f", None, None).count()); + assert_eq!(2, tree.range("f"..="g", None, None).count()); assert_eq!( 1, - tree.range::, (Bound>, Bound>)>((Excluded("f".into()), Unbounded)) - .count() + tree.range::, (Bound>, Bound>)>( + (Excluded("f".into()), Unbounded), + None, + None + ) + .count() ); tree.flush_active_memtable(0)?; - assert_eq!(2, tree.range("a"..="f").count()); + assert_eq!(2, tree.range("a"..="f", None, None).count()); assert_eq!( 1, - tree.range::, (Bound>, Bound>)>((Excluded("f".into()), Unbounded)) - .count() + tree.range::, (Bound>, Bound>)>( + (Excluded("f".into()), Unbounded), + None, + None + ) + .count() ); tree.insert("a".as_bytes(), nanoid::nanoid!().as_bytes(), 6); tree.insert("f".as_bytes(), nanoid::nanoid!().as_bytes(), 7); tree.insert("g".as_bytes(), nanoid::nanoid!().as_bytes(), 8); - assert_eq!(2, tree.range("a"..="f").count()); + assert_eq!(2, tree.range("a"..="f", None, None).count()); assert_eq!( 1, - tree.range::, (Bound>, Bound>)>((Excluded("f".into()), Unbounded)) - .count() + tree.range::, (Bound>, Bound>)>( + (Excluded("f".into()), Unbounded), + None, + None + ) + .count() ); Ok(()) diff --git a/tests/tree_range_memtable_only.rs b/tests/tree_range_memtable_only.rs index 54bf8df1..a78e4065 100644 --- a/tests/tree_range_memtable_only.rs +++ b/tests/tree_range_memtable_only.rs @@ -11,36 +11,36 @@ fn tree_range_memtable_only() -> lsm_tree::Result<()> { tree.insert("b", "", 0); tree.insert("c", "", 0); - let found = tree - .range("a".."a") + let found: Vec = tree + .range("a".."a", None, None) .flatten() .map(|(k, _)| String::from_utf8(k.to_vec()).unwrap()) .collect::>(); assert_eq!(Vec::::new(), found); let found = tree - .range("a"..="a") + .range("a"..="a", None, None) .flatten() .map(|(k, _)| String::from_utf8(k.to_vec()).unwrap()) .collect::>(); assert_eq!(vec!["a"], found); let found = tree - .range("a".."b") + .range("a".."b", None, None) .flatten() .map(|(k, _)| String::from_utf8(k.to_vec()).unwrap()) .collect::>(); assert_eq!(vec!["a"], found); let found = tree - .range("a"..="b") + .range("a"..="b", None, None) .flatten() .map(|(k, _)| String::from_utf8(k.to_vec()).unwrap()) .collect::>(); assert_eq!(vec!["a", "b"], found); let found = tree - .range("a".."a") + .range("a".."a", None, None) .flatten() .rev() .map(|(k, _)| String::from_utf8(k.to_vec()).unwrap()) @@ -48,7 +48,7 @@ fn tree_range_memtable_only() -> lsm_tree::Result<()> { assert_eq!(Vec::::new(), found); let found = tree - .range("a"..="a") + .range("a"..="a", None, None) .flatten() .rev() .map(|(k, _)| String::from_utf8(k.to_vec()).unwrap()) @@ -56,7 +56,7 @@ fn tree_range_memtable_only() -> lsm_tree::Result<()> { assert_eq!(vec!["a"], found); let found = tree - .range("a".."b") + .range("a".."b", None, None) .flatten() .rev() .map(|(k, _)| String::from_utf8(k.to_vec()).unwrap()) @@ -64,7 +64,7 @@ fn tree_range_memtable_only() -> lsm_tree::Result<()> { assert_eq!(vec!["a"], found); let found = tree - .range("a"..="b") + .range("a"..="b", None, None) .flatten() .rev() .map(|(k, _)| String::from_utf8(k.to_vec()).unwrap()) diff --git a/tests/tree_recover_large_value.rs b/tests/tree_recover_large_value.rs index eac45144..fe6b15f7 100644 --- a/tests/tree_recover_large_value.rs +++ b/tests/tree_recover_large_value.rs @@ -14,7 +14,7 @@ fn tree_recover_large_value() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open()?; assert_eq!( - &*tree.get("a")?.expect("should exist"), + &*tree.get("a", None)?.expect("should exist"), "a".repeat(100_000).as_bytes() ); } diff --git a/tests/tree_reload.rs b/tests/tree_reload.rs index 256dae8d..6672beb8 100644 --- a/tests/tree_reload.rs +++ b/tests/tree_reload.rs @@ -11,18 +11,18 @@ fn tree_reload_empty() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); assert_eq!(tree.tree_type(), TreeType::Standard); } { let tree = Config::new(&folder).open()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); assert_eq!(tree.tree_type(), TreeType::Standard); tree.flush_active_memtable(0)?; @@ -31,9 +31,9 @@ fn tree_reload_empty() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); assert_eq!(tree.tree_type(), TreeType::Standard); } @@ -63,9 +63,12 @@ fn tree_reload() -> lsm_tree::Result<()> { tree.insert(key, value.as_bytes(), seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.iter().flatten().count(), ITEM_COUNT * 2); - assert_eq!(tree.iter().rev().flatten().count(), ITEM_COUNT * 2); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!(tree.iter(None, None).flatten().count(), ITEM_COUNT * 2); + assert_eq!( + tree.iter(None, None).rev().flatten().count(), + ITEM_COUNT * 2 + ); tree.flush_active_memtable(0)?; } @@ -73,9 +76,12 @@ fn tree_reload() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open()?; - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.iter().flatten().count(), ITEM_COUNT * 2); - assert_eq!(tree.iter().rev().flatten().count(), ITEM_COUNT * 2); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!(tree.iter(None, None).flatten().count(), ITEM_COUNT * 2); + assert_eq!( + tree.iter(None, None).rev().flatten().count(), + ITEM_COUNT * 2 + ); } std::thread::sleep(std::time::Duration::from_secs(2)); @@ -103,18 +109,18 @@ fn tree_remove_unfinished_segments() -> lsm_tree::Result<()> { { let tree = Config::new(&folder).open()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); } // Recover tree { let tree = Config::new(&folder).open()?; - assert_eq!(tree.len()?, 0); - assert_eq!(tree.iter().flatten().count(), 0); - assert_eq!(tree.iter().rev().flatten().count(), 0); + assert_eq!(tree.len(None, None)?, 0); + assert_eq!(tree.iter(None, None).flatten().count(), 0); + assert_eq!(tree.iter(None, None).rev().flatten().count(), 0); } assert!(!file0.try_exists()?); diff --git a/tests/tree_reload_pwd.rs b/tests/tree_reload_pwd.rs index 2c2435fc..2b5dc4b5 100644 --- a/tests/tree_reload_pwd.rs +++ b/tests/tree_reload_pwd.rs @@ -21,7 +21,7 @@ fn tree_reload_pwd() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(ITEM_COUNT, tree.len()?); + assert_eq!(ITEM_COUNT, tree.len(None, None)?); } let folder_new = tempfile::tempdir()?; @@ -37,7 +37,7 @@ fn tree_reload_pwd() -> lsm_tree::Result<()> { { let tree = Config::new(&folder_new_subfolder).open()?; - assert_eq!(ITEM_COUNT, tree.len()?); + assert_eq!(ITEM_COUNT, tree.len(None, None)?); } Ok(()) diff --git a/tests/tree_sealed_shadowing.rs b/tests/tree_sealed_shadowing.rs index ebc1806c..5b5325f3 100644 --- a/tests/tree_sealed_shadowing.rs +++ b/tests/tree_sealed_shadowing.rs @@ -9,24 +9,24 @@ fn tree_sealed_memtable_tombstone_shadowing() -> lsm_tree::Result<()> { let tree = Config::new(path).open()?; tree.insert("a", "123", 0); - assert!(tree.contains_key("a")?); + assert!(tree.contains_key("a", None)?); tree.flush_active_memtable(0)?; tree.remove("a", 1); - assert!(!tree.contains_key("a")?); + assert!(!tree.contains_key("a", None)?); let (id, memtable) = tree.rotate_memtable().unwrap(); - assert!(!tree.contains_key("a")?); + assert!(!tree.contains_key("a", None)?); let segment = tree.flush_memtable(id, &memtable, 0)?.unwrap(); tree.register_segments(&[segment])?; - assert!(!tree.contains_key("a")?); + assert!(!tree.contains_key("a", None)?); tree.major_compact(u64::MAX, 2)?; - assert!(!tree.contains_key("a")?); + assert!(!tree.contains_key("a", None)?); Ok(()) } diff --git a/tests/tree_shadowing.rs b/tests/tree_shadowing.rs index 745fbbca..2b0fc3d7 100644 --- a/tests/tree_shadowing.rs +++ b/tests/tree_shadowing.rs @@ -10,24 +10,24 @@ fn tree_shadowing_upsert() -> lsm_tree::Result<()> { let key = "1".as_bytes(); let value = "oldvalue".as_bytes(); - assert_eq!(tree.len()?, 0); + assert_eq!(tree.len(None, None)?, 0); tree.insert(key, value, 0); - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); let value = "newvalue".as_bytes(); tree.insert(key, value, 1); - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); Ok(()) } @@ -41,24 +41,24 @@ fn tree_shadowing_upsert_blob() -> lsm_tree::Result<()> { let key = "1".as_bytes(); let value = "oldvalue".as_bytes(); - assert_eq!(tree.len()?, 0); + assert_eq!(tree.len(None, None)?, 0); tree.insert(key, value, 0); - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); let value = "newvalue".as_bytes(); tree.insert(key, value, 1); - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); Ok(()) } @@ -72,22 +72,22 @@ fn tree_shadowing_delete() -> lsm_tree::Result<()> { let key = "1".as_bytes(); let value = "oldvalue".as_bytes(); - assert_eq!(tree.len()?, 0); + assert_eq!(tree.len(None, None)?, 0); tree.insert(key, value, 0); - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); tree.remove(key, 1); - assert_eq!(tree.len()?, 0); - assert!(tree.get(key)?.is_none()); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.get(key, None)?.is_none()); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 0); - assert!(tree.get(key)?.is_none()); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.get(key, None)?.is_none()); Ok(()) } @@ -101,22 +101,22 @@ fn tree_shadowing_delete_blob() -> lsm_tree::Result<()> { let key = "1".as_bytes(); let value = "oldvalue".as_bytes(); - assert_eq!(tree.len()?, 0); + assert_eq!(tree.len(None, None)?, 0); tree.insert(key, value, 0); - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 1); - assert_eq!(tree.get(key)?, Some(value.into())); + assert_eq!(tree.len(None, None)?, 1); + assert_eq!(tree.get(key, None)?, Some(value.into())); tree.remove(key, 1); - assert_eq!(tree.len()?, 0); - assert!(tree.get(key)?.is_none()); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.get(key, None)?.is_none()); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, 0); - assert!(tree.get(key)?.is_none()); + assert_eq!(tree.len(None, None)?, 0); + assert!(tree.get(key, None)?.is_none()); Ok(()) } @@ -139,8 +139,10 @@ fn tree_shadowing_range() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "old".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "old".as_bytes())); for x in 0..ITEM_COUNT as u64 { let key = x.to_be_bytes(); @@ -148,13 +150,17 @@ fn tree_shadowing_range() -> lsm_tree::Result<()> { tree.insert(key, value, seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "new".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "new".as_bytes())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "new".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "new".as_bytes())); Ok(()) } @@ -177,8 +183,10 @@ fn tree_shadowing_range_blob() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "old".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "old".as_bytes())); for x in 0..ITEM_COUNT as u64 { let key = x.to_be_bytes(); @@ -186,13 +194,17 @@ fn tree_shadowing_range_blob() -> lsm_tree::Result<()> { tree.insert(key, value, seqno.next()); } - assert_eq!(tree.len()?, ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "new".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "new".as_bytes())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "new".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "new".as_bytes())); Ok(()) } @@ -217,10 +229,18 @@ fn tree_shadowing_prefix() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.prefix("pre".as_bytes()).count(), ITEM_COUNT * 2); - assert_eq!(tree.prefix("prefix".as_bytes()).count(), ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "old".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!( + tree.prefix("pre".as_bytes(), None, None).count(), + ITEM_COUNT * 2 + ); + assert_eq!( + tree.prefix("prefix".as_bytes(), None, None).count(), + ITEM_COUNT + ); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "old".as_bytes())); for x in 0..ITEM_COUNT as u64 { let value = "new".as_bytes(); @@ -230,17 +250,33 @@ fn tree_shadowing_prefix() -> lsm_tree::Result<()> { tree.insert(format!("prefix:{x}").as_bytes(), value, batch_seqno); } - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.prefix("pre".as_bytes()).count(), ITEM_COUNT * 2); - assert_eq!(tree.prefix("prefix".as_bytes()).count(), ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "new".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!( + tree.prefix("pre".as_bytes(), None, None).count(), + ITEM_COUNT * 2 + ); + assert_eq!( + tree.prefix("prefix".as_bytes(), None, None).count(), + ITEM_COUNT + ); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "new".as_bytes())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.prefix("pre".as_bytes()).count(), ITEM_COUNT * 2); - assert_eq!(tree.prefix("prefix".as_bytes()).count(), ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "new".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!( + tree.prefix("pre".as_bytes(), None, None).count(), + ITEM_COUNT * 2 + ); + assert_eq!( + tree.prefix("prefix".as_bytes(), None, None).count(), + ITEM_COUNT + ); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "new".as_bytes())); Ok(()) } @@ -265,10 +301,18 @@ fn tree_shadowing_prefix_blob() -> lsm_tree::Result<()> { tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.prefix("pre".as_bytes()).count(), ITEM_COUNT * 2); - assert_eq!(tree.prefix("prefix".as_bytes()).count(), ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "old".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!( + tree.prefix("pre".as_bytes(), None, None).count(), + ITEM_COUNT * 2 + ); + assert_eq!( + tree.prefix("prefix".as_bytes(), None, None).count(), + ITEM_COUNT + ); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "old".as_bytes())); for x in 0..ITEM_COUNT as u64 { let value = "new".as_bytes(); @@ -278,17 +322,33 @@ fn tree_shadowing_prefix_blob() -> lsm_tree::Result<()> { tree.insert(format!("prefix:{x}").as_bytes(), value, batch_seqno); } - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.prefix("pre".as_bytes()).count(), ITEM_COUNT * 2); - assert_eq!(tree.prefix("prefix".as_bytes()).count(), ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "new".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!( + tree.prefix("pre".as_bytes(), None, None).count(), + ITEM_COUNT * 2 + ); + assert_eq!( + tree.prefix("prefix".as_bytes(), None, None).count(), + ITEM_COUNT + ); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "new".as_bytes())); tree.flush_active_memtable(0)?; - assert_eq!(tree.len()?, ITEM_COUNT * 2); - assert_eq!(tree.prefix("pre".as_bytes()).count(), ITEM_COUNT * 2); - assert_eq!(tree.prefix("prefix".as_bytes()).count(), ITEM_COUNT); - assert!(tree.iter().all(|x| &*x.unwrap().1 == "new".as_bytes())); + assert_eq!(tree.len(None, None)?, ITEM_COUNT * 2); + assert_eq!( + tree.prefix("pre".as_bytes(), None, None).count(), + ITEM_COUNT * 2 + ); + assert_eq!( + tree.prefix("prefix".as_bytes(), None, None).count(), + ITEM_COUNT + ); + assert!(tree + .iter(None, None) + .all(|x| &*x.unwrap().1 == "new".as_bytes())); Ok(()) } diff --git a/tests/tree_v2_load_fixture.rs b/tests/tree_v2_load_fixture.rs index e6f3c941..7443389c 100644 --- a/tests/tree_v2_load_fixture.rs +++ b/tests/tree_v2_load_fixture.rs @@ -6,7 +6,7 @@ fn tree_load_v2() -> lsm_tree::Result<()> { let folder = "test_fixture/v2_tree"; let tree = Config::new(folder).open()?; - assert_eq!(5, tree.len()?); + assert_eq!(5, tree.len(None, None)?); Ok(()) } diff --git a/tests/tree_weak_delete.rs b/tests/tree_weak_delete.rs index b5474aa8..f07bf92c 100644 --- a/tests/tree_weak_delete.rs +++ b/tests/tree_weak_delete.rs @@ -9,20 +9,20 @@ fn tree_weak_delete_simple() -> lsm_tree::Result<()> { let tree = lsm_tree::Config::new(path).open()?; tree.insert("a", "old", 0); - assert_eq!(1, tree.len()?); - assert!(tree.contains_key("a")?); + assert_eq!(1, tree.len(None, None)?); + assert!(tree.contains_key("a", None)?); tree.remove_weak("a", 1); - assert_eq!(0, tree.len()?); - assert!(!tree.contains_key("a")?); + assert_eq!(0, tree.len(None, None)?); + assert!(!tree.contains_key("a", None)?); tree.insert("a", "new", 2); - assert_eq!(1, tree.len()?); - assert!(tree.contains_key("a")?); + assert_eq!(1, tree.len(None, None)?); + assert!(tree.contains_key("a", None)?); tree.remove_weak("a", 3); - assert_eq!(0, tree.len()?); - assert!(!tree.contains_key("a")?); + assert_eq!(0, tree.len(None, None)?); + assert!(!tree.contains_key("a", None)?); Ok(()) } @@ -35,14 +35,14 @@ fn tree_weak_delete_flush() -> lsm_tree::Result<()> { let tree = lsm_tree::Config::new(path).open()?; tree.insert("a", "old", 0); - assert_eq!(1, tree.len()?); + assert_eq!(1, tree.len(None, None)?); tree.remove_weak("a", 1); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); tree.flush_active_memtable(0)?; assert_eq!(1, tree.segment_count()); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); Ok(()) } @@ -55,16 +55,16 @@ fn tree_weak_delete_semi_flush() -> lsm_tree::Result<()> { let tree = lsm_tree::Config::new(path).open()?; tree.insert("a", "old", 0); - assert_eq!(1, tree.len()?); + assert_eq!(1, tree.len(None, None)?); tree.flush_active_memtable(0)?; assert_eq!(1, tree.segment_count()); tree.remove_weak("a", 1); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); tree.flush_active_memtable(0)?; assert_eq!(2, tree.segment_count()); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); Ok(()) } @@ -77,14 +77,14 @@ fn tree_weak_delete_flush_point_read() -> lsm_tree::Result<()> { let tree = lsm_tree::Config::new(path).open()?; tree.insert("a", "old", 0); - assert!(tree.contains_key("a")?); + assert!(tree.contains_key("a", None)?); tree.remove_weak("a", 1); - assert!(!tree.contains_key("a")?); + assert!(!tree.contains_key("a", None)?); tree.flush_active_memtable(0)?; assert_eq!(1, tree.segment_count()); - assert!(!tree.contains_key("a")?); + assert!(!tree.contains_key("a", None)?); Ok(()) } @@ -97,16 +97,16 @@ fn tree_weak_delete_semi_flush_point_read() -> lsm_tree::Result<()> { let tree = lsm_tree::Config::new(path).open()?; tree.insert("a", "old", 0); - assert!(tree.contains_key("a")?); + assert!(tree.contains_key("a", None)?); tree.flush_active_memtable(0)?; assert_eq!(1, tree.segment_count()); tree.remove_weak("a", 1); - assert!(!tree.contains_key("a")?); + assert!(!tree.contains_key("a", None)?); tree.flush_active_memtable(0)?; assert_eq!(2, tree.segment_count()); - assert!(!tree.contains_key("a")?); + assert!(!tree.contains_key("a", None)?); Ok(()) } @@ -119,13 +119,13 @@ fn tree_weak_delete_resurrection() -> lsm_tree::Result<()> { let tree = lsm_tree::Config::new(path).open()?; tree.insert("a", "old", 0); - assert_eq!(1, tree.len()?); + assert_eq!(1, tree.len(None, None)?); tree.insert("a", "new", 1); - assert_eq!(1, tree.len()?); + assert_eq!(1, tree.len(None, None)?); tree.remove_weak("a", 2); - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); Ok(()) } diff --git a/tests/tree_weak_delete_eviction.rs b/tests/tree_weak_delete_eviction.rs index e2cff33d..ddd0507f 100644 --- a/tests/tree_weak_delete_eviction.rs +++ b/tests/tree_weak_delete_eviction.rs @@ -16,7 +16,7 @@ fn tree_weak_remove_flush_eviction() -> lsm_tree::Result<()> { tree.remove_weak(c, idx as SeqNo + 1000); } - assert_eq!(0, tree.len()?); + assert_eq!(0, tree.len(None, None)?); tree.flush_active_memtable(1_100)?; diff --git a/tests/tree_weak_delete_queue.rs b/tests/tree_weak_delete_queue.rs index 58dc74f3..162b25de 100644 --- a/tests/tree_weak_delete_queue.rs +++ b/tests/tree_weak_delete_queue.rs @@ -13,22 +13,22 @@ fn tree_weak_delete_queue() -> lsm_tree::Result<()> { tree.insert("c", "c", 0); tree.insert("d", "d", 0); tree.insert("e", "e", 0); - assert_eq!(b"a", &*tree.first_key_value().unwrap().unwrap().0); + assert_eq!(b"a", &*tree.first_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("a", 1); - assert_eq!(b"b", &*tree.first_key_value().unwrap().unwrap().0); + assert_eq!(b"b", &*tree.first_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("b", 1); - assert_eq!(b"c", &*tree.first_key_value().unwrap().unwrap().0); + assert_eq!(b"c", &*tree.first_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("c", 1); - assert_eq!(b"d", &*tree.first_key_value().unwrap().unwrap().0); + assert_eq!(b"d", &*tree.first_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("d", 1); - assert_eq!(b"e", &*tree.first_key_value().unwrap().unwrap().0); + assert_eq!(b"e", &*tree.first_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("e", 1); - assert!(tree.is_empty()?); + assert!(tree.is_empty(None, None)?); Ok(()) } @@ -45,22 +45,22 @@ fn tree_weak_delete_queue_reverse() -> lsm_tree::Result<()> { tree.insert("c", "c", 0); tree.insert("d", "d", 0); tree.insert("e", "e", 0); - assert_eq!(b"e", &*tree.last_key_value().unwrap().unwrap().0); + assert_eq!(b"e", &*tree.last_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("e", 1); - assert_eq!(b"d", &*tree.last_key_value().unwrap().unwrap().0); + assert_eq!(b"d", &*tree.last_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("d", 1); - assert_eq!(b"c", &*tree.last_key_value().unwrap().unwrap().0); + assert_eq!(b"c", &*tree.last_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("c", 1); - assert_eq!(b"b", &*tree.last_key_value().unwrap().unwrap().0); + assert_eq!(b"b", &*tree.last_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("b", 1); - assert_eq!(b"a", &*tree.last_key_value().unwrap().unwrap().0); + assert_eq!(b"a", &*tree.last_key_value(None, None).unwrap().unwrap().0); tree.remove_weak("a", 1); - assert!(tree.is_empty()?); + assert!(tree.is_empty(None, None)?); Ok(()) } From d52639601ccf1a53f343db4469d4f3b9b27f6525 Mon Sep 17 00:00:00 2001 From: marvin-j97 Date: Sat, 11 Jan 2025 01:29:33 +0100 Subject: [PATCH 2/3] fix tests --- tests/blob_simple.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/blob_simple.rs b/tests/blob_simple.rs index cea117fc..ab1b6dfe 100644 --- a/tests/blob_simple.rs +++ b/tests/blob_simple.rs @@ -63,30 +63,30 @@ fn blob_tree_simple_compressed() -> lsm_tree::Result<()> { let big_value = b"neptune!".repeat(128_000); - assert!(tree.get("big")?.is_none()); + assert!(tree.get("big", None)?.is_none()); tree.insert("big", &big_value, 0); tree.insert("smol", "small value", 0); - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, big_value); tree.flush_active_memtable(0)?; - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, big_value); - let value = tree.get("smol")?.expect("should exist"); + let value = tree.get("smol", None)?.expect("should exist"); assert_eq!(&*value, b"small value"); let new_big_value = b"winter!".repeat(128_000); tree.insert("big", &new_big_value, 1); - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, new_big_value); tree.flush_active_memtable(0)?; - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, new_big_value); Ok(()) @@ -104,30 +104,30 @@ fn blob_tree_simple_compressed_2() -> lsm_tree::Result<()> { let big_value = b"neptune!".repeat(128_000); - assert!(tree.get("big")?.is_none()); + assert!(tree.get("big", None)?.is_none()); tree.insert("big", &big_value, 0); tree.insert("smol", "small value", 0); - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, big_value); tree.flush_active_memtable(0)?; - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, big_value); - let value = tree.get("smol")?.expect("should exist"); + let value = tree.get("smol", None)?.expect("should exist"); assert_eq!(&*value, b"small value"); let new_big_value = b"winter!".repeat(128_000); tree.insert("big", &new_big_value, 1); - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, new_big_value); tree.flush_active_memtable(0)?; - let value = tree.get("big")?.expect("should exist"); + let value = tree.get("big", None)?.expect("should exist"); assert_eq!(&*value, new_big_value); Ok(()) From 582cefb4b23d7138eeb6c1b5cf8e1ef39c2e3fd0 Mon Sep 17 00:00:00 2001 From: marvin-j97 Date: Sat, 11 Jan 2025 01:29:49 +0100 Subject: [PATCH 3/3] log flush duration --- src/compaction/worker.rs | 4 ++-- src/tree/mod.rs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/compaction/worker.rs b/src/compaction/worker.rs index a45aedf7..564afb20 100644 --- a/src/compaction/worker.rs +++ b/src/compaction/worker.rs @@ -339,8 +339,8 @@ fn merge_segments( }; log::debug!( - "Compacted in {}ms ({} segments created)", - start.elapsed().as_millis(), + "Compacted in {:?} ({} segments created)", + start.elapsed(), writer_results.len(), ); diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 76d1b932..b885eb4d 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -127,6 +127,8 @@ impl AbstractTree for Tree { segment::writer::{Options, Writer}, }; + let start = std::time::Instant::now(); + let folder = self.config.path.join(SEGMENTS_FOLDER); log::debug!("writing segment to {folder:?}"); @@ -158,7 +160,11 @@ impl AbstractTree for Tree { segment_writer.write(item?)?; } - self.consume_writer(segment_id, segment_writer) + let result = self.consume_writer(segment_id, segment_writer)?; + + log::debug!("Flushed memtable {segment_id:?} in {:?}", start.elapsed()); + + Ok(result) } fn register_segments(&self, segments: &[Segment]) -> crate::Result<()> {