pub struct LSMTree<K, V> { /* private fields */ }
Expand description
LSMTree manages a tree of layers to provide a key/value store. Each layer contains deltas on the preceding layer. The top layer is an in-memory mutable layer. Layers can be compacted to form a new combined layer.
Implementations§
Source§impl<'tree, K: MergeableKey, V: Value> LSMTree<K, V>
impl<'tree, K: MergeableKey, V: Value> LSMTree<K, V>
Sourcepub fn new(merge_fn: MergeFn<K, V>, cache: Box<dyn ObjectCache<K, V>>) -> Self
pub fn new(merge_fn: MergeFn<K, V>, cache: Box<dyn ObjectCache<K, V>>) -> Self
Creates a new empty tree.
Sourcepub async fn open(
merge_fn: MergeFn<K, V>,
handles: impl IntoIterator<Item = impl ReadObjectHandle + 'static>,
cache: Box<dyn ObjectCache<K, V>>,
) -> Result<Self, Error>
pub async fn open( merge_fn: MergeFn<K, V>, handles: impl IntoIterator<Item = impl ReadObjectHandle + 'static>, cache: Box<dyn ObjectCache<K, V>>, ) -> Result<Self, Error>
Opens an existing tree from the provided handles to the layer objects.
Sourcepub fn set_layers(&self, layers: Vec<Arc<dyn Layer<K, V>>>)
pub fn set_layers(&self, layers: Vec<Arc<dyn Layer<K, V>>>)
Replaces the immutable layers.
Sourcepub async fn append_layers(
&self,
handles: impl IntoIterator<Item = impl ReadObjectHandle + 'static>,
) -> Result<(), Error>
pub async fn append_layers( &self, handles: impl IntoIterator<Item = impl ReadObjectHandle + 'static>, ) -> Result<(), Error>
Appends to the given layers at the end i.e. they should be base layers. This is supposed to be used after replay when we are opening a tree and we have discovered the base layers.
Sourcepub fn reset_immutable_layers(&self)
pub fn reset_immutable_layers(&self)
Resets the immutable layers.
Sourcepub async fn compact_with_iterator<W: WriteBytes + Send>(
&self,
iterator: impl LayerIterator<K, V>,
num_items: usize,
writer: W,
block_size: u64,
) -> Result<(), Error>
pub async fn compact_with_iterator<W: WriteBytes + Send>( &self, iterator: impl LayerIterator<K, V>, num_items: usize, writer: W, block_size: u64, ) -> Result<(), Error>
Writes the items yielded by the iterator into the supplied object.
Sourcepub fn empty_layer_set(&self) -> LayerSet<K, V>
pub fn empty_layer_set(&self) -> LayerSet<K, V>
Returns an empty layer-set for this tree.
Sourcepub fn add_all_layers_to_layer_set(&self, layer_set: &mut LayerSet<K, V>)
pub fn add_all_layers_to_layer_set(&self, layer_set: &mut LayerSet<K, V>)
Adds all the layers (including the mutable layer) to layer_set
.
Sourcepub fn layer_set(&self) -> LayerSet<K, V>
pub fn layer_set(&self) -> LayerSet<K, V>
Returns a clone of the current set of layers (including the mutable layer), after which one can get an iterator.
Sourcepub fn immutable_layer_set(&self) -> LayerSet<K, V>
pub fn immutable_layer_set(&self) -> LayerSet<K, V>
Returns the current set of immutable layers after which one can get an iterator (for e.g. compacting). Since these layers are immutable, getting an iterator should not block anything else.
Sourcepub fn insert(&self, item: Item<K, V>) -> Result<(), Error>
pub fn insert(&self, item: Item<K, V>) -> Result<(), Error>
Inserts an item into the mutable layer. Returns error if item already exists.
Sourcepub fn replace_or_insert(&self, item: Item<K, V>)
pub fn replace_or_insert(&self, item: Item<K, V>)
Replaces or inserts an item into the mutable layer.
Sourcepub fn merge_into(&self, item: Item<K, V>, lower_bound: &K)
pub fn merge_into(&self, item: Item<K, V>, lower_bound: &K)
Merges the given item into the mutable layer.
Sourcepub async fn find(&self, search_key: &K) -> Result<Option<Item<K, V>>, Error>where
K: Eq,
pub async fn find(&self, search_key: &K) -> Result<Option<Item<K, V>>, Error>where
K: Eq,
Searches for an exact match for the given key. If the value is equal to
Value::DELETED_MARKER
the item is considered missing and will not be returned.
pub fn mutable_layer(&self) -> Arc<SkipListLayer<K, V>>
Sourcepub fn set_mutation_callback(&self, mutation_callback: MutationCallback<K, V>)
pub fn set_mutation_callback(&self, mutation_callback: MutationCallback<K, V>)
Sets a mutation callback which is a callback that is triggered whenever any mutations are applied to the tree. This might be useful for tests that want to record the precise sequence of mutations that are applied to the tree.
Sourcepub fn get_earliest_version(&self) -> Version
pub fn get_earliest_version(&self) -> Version
Returns the earliest version used by a layer in the tree.
Sourcepub fn new_mutable_layer() -> Arc<SkipListLayer<K, V>>
pub fn new_mutable_layer() -> Arc<SkipListLayer<K, V>>
Returns a new mutable layer.
Sourcepub fn set_mutable_layer(&self, layer: Arc<SkipListLayer<K, V>>)
pub fn set_mutable_layer(&self, layer: Arc<SkipListLayer<K, V>>)
Replaces the mutable layer.
Sourcepub fn record_inspect_data(&self, root: &Node)
pub fn record_inspect_data(&self, root: &Node)
Records inspect data for the LSM tree into node
. Called lazily when inspect is queried.
Auto Trait Implementations§
impl<K, V> !Freeze for LSMTree<K, V>
impl<K, V> !RefUnwindSafe for LSMTree<K, V>
impl<K, V> Send for LSMTree<K, V>
impl<K, V> Sync for LSMTree<K, V>
impl<K, V> Unpin for LSMTree<K, V>
impl<K, V> !UnwindSafe for LSMTree<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more