pub struct LsmConfig { /* private fields */ }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
impl LsmConfig
Sourcepub fn new() -> Self
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());Sourcepub fn memtable_capacity(self, bytes: usize) -> Self
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);Sourcepub fn memtable_capacity_bytes(&self) -> usize
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,
);Sourcepub fn compaction_trigger(self, runs: usize) -> Self
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);Sourcepub fn compaction_trigger_runs(&self) -> usize
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,
);Sourcepub fn block_cache_capacity(self, bytes: usize) -> Self
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);Sourcepub fn block_cache_capacity_bytes(&self) -> usize
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 Default for LsmConfig
impl Default for LsmConfig
Source§fn default() -> Self
fn default() -> Self
The default configuration: a DEFAULT_MEMTABLE_CAPACITY write buffer
and a DEFAULT_COMPACTION_TRIGGER run threshold.