Skip to main content

Leveled

Struct Leveled 

Source
pub struct Leveled { /* private fields */ }
Expand description

Leveled compaction strategy (LCS)

When a level reaches some threshold size, parts of it are merged into overlapping tables in the next level.

Each level Ln for n >= 2 can have up to level_base_size * ratio^(n - 1) tables.

LCS suffers from comparatively high write amplification, but has decent read amplification and great space amplification (~1.1x).

LCS is the recommended compaction strategy to use.

More info here: https://fjall-rs.github.io/post/lsm-leveling/

Implementations§

Source§

impl Strategy

Source

pub fn with_level_ratio_policy(self, policy: Vec<f32>) -> Self

Sets the growth ratio between levels.

Same as set_max_bytes_for_level_multiplier in RocksDB.

Default = [10.0]

Source

pub fn with_l0_threshold(self, threshold: u8) -> Self

Sets the L0 threshold.

When the number of tables in L0 reaches this threshold, they are merged into L1.

Same as level0_file_num_compaction_trigger in RocksDB.

Default = 4

Source

pub fn with_table_target_size(self, bytes: u64) -> Self

Sets the table target size on disk (possibly compressed).

Same as target_file_size_base in RocksDB.

Default = 64 MiB

Source

pub fn with_dynamic_level_bytes(self, enabled: bool) -> Self

Enables dynamic level sizing based on actual data in the last level.

When enabled, level target sizes are computed top-down from the actual size of the last non-empty level, divided by the ratio at each step. This reduces space amplification to ~1.1x while keeping write amplification comparable to static leveling.

Same as level_compaction_dynamic_level_bytes in RocksDB.

Default = false

Source

pub fn with_multi_level(self, enabled: bool) -> Self

Enables multi-level compaction optimization.

When L0→L1 compaction is selected but L1 already exceeds its target size, this option allows compacting L0+L1 directly into L2 in one pass, avoiding the write-then-rewrite cycle that would otherwise occur.

Default = false

Trait Implementations§

Source§

impl Clone for Strategy

Source§

fn clone(&self) -> Strategy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CompactionStrategy for Strategy

Source§

fn get_name(&self) -> &'static str

Gets the compaction strategy name.
Source§

fn pending_compaction_bytes(&self, version: &Version) -> u64

Estimated bytes pending compaction: on-disk data currently sitting above its level’s target size that must eventually be rewritten downward (a RocksDB estimate-pending-compaction-bytes analog). A scheduler / tiering consumer reads it as a compaction-debt signal; 0 means the tree is at or below its target shape. Read more
Source§

fn choose( &self, version: &Version, config: &Config, state: &CompactionState, ) -> Choice

Decides on what to do based on the current state of the LSM-tree’s levels Read more
Source§

impl Default for Strategy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V