Struct LSMTree

Source
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>

Source

pub fn new(merge_fn: MergeFn<K, V>, cache: Box<dyn ObjectCache<K, V>>) -> Self

Creates a new empty tree.

Source

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.

Source

pub fn set_layers(&self, layers: Vec<Arc<dyn Layer<K, V>>>)

Replaces the immutable layers.

Source

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.

Source

pub fn reset_immutable_layers(&self)

Resets the immutable layers.

Source

pub fn seal(&self)

Seals the current mutable layer and creates a new one.

Source

pub fn reset(&self)

Resets the tree to an empty state.

Source

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.

Source

pub fn empty_layer_set(&self) -> LayerSet<K, V>

Returns an empty layer-set for this tree.

Source

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.

Source

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.

Source

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.

Source

pub fn insert(&self, item: Item<K, V>) -> Result<(), Error>

Inserts an item into the mutable layer. Returns error if item already exists.

Source

pub fn replace_or_insert(&self, item: Item<K, V>)

Replaces or inserts an item into the mutable layer.

Source

pub fn merge_into(&self, item: Item<K, V>, lower_bound: &K)

Merges the given item into the mutable layer.

Source

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.

Source

pub fn mutable_layer(&self) -> Arc<SkipListLayer<K, V>>

Source

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.

Source

pub fn get_earliest_version(&self) -> Version

Returns the earliest version used by a layer in the tree.

Source

pub fn new_mutable_layer() -> Arc<SkipListLayer<K, V>>

Returns a new mutable layer.

Source

pub fn set_mutable_layer(&self, layer: Arc<SkipListLayer<K, V>>)

Replaces the mutable layer.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V