Struct lsm_tree::Config

source ·
pub struct Config {
    pub path: PathBuf,
    pub block_size: u32,
    pub block_cache: Arc<BlockCache>,
    pub max_memtable_size: u32,
    pub level_count: u8,
    pub level_ratio: u8,
    pub flush_threads: u8,
    pub fsync_ms: Option<usize>,
    /* private fields */
}
Expand description

Tree configuration

Fields§

§path: PathBuf

Folder path

§block_size: u32

Block size of data and index blocks

§block_cache: Arc<BlockCache>

Block cache

§max_memtable_size: u32

Maximum size in bytes of the write buffer

§level_count: u8

Amount of levels of the LSM tree (depth of tree)

§level_ratio: u8

Size ratio between levels of the LSM tree (a.k.a fanout, growth rate).

This is the exponential growth of the from one level to the next

A level target size is: max_memtable_size * level_ratio.pow(#level + 1)

§flush_threads: u8

Maximum amount of concurrent flush threads

§fsync_ms: Option<usize>

Starts a thread that will periodically fsync the journals for durability

Implementations§

source§

impl Config

source

pub fn new<P: AsRef<Path>>(path: P) -> Self

Initializes a new config

source

pub fn fsync_ms(self, ms: Option<usize>) -> Self

Starts a thread that will periodically fsync the journal for durability.

That means in case of a fatal crash (not proper unwind) at most the last ms of data may be lost. Without fsyncing, your data is at the mercy of your operating system’s syncing logic. If you want to make sure a write is definitely durable, call Tree::flush manually after writing. Flushing after every write has dramatic performance implications (100x-1000x slower for SSDs). Even when disabled, the tree will always try to fsync when it is being dropped.

Defaults to 1 second.

Panics

Panics if ms is below 100.

source

pub fn flush_threads(self, count: u8) -> Self

Maximum amount of concurrent flush threads.

You may want to increase this the more CPU cores you have.

Defaults to 4.

Panics

Panics if count is 0.

source

pub fn level_count(self, n: u8) -> Self

Sets the amount of levels of the LSM tree (depth of tree).

Defaults to 7, like LevelDB and RocksDB.

Panics

Panics if n is 0.

source

pub fn level_ratio(self, n: u8) -> Self

Sets the size ratio between levels of the LSM tree (a.k.a. fanout, growth rate).

Defaults to 10.

Panics

Panics if n is less than 2.

source

pub fn max_memtable_size(self, bytes: u32) -> Self

Sets the maximum memtable size.

Defaults to 16 MiB.

source

pub fn block_size(self, block_size: u32) -> Self

Sets the block size.

Defaults to 4 KiB (4096 bytes).

Panics

Panics if the block size is smaller than 1 KiB (1024 bytes).

source

pub fn block_cache(self, block_cache: Arc<BlockCache>) -> Self

Sets the block cache.

You can create a global BlockCache and share it between multiple trees to cap global cache memory usage.

Defaults to a block cache with 16 MiB of capacity per tree.

source

pub fn compaction_strategy( self, strategy: Arc<dyn CompactionStrategy + Send + Sync> ) -> Self

Sets the compaction strategy to use.

Defaults to compaction::Levelled

source

pub fn open(self) -> Result<Tree>

Opens a tree using the config.

Errors

Will return Err if an IO error occurs.

Trait Implementations§

source§

impl Clone for Config

source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Default for Config

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl !UnwindSafe for Config

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

§

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> ToOwned for T
where T: Clone,

§

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

§

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

§

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