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: Option<Box<dyn ObjectCache<K, V>>>,
) -> Self
pub fn new( merge_fn: MergeFn<K, V>, cache: Option<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 LayerObject + 'static>,
cache: Option<Box<dyn ObjectCache<K, V>>>,
) -> Result<Self, Error>
pub async fn open( merge_fn: MergeFn<K, V>, handles: impl IntoIterator<Item = impl LayerObject + 'static>, cache: Option<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,
store: &Arc<ObjectStore>,
object_ids: impl IntoIterator<Item = u64>,
crypt: Option<Arc<dyn Crypt>>,
) -> Result<u64, Error>
pub async fn append_layers( &self, store: &Arc<ObjectStore>, object_ids: impl IntoIterator<Item = u64>, crypt: Option<Arc<dyn Crypt>>, ) -> Result<u64, Error>
Opens layers for object_ids from store and appends them to the end of the tree (i.e. as
base layers). This is supposed to be used after replay when we are opening a tree and we
have discovered the base layers.
Returns the sum of the sizes in bytes of all appended layers.
Sourcepub fn append_open_layers(&self, layers: Vec<Arc<dyn Layer<K, V>>>)
pub fn append_open_layers(&self, layers: Vec<Arc<dyn Layer<K, V>>>)
Appends already-opened layers to the end of the tree.
Sourcepub fn reset_immutable_layers(&self)
pub fn reset_immutable_layers(&self)
Resets the immutable layers.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clears all in-memory caches (object cache and persistent layer chunk caches) for this tree.
pub fn cache_len(&self) -> usize
pub fn report_compaction_metrics( &self, bytes_written: u64, duration: Duration, layer_count: usize, )
pub fn compaction_bytes_written(&self) -> u64
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_map<R, F>(
&self,
search_key: &K,
f: F,
) -> Result<Option<R>, Error>
pub async fn find_map<R, F>( &self, search_key: &K, f: F, ) -> Result<Option<R>, Error>
Searches for an exact match for the given key, applying f to the found ItemRef.
If the item does not exist or has a value equal to Value::DELETED_MARKER, returns
Ok(None).
Range keys (FuzzyHash::is_range_key) are not supported.
Sourcepub fn find(
&self,
search_key: &K,
) -> impl Future<Output = Result<Option<Item<K, V>>, Error>> + Sendwhere
K: Eq,
pub fn find(
&self,
search_key: &K,
) -> impl Future<Output = Result<Option<Item<K, V>>, Error>> + Sendwhere
K: Eq,
Searches for an exact match for the given key. If the item does not exist or has a value
equal to Value::DELETED_MARKER, returns Ok(None).
Range keys (FuzzyHash::is_range_key) are not supported.
Sourcepub fn find_value(
&self,
search_key: &K,
) -> impl Future<Output = Result<Option<V>, Error>> + Sendwhere
K: Eq,
pub fn find_value(
&self,
search_key: &K,
) -> impl Future<Output = Result<Option<V>, Error>> + Sendwhere
K: Eq,
Searches for an exact match for the given key, returning only the value. If the item does
not exist or has a value equal to Value::DELETED_MARKER, returns Ok(None).
Range keys (FuzzyHash::is_range_key) are not supported.
Sourcepub async fn exists(&self, search_key: &K) -> Result<bool, Error>where
K: Eq,
pub async fn exists(&self, search_key: &K) -> Result<bool, Error>where
K: Eq,
Returns true if an exact match exists for the given key and is not deleted.
Range keys (FuzzyHash::is_range_key) are not supported.
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> !UnwindSafe 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> UnsafeUnpin 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
§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
§impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
fn fidl_into_native(self) -> Box<N>
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