pub enum AnyTree {
Standard(Tree),
Blob(BlobTree),
}Variants§
Standard(Tree)
Standard LSM-tree, see Tree
Blob(BlobTree)
Key-value separated LSM-tree, see BlobTree
Implementations§
Trait Implementations§
Source§impl AbstractTree for AnyTree
impl AbstractTree for AnyTree
Source§fn table_file_cache_size(&self) -> usize
fn table_file_cache_size(&self) -> usize
Returns the number of cached table file descriptors.
Source§fn flush(
&self,
__enum_dispatch_arg_0: &MutexGuard<'_, ()>,
__enum_dispatch_arg_1: SeqNo,
) -> Result<Option<u64>>
fn flush( &self, __enum_dispatch_arg_0: &MutexGuard<'_, ()>, __enum_dispatch_arg_1: SeqNo, ) -> Result<Option<u64>>
Synchronously flushes pending sealed memtables to tables.
Returns the sum of flushed memtable sizes that were flushed.
The function may not return a result, if nothing was flushed.
§Errors
Will return Err if an IO error occurs.
Source§fn iter(
&self,
__enum_dispatch_arg_0: SeqNo,
__enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>,
) -> Box<dyn DoubleEndedIterator<Item = IterGuardImpl> + Send + 'static>
fn iter( &self, __enum_dispatch_arg_0: SeqNo, __enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>, ) -> Box<dyn DoubleEndedIterator<Item = IterGuardImpl> + Send + 'static>
Returns an iterator that scans through the entire tree.
Avoid using this function, or limit it as otherwise it may scan a lot of items.
Source§fn prefix<K: AsRef<[u8]>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: SeqNo,
__enum_dispatch_arg_2: Option<(Arc<Memtable>, SeqNo)>,
) -> Box<dyn DoubleEndedIterator<Item = IterGuardImpl> + Send + 'static>
fn prefix<K: AsRef<[u8]>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: SeqNo, __enum_dispatch_arg_2: Option<(Arc<Memtable>, SeqNo)>, ) -> Box<dyn DoubleEndedIterator<Item = IterGuardImpl> + Send + 'static>
Returns an iterator over a prefixed set of items.
Avoid using an empty prefix as it may scan a lot of items (unless limited).
Source§fn range<K: AsRef<[u8]>, R: RangeBounds<K>>(
&self,
__enum_dispatch_arg_0: R,
__enum_dispatch_arg_1: SeqNo,
__enum_dispatch_arg_2: Option<(Arc<Memtable>, SeqNo)>,
) -> Box<dyn DoubleEndedIterator<Item = IterGuardImpl> + Send + 'static>
fn range<K: AsRef<[u8]>, R: RangeBounds<K>>( &self, __enum_dispatch_arg_0: R, __enum_dispatch_arg_1: SeqNo, __enum_dispatch_arg_2: Option<(Arc<Memtable>, SeqNo)>, ) -> Box<dyn DoubleEndedIterator<Item = IterGuardImpl> + Send + '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).
Source§fn tombstone_count(&self) -> u64
fn tombstone_count(&self) -> u64
Returns the approximate number of tombstones in the tree.
Source§fn weak_tombstone_count(&self) -> u64
fn weak_tombstone_count(&self) -> u64
Returns the approximate number of weak tombstones (single deletes) in the tree.
Source§fn weak_tombstone_reclaimable_count(&self) -> u64
fn weak_tombstone_reclaimable_count(&self) -> u64
Returns the approximate number of values reclaimable once weak tombstones can be GC’d.
Source§fn drop_range<K: AsRef<[u8]>, R: RangeBounds<K>>(
&self,
__enum_dispatch_arg_0: R,
) -> Result<()>
fn drop_range<K: AsRef<[u8]>, R: RangeBounds<K>>( &self, __enum_dispatch_arg_0: R, ) -> Result<()>
Drops tables that are fully contained in a given range.
Accepts any RangeBounds, including unbounded or exclusive endpoints.
If the normalized lower bound is greater than the upper bound, the
method returns without performing any work.
§Errors
Will return Err only if an IO error occurs.
Source§fn clear(&self) -> Result<()>
fn clear(&self) -> Result<()>
Drops all tables and clears all memtables atomically.
§Errors
Will return Err only if an IO error occurs.
Source§fn major_compact(
&self,
__enum_dispatch_arg_0: u64,
__enum_dispatch_arg_1: SeqNo,
) -> Result<CompactionResult>
fn major_compact( &self, __enum_dispatch_arg_0: u64, __enum_dispatch_arg_1: SeqNo, ) -> Result<CompactionResult>
Performs major compaction, blocking the caller until it’s done.
Returns a crate::compaction::CompactionResult describing what action was taken.
§Errors
Will return Err if an IO error occurs.
Source§fn stale_blob_bytes(&self) -> u64
fn stale_blob_bytes(&self) -> u64
Returns the disk space used by stale blobs.
Source§fn filter_size(&self) -> u64
fn filter_size(&self) -> u64
Gets the space usage of all filters in the tree.
May not correspond to the actual memory size because filter blocks may be paged out.
Source§fn pinned_filter_size(&self) -> usize
fn pinned_filter_size(&self) -> usize
Gets the memory usage of all pinned filters in the tree.
Source§fn pinned_block_index_size(&self) -> usize
fn pinned_block_index_size(&self) -> usize
Gets the memory usage of all pinned index blocks in the tree.
Source§fn version_free_list_len(&self) -> usize
fn version_free_list_len(&self) -> usize
Gets the length of the version free list.
Source§fn get_flush_lock(&self) -> MutexGuard<'_, ()>
fn get_flush_lock(&self) -> MutexGuard<'_, ()>
Acquires the flush lock which is required to call Tree::flush.
Source§fn flush_to_tables(
&self,
__enum_dispatch_arg_0: impl Iterator<Item = Result<InternalValue>>,
) -> Result<Option<(Vec<Table>, Option<Vec<BlobFile>>)>>
fn flush_to_tables( &self, __enum_dispatch_arg_0: impl Iterator<Item = Result<InternalValue>>, ) -> Result<Option<(Vec<Table>, Option<Vec<BlobFile>>)>>
Synchronously flushes a memtable to a table.
This method will not make the table immediately available,
use AbstractTree::register_tables for that.
§Errors
Will return Err if an IO error occurs.
Source§fn register_tables(
&self,
__enum_dispatch_arg_0: &[Table],
__enum_dispatch_arg_1: Option<&[BlobFile]>,
__enum_dispatch_arg_2: Option<FragmentationMap>,
__enum_dispatch_arg_3: &[MemtableId],
__enum_dispatch_arg_4: SeqNo,
) -> Result<()>
fn register_tables( &self, __enum_dispatch_arg_0: &[Table], __enum_dispatch_arg_1: Option<&[BlobFile]>, __enum_dispatch_arg_2: Option<FragmentationMap>, __enum_dispatch_arg_3: &[MemtableId], __enum_dispatch_arg_4: SeqNo, ) -> Result<()>
Atomically registers flushed tables into the tree, removing their associated sealed memtables.
§Errors
Will return Err if an IO error occurs.
Source§fn clear_active_memtable(&self)
fn clear_active_memtable(&self)
Clears the active memtable atomically.
Source§fn sealed_memtable_count(&self) -> usize
fn sealed_memtable_count(&self) -> usize
Returns the number of sealed memtables.
Source§fn compact(
&self,
__enum_dispatch_arg_0: Arc<dyn CompactionStrategy>,
__enum_dispatch_arg_1: SeqNo,
) -> Result<CompactionResult>
fn compact( &self, __enum_dispatch_arg_0: Arc<dyn CompactionStrategy>, __enum_dispatch_arg_1: SeqNo, ) -> Result<CompactionResult>
Performs compaction on the tree’s levels, blocking the caller until it’s done.
Returns a crate::compaction::CompactionResult describing what action was taken.
§Errors
Will return Err if an IO error occurs.
Source§fn get_next_table_id(&self) -> TableId
fn get_next_table_id(&self) -> TableId
Returns the next table’s ID.
Source§fn tree_config(&self) -> &Config
fn tree_config(&self) -> &Config
Returns the tree config.
Source§fn get_highest_seqno(&self) -> Option<SeqNo>
fn get_highest_seqno(&self) -> Option<SeqNo>
Returns the highest sequence number.
Source§fn active_memtable(&self) -> Arc<Memtable>
fn active_memtable(&self) -> Arc<Memtable>
Returns the active memtable.
Source§fn table_count(&self) -> usize
fn table_count(&self) -> usize
Returns the number of tables currently in the tree.
Source§fn level_table_count(&self, __enum_dispatch_arg_0: usize) -> Option<usize>
fn level_table_count(&self, __enum_dispatch_arg_0: usize) -> Option<usize>
Returns the number of tables in levels[idx].
Returns None if the level does not exist (if idx >= 7).
Source§fn l0_run_count(&self) -> usize
fn l0_run_count(&self) -> usize
Returns the number of disjoint runs in L0.
Can be used to determine whether to write stall.
Source§fn blob_file_count(&self) -> usize
fn blob_file_count(&self) -> usize
Returns the number of blob files currently in the tree.
Source§fn approximate_len(&self) -> usize
fn approximate_len(&self) -> usize
Approximates the number of items in the tree.
Source§fn disk_space(&self) -> u64
fn disk_space(&self) -> u64
Returns the disk space usage.
Source§fn get_highest_memtable_seqno(&self) -> Option<SeqNo>
fn get_highest_memtable_seqno(&self) -> Option<SeqNo>
Returns the highest sequence number of the active memtable.
Source§fn get_highest_persisted_seqno(&self) -> Option<SeqNo>
fn get_highest_persisted_seqno(&self) -> Option<SeqNo>
Returns the highest sequence number that is flushed to disk.
Source§fn len(
&self,
__enum_dispatch_arg_0: SeqNo,
__enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>,
) -> Result<usize>
fn len( &self, __enum_dispatch_arg_0: SeqNo, __enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>, ) -> Result<usize>
Scans the entire tree, returning the number of items.
§Caution
This operation scans the entire tree: O(n) complexity!
Never, under any circumstances, use .len() == 0 to check
if the tree is empty, use Tree::is_empty instead.
§Examples
use lsm_tree::{AbstractTree, Config, Tree};
let folder = tempfile::tempdir()?;
let tree = Config::new(folder, Default::default(), Default::default()).open()?;
assert_eq!(tree.len(0, None)?, 0);
tree.insert("1", "abc", 0);
tree.insert("3", "abc", 1);
tree.insert("5", "abc", 2);
assert_eq!(tree.len(3, None)?, 3);§Errors
Will return Err if an IO error occurs.
Source§fn is_empty(
&self,
__enum_dispatch_arg_0: SeqNo,
__enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>,
) -> Result<bool>
fn is_empty( &self, __enum_dispatch_arg_0: SeqNo, __enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>, ) -> Result<bool>
Returns true if the tree is empty.
This operation has O(log N) complexity.
§Examples
use lsm_tree::{AbstractTree, Config, Tree};
let tree = Config::new(folder, Default::default(), Default::default()).open()?;
assert!(tree.is_empty(0, None)?);
tree.insert("a", "abc", 0);
assert!(!tree.is_empty(1, None)?);§Errors
Will return Err if an IO error occurs.
Source§fn first_key_value(
&self,
__enum_dispatch_arg_0: SeqNo,
__enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>,
) -> Option<IterGuardImpl>
fn first_key_value( &self, __enum_dispatch_arg_0: SeqNo, __enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>, ) -> Option<IterGuardImpl>
Returns the first key-value pair in the tree. The key in this pair is the minimum key in the tree.
§Examples
let tree = Config::new(folder, Default::default(), Default::default()).open()?;
tree.insert("1", "abc", 0);
tree.insert("3", "abc", 1);
tree.insert("5", "abc", 2);
let key = tree.first_key_value(3, None).expect("item should exist").key()?;
assert_eq!(&*key, "1".as_bytes());§Errors
Will return Err if an IO error occurs.
Source§fn last_key_value(
&self,
__enum_dispatch_arg_0: SeqNo,
__enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>,
) -> Option<IterGuardImpl>
fn last_key_value( &self, __enum_dispatch_arg_0: SeqNo, __enum_dispatch_arg_1: Option<(Arc<Memtable>, SeqNo)>, ) -> Option<IterGuardImpl>
Returns the last key-value pair in the tree. The key in this pair is the maximum key in the tree.
§Examples
tree.insert("1", "abc", 0);
tree.insert("3", "abc", 1);
tree.insert("5", "abc", 2);
let key = tree.last_key_value(3, None).expect("item should exist").key()?;
assert_eq!(&*key, "5".as_bytes());§Errors
Will return Err if an IO error occurs.
Source§fn size_of<K: AsRef<[u8]>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: SeqNo,
) -> Result<Option<u32>>
fn size_of<K: AsRef<[u8]>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: SeqNo, ) -> Result<Option<u32>>
Returns the size of a value if it exists.
§Examples
use lsm_tree::{AbstractTree, Config, Tree};
let tree = Config::new(folder, Default::default(), Default::default()).open()?;
tree.insert("a", "my_value", 0);
let size = tree.size_of("a", 1)?.unwrap_or_default();
assert_eq!("my_value".len() as u32, size);
let size = tree.size_of("b", 1)?.unwrap_or_default();
assert_eq!(0, size);§Errors
Will return Err if an IO error occurs.
Source§fn get<K: AsRef<[u8]>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: SeqNo,
) -> Result<Option<UserValue>>
fn get<K: AsRef<[u8]>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: SeqNo, ) -> Result<Option<UserValue>>
Retrieves an item from the tree.
§Examples
use lsm_tree::{AbstractTree, Config, Tree};
let tree = Config::new(folder, Default::default(), Default::default()).open()?;
tree.insert("a", "my_value", 0);
let item = tree.get("a", 1)?;
assert_eq!(Some("my_value".as_bytes().into()), item);§Errors
Will return Err if an IO error occurs.
Source§fn contains_key<K: AsRef<[u8]>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: SeqNo,
) -> Result<bool>
fn contains_key<K: AsRef<[u8]>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: SeqNo, ) -> Result<bool>
Source§fn contains_prefix<K: AsRef<[u8]>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: SeqNo,
__enum_dispatch_arg_2: Option<(Arc<Memtable>, SeqNo)>,
) -> Result<bool>
fn contains_prefix<K: AsRef<[u8]>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: SeqNo, __enum_dispatch_arg_2: Option<(Arc<Memtable>, SeqNo)>, ) -> Result<bool>
Returns true if the tree contains any key with the given prefix.
This is a convenience method that checks whether the corresponding
prefix iterator yields at least one item, while surfacing any IO
errors via the Result return type. Implementations may override
this method to provide a more efficient prefix-existence check.
§Examples
use lsm_tree::{AbstractTree, Config, Tree};
let tree = Config::new(folder, Default::default(), Default::default()).open()?;
assert!(!tree.contains_prefix("abc", 0, None)?);
tree.insert("abc:1", "value", 0);
assert!(tree.contains_prefix("abc", 1, None)?);
assert!(!tree.contains_prefix("xyz", 1, None)?);§Errors
Will return Err if an IO error occurs.
Source§fn multi_get<K: AsRef<[u8]>>(
&self,
__enum_dispatch_arg_0: impl IntoIterator<Item = K>,
__enum_dispatch_arg_1: SeqNo,
) -> Result<Vec<Option<UserValue>>>
fn multi_get<K: AsRef<[u8]>>( &self, __enum_dispatch_arg_0: impl IntoIterator<Item = K>, __enum_dispatch_arg_1: SeqNo, ) -> Result<Vec<Option<UserValue>>>
Reads multiple keys from the tree.
Implementations may choose to perform all lookups against a single
version snapshot and acquire the version lock only once, which can be
more efficient than calling AbstractTree::get in a loop. The
default trait implementation, however, is a convenience wrapper that
simply calls AbstractTree::get for each key and therefore does not
guarantee a single-snapshot or single-lock acquisition. Optimized
implementations (such as Tree and BlobTree) provide the
single-snapshot/one-lock behavior.
§Examples
use lsm_tree::{AbstractTree, Config, Tree};
let tree = Config::new(folder, Default::default(), Default::default()).open()?;
tree.insert("a", "value_a", 0);
tree.insert("b", "value_b", 1);
let results = tree.multi_get(["a", "b", "c"], 2)?;
assert_eq!(results[0], Some("value_a".as_bytes().into()));
assert_eq!(results[1], Some("value_b".as_bytes().into()));
assert_eq!(results[2], None);§Errors
Will return Err if an IO error occurs.
Source§fn insert<K: Into<UserKey>, V: Into<UserValue>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: V,
__enum_dispatch_arg_2: SeqNo,
) -> (u64, u64)
fn insert<K: Into<UserKey>, V: Into<UserValue>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: V, __enum_dispatch_arg_2: SeqNo, ) -> (u64, u64)
Inserts a key-value pair into the tree.
If the key already exists, the item will be overwritten.
Returns the added item’s size and new size of the memtable.
§Examples
use lsm_tree::{AbstractTree, Config, Tree};
let tree = Config::new(folder, Default::default(), Default::default()).open()?;
tree.insert("a", "abc", 0);§Errors
Will return Err if an IO error occurs.
Source§fn remove<K: Into<UserKey>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: SeqNo,
) -> (u64, u64)
fn remove<K: Into<UserKey>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: SeqNo, ) -> (u64, u64)
Removes an item from the tree.
Returns the added item’s size and new size of the memtable.
§Examples
tree.insert("a", "abc", 0);
let item = tree.get("a", 1)?.expect("should have item");
assert_eq!("abc".as_bytes(), &*item);
tree.remove("a", 1);
let item = tree.get("a", 2)?;
assert_eq!(None, item);§Errors
Will return Err if an IO error occurs.
Source§fn merge<K: Into<UserKey>, V: Into<UserValue>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: V,
__enum_dispatch_arg_2: SeqNo,
) -> (u64, u64)
fn merge<K: Into<UserKey>, V: Into<UserValue>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: V, __enum_dispatch_arg_2: SeqNo, ) -> (u64, u64)
Writes a merge operand for a key.
The operand is stored as a partial update that will be combined with
other operands and/or a base value via the configured crate::MergeOperator
during reads and compaction.
Returns the added item’s size and new size of the memtable.
§Examples
tree.merge("counter", 1_i64.to_le_bytes(), 0);Source§fn remove_range<K: Into<UserKey>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: K,
__enum_dispatch_arg_2: SeqNo,
) -> u64
fn remove_range<K: Into<UserKey>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: K, __enum_dispatch_arg_2: SeqNo, ) -> u64
Deletes all keys in the range [start, end) by inserting a range tombstone.
This is much more efficient than deleting keys individually when removing a contiguous range of keys.
Returns the approximate size added to the memtable.
Returns 0 if start >= end (invalid interval is silently ignored).
This is a required method on the crate’s sealed tree types.
Source§fn remove_prefix<K: AsRef<[u8]>>(
&self,
__enum_dispatch_arg_0: K,
__enum_dispatch_arg_1: SeqNo,
) -> u64
fn remove_prefix<K: AsRef<[u8]>>( &self, __enum_dispatch_arg_0: K, __enum_dispatch_arg_1: SeqNo, ) -> u64
Deletes all keys with the given prefix by inserting a range tombstone.
This is sugar over AbstractTree::remove_range using prefix bounds.
Returns the approximate size added to the memtable.
Returns 0 for empty prefixes or all-0xFF prefixes (cannot form valid half-open range).