Skip to main content

LsmConfig

Struct LsmConfig 

Source
pub struct LsmConfig { /* private fields */ }
Available on crate feature std only.
Expand description

Tuning parameters for an Lsm engine.

Construct with LsmConfig::new (or LsmConfig::default) and refine with the chained setters, then pass to Lsm::open_with.

§Examples

use lsm_db::LsmConfig;

// A 64 KiB write buffer — flushes often, keeps resident memory tiny.
let config = LsmConfig::new().memtable_capacity(64 * 1024);
assert_eq!(config.memtable_capacity_bytes(), 64 * 1024);

Implementations§

Source§

impl LsmConfig

Source

pub fn new() -> Self

Start from the default configuration.

Equivalent to LsmConfig::default; provided so configuration reads as a builder chain.

§Examples
use lsm_db::LsmConfig;
let config = LsmConfig::new();
assert_eq!(config, LsmConfig::default());
Source

pub fn memtable_capacity(self, bytes: usize) -> Self

Set the memtable capacity, in bytes of live key and value data.

When the in-memory write buffer reaches this size, the next write triggers a flush to disk. A capacity of 0 flushes after every write, which is useful in tests but rarely otherwise.

The figure counts key and value bytes only, not per-entry bookkeeping, so peak resident memory is somewhat higher than the configured number.

§Examples
use lsm_db::LsmConfig;
let config = LsmConfig::new().memtable_capacity(1 << 20); // 1 MiB
assert_eq!(config.memtable_capacity_bytes(), 1 << 20);
Source

pub fn memtable_capacity_bytes(&self) -> usize

The configured memtable capacity, in bytes.

§Examples
use lsm_db::LsmConfig;
assert_eq!(
    LsmConfig::default().memtable_capacity_bytes(),
    lsm_db::DEFAULT_MEMTABLE_CAPACITY,
);
Source

pub fn compaction_trigger(self, runs: usize) -> Self

Set the number of on-disk runs that triggers a background compaction.

Reads may consult every run, so this bounds read amplification: the engine keeps at most roughly this many runs before merging them into one in the background. Smaller values keep reads fast at the cost of more compaction work; larger values do the reverse. Values below 2 are treated as 2, since merging a single run is pointless.

§Examples
use lsm_db::LsmConfig;
let config = LsmConfig::new().compaction_trigger(8);
assert_eq!(config.compaction_trigger_runs(), 8);
Source

pub fn compaction_trigger_runs(&self) -> usize

The configured compaction trigger, in number of runs.

§Examples
use lsm_db::LsmConfig;
assert_eq!(
    LsmConfig::default().compaction_trigger_runs(),
    lsm_db::DEFAULT_COMPACTION_TRIGGER,
);
Source

pub fn block_cache_capacity(self, bytes: usize) -> Self

Set the block-cache capacity, in bytes of decoded data blocks.

The cache keeps recently-read run blocks so a repeat point lookup over a hot working set returns with no I/O, checksum, or parse. Set to 0 to disable it (every lookup decodes directly). The capacity is approximate — it is counted in block-sized units — and shared across all of an engine’s runs.

§Examples
use lsm_db::LsmConfig;
// A 32 MiB block cache.
let config = LsmConfig::new().block_cache_capacity(32 * 1024 * 1024);
assert_eq!(config.block_cache_capacity_bytes(), 32 * 1024 * 1024);
// Disable the cache.
assert_eq!(LsmConfig::new().block_cache_capacity(0).block_cache_capacity_bytes(), 0);
Source

pub fn block_cache_capacity_bytes(&self) -> usize

The configured block-cache capacity, in bytes.

§Examples
use lsm_db::LsmConfig;
assert_eq!(
    LsmConfig::default().block_cache_capacity_bytes(),
    lsm_db::DEFAULT_BLOCK_CACHE_CAPACITY,
);

Trait Implementations§

Source§

impl Clone for LsmConfig

Source§

fn clone(&self) -> LsmConfig

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 Debug for LsmConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LsmConfig

Source§

fn default() -> Self

The default configuration: a DEFAULT_MEMTABLE_CAPACITY write buffer and a DEFAULT_COMPACTION_TRIGGER run threshold.

Source§

impl Eq for LsmConfig

Source§

impl PartialEq for LsmConfig

Source§

fn eq(&self, other: &LsmConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for LsmConfig

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<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> 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<E> WithErrorCode<E> for E

Source§

fn with_code(self, code: impl Into<String>) -> CodedError<E>

Attach an error code to an error