Expand description
Embedded LSM-tree storage engine.
Provides keyed point reads, prefix and range scans, MVCC snapshots, block
and file-descriptor caching, and a configurable compaction subsystem. No
write-ahead log — durability is the caller’s responsibility (flush_active_memtable
forces persistence when needed).
§Highlights
- AMQ filter:
BuRR(Bumped Ribbon Retrieval, Walzer & Dillinger 2022) for per-key and per-prefix membership checks. ~30% smaller filter blocks than a same-FPR Bloom filter, or ~10× tighter FPR at the same memory budget. - Compression: pure-Rust zstd (incl. dictionary mode), LZ4, or none — per-table and per-level policy.
- Encryption at rest: AES-256-GCM block encryption with a caller-supplied key.
- Range tombstones:
delete_range/delete_prefix(SST-encoded; the feature was added in disk format V4 and remains supported in the current V5 format — the V5 break extends the block header for per-block Reed- Solomon Page ECC, not the tombstone encoding). - Merge operators: commutative-merge LSM operations with lazy resolution.
- K/V separation (
BlobTree): large-value workloads with automatic GC. - Pluggable
Fs: standard, in-memory,io_uring, or custom backends. - MVCC: snapshot reads at a chosen
SeqNo, customUserComparator. - Concurrency: thread-safe
BTreeMap-like API.
Keys: up to 65,535 bytes (u16 length field). Values: up to 4,294,967,295
bytes (u32 length field, 2³² − 1). Larger keys and values
carry a proportional performance cost.
§Quick start
use lsm_tree::{AbstractTree, Config, SequenceNumberCounter};
let folder = tempfile::tempdir().unwrap();
let seqno = SequenceNumberCounter::default();
let tree = Config::new(&folder, seqno.clone(), SequenceNumberCounter::default())
.open()
.unwrap();
tree.insert("key", "value", seqno.next());
let value = tree.get("key", lsm_tree::SeqNo::MAX).unwrap();
assert_eq!(value.map(|v| v.to_vec()), Some(b"value".to_vec()));§On-disk format
Current version: V6, the only one this engine reads or writes. Relative
to V5, which the 5.x releases write, the version snapshot names each
table’s level and run in its own record, and the BuRR filter and
retrieval-locator sections use the packed solution layout; see
FormatVersion for the full list.
The self-describing block types (Meta / Manifest / ManifestFooter)
carry a block_flags byte whose ECC_PARITY bit marks a per-block
Reed-Solomon parity trailer and whose KV_CHECKSUM_FOOTER bit marks a
per-entry checksum footer. SST block types (Data / Index / Filter /
RangeTombstone) keep the compact header WITHOUT that byte and derive
parity / footer presence from the per-SST meta descriptors
(descriptor#page_ecc, descriptor#kv_checksum). Any “byte-identical when
off” guarantee in the feature docs is within the current format and
payload-level (e.g. index entries when seqno_in_index = false), not a
cross-version equivalence.
Earlier formats, V5 included, are not readable by this version and vice
versa. A V5 manifest is refused by the manifest version gate with
Error::InvalidVersion at Tree::open and at Config::repair, before
any section is parsed. Older manifests usually fail earlier, at the
manifest footer (see FormatVersion); the engine knows no earlier
layout, so it cannot tell such a manifest from a damaged one, and
Config::repair treats it as unreadable. A V5 store is converted by the
separate offline converter; the engine carries no V5 decoder.
Re-exports§
pub use storage_stats::ApproximateRangeStats;pub use storage_stats::BlobReferenceStats;pub use storage_stats::FilterMemory;pub use storage_stats::LevelStats;pub use storage_stats::RangeCardinality;pub use storage_stats::SegmentStats;pub use storage_stats::StorageStatistics;pub use storage_stats::StorageStats;pub use storage_stats::StorageStatus;pub use encryption::EncryptionProvider;pub use encryption::Aes256GcmProvider;pub use recovery_progress::RecoveryPhase;pub use recovery_progress::RecoveryProgress;pub use recovery_progress::RecoveryProgressSnapshot;pub use repair::RepairPolicy;pub use repair::RepairReport;pub use repair::WalReplayScope;pub use cache::Cache;pub use comparator::DefaultUserComparator;pub use comparator::UserComparator;pub use compression::CompressionType;pub use config::BlobLocalityRelocation;pub use config::Config;pub use config::KvSeparationOptions;pub use config::TreeType;pub use error::Error;pub use error::FormatPart;pub use error::Result;pub use format_version::FormatVersion;pub use iter_guard::IterGuard as Guard;pub use key_domain::KeyDomains;pub use memtable::Memtable;pub use memtable::MemtableId;pub use merge_operator::MergeOperator;pub use prefix::PrefixExtractor;pub use seqno::MAX_SEQNO;pub use seqno::SequenceNumberCounter;pub use seqno::SequenceNumberGenerator;pub use slice::Slice;pub use value::SeqNo;pub use value_type::ValueType;pub use backpressure::WriteBufferBudget;pub use backpressure::Backpressure;pub use backpressure::BackpressureSignals;pub use backpressure::BackpressureThresholds;
Modules§
- backpressure
- Computed write-backpressure verdict (caller-honoured, see
backpressure). Computed write-backpressure verdict. - compaction
- Contains compaction strategies
- config
- Configuration
- ecc
- Shard-based Page ECC (XOR single-parity and Reed-Solomon).
- encryption
- Block-level encryption at rest. Block-level encryption at rest.
- fs
- Pluggable filesystem abstraction for I/O backends. Pluggable filesystem abstraction for I/O backends.
- hash
- Stable hash functions used across the filter and table subsystems.
- heal_
hints - Tree-wide queue of SSTs whose blocks were ECC-corrected on a read that was confirmed persistent (the on-disk bytes are still faulty after a cache-bypassing re-read).
- inspect
- Out-of-band inspection of a single SST file.
- io
- Local I/O trait surface mirroring
std::io::{Read, Write, Seek}. - rate_
limiter - Compaction I/O rate limiter.
- recovery_
progress - Live progress counters for long-running recovery (repair / salvage). Live progress counters for long-running recovery work.
- repair
- Disaster-recovery: rebuild a missing/corrupt manifest from on-disk SSTs.
Last-resort
MANIFESTreconstruction from the SST files on disk. - restrict_
bound - Sidecar recording a tight-space-punched SST’s restriction lower bound.
- resumable
- A multi-get its caller drives, which never blocks, sleeps or waits.
- runtime_
config - Runtime-toggleable configuration (
RuntimeConfig+ atomic-swap handle). Runtime-toggleable configuration. - salvage
- Block-granular SST salvage: recover the readable blocks of an SST whose whole-file verification fails, dropping the corrupted ones.
- scrub
- ECC patrol scrub: a proactive sweep over Page-ECC-protected SST blocks.
- storage_
stats - Read-only storage introspection: how much is stored, the average shape of a stored entry, and an estimate of how many more entries fit in a byte budget.
- util
- Utility functions
- verify
- Integrity verification for SST and blob files.
- write_
budget - A cumulative host-write budget for one physical medium.
Structs§
- Accepted
Writes - What a tree took in from its caller, before any encoding: the payload the bytes it writes are measured against.
- Blob
File - A blob file stores large values and is part of the value log
- Blob
Tree - A key-value-separated log-structured merge tree
- Cache
- Cache, in which blocks or blobs are cached in-memory after being retrieved from disk
- Cache
Stats - A point-in-time snapshot of block-cache effectiveness and occupancy.
- Capacity
Pool - The room compactions in progress hold on the volumes they write to, shared by every tree given the same pool.
- Checkpoint
Info - Summary of a checkpoint produced by
AbstractTree::create_checkpoint. - Columnar
Scan - Iterator over a tree-level projected columnar scan.
- Default
User Comparator - Default comparator using lexicographic byte ordering.
- Descriptor
Table - Caches file descriptors to tables and blob files
- Memtable
- The memtable serves as an intermediary, ephemeral, sorted storage for new items
- Metrics
- Runtime metrics
- Pinned
Entry - One entry of a pinned memtable, as a flush would write it.
- Pinned
File - A file a
PinnedVersionholds in place: a table, a blob file or a compression dictionary. - Pinned
Range Tombstone - A range tombstone of a pinned memtable, deleting
[start, end)belowseqno. - Pinned
Version - A point-in-time view of a tree that keeps its files in place.
- Projected
Field - One field of a
Projection: its column id, its physical type and what its absence means. - Projected
Row - The cells a
ValueProjectorwrites for one row. - Projection
- The columns a projected scan returns: intrinsic columns and value fields, in the order the scan yields them, and the projector that reads the fields out of row values.
- Sequence
Number Counter - Thread-safe sequence number generator
- Slice
- An immutable byte slice that can be cloned without additional heap allocation
- System
Clock - The system wall-clock, backed by
std::time::SystemTime. - Tree
- A log-structured merge tree (LSM-tree/LSMT)
- Tree
Close - The signal of a tree being closed, returned by
Tree::closeand its counterparts. - Weak
Tree - A handle on a tree that does not keep it open, made by
Tree::downgradeand its counterparts. - Write
Batch - Batch of write operations applied with a shared seqno.
- Zstd
Dictionaries - Every dictionary a tree can decompress against, keyed by the id its tables already record.
- Zstd
Dictionary - A zstd dictionary to compress small blocks against.
Enums§
- Absent
- What a projected field reads as in a row that does not have it: a segment
written without the column, a null cell, or a row value the
ValueProjectorfinds no such field in. - AnyIngestion
- Unified ingestion builder over
AnyTree - AnyTree
- May be a standard
Treeor aBlobTree - Compression
Type - Compression algorithm to use
- Error
- Represents errors that can occur in the LSM-tree
- Format
Part - The part of a table whose on-disk format
Error::UnsupportedFormatrefers to. - Format
Version - Block / SST disk format version.
- Pinnable
Slice - A value reference that may share the decompressed block buffer.
- Scan
Since Event - A single change event emitted by
Tree::scan_since_seqno. - Value
Type - Value type (regular value or tombstone)
Constants§
- MAX_
SEQNO - The maximum allowed sequence number value.
Traits§
- Abstract
Tree - Generic Tree API
- Clock
- A source of wall-clock time.
- Guard
- Guard to access key-value pairs
- KeyDomains
- Splits the key space into domains that no new table spans.
- Merge
Operator - A user-defined merge operator for commutative LSM operations.
- Prefix
Extractor - Extracts prefixes from keys for prefix bloom filter indexing.
- Sequence
Number Generator - Trait for custom sequence number generation.
- User
Comparator - Trait for custom user key comparison.
- Value
Projector - Reads the projected fields out of a row value the engine cannot interpret: a value in a memtable or a row-oriented table, or the result of a merge.
Type Aliases§
- KvPair
- KV-tuple (key + value)
- Memtable
Id - Unique memtable ID
- Result
- Tree result
- SeqNo
- Sequence number - a monotonically increasing counter
- Shared
Comparator - Shared reference to a
UserComparator. - Shared
Sequence Number Generator - A shared, cloneable sequence number generator.
- UserKey
- User defined key (byte array)
- User
Value - User defined data (byte array)