You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Keys in memory before flush (set higher for real use)
COMPACTION_THRESHOLD
3
SSTable file count before needs_compaction() is true
BLOOM_BITS
8192
Bits per bloom filter (~1 KB); more bits = lower false positive rate
BLOOM_HASHES
3
Hash functions per bloom filter
SPARSE_INDEX_INTERVAL
4
Index one entry every N keys; smaller = faster seek, more memory
Potential improvements
Correctness
fsync after writes — currently only flush() (userspace buffer); a hard crash could still lose data without sync_all()
WAL truncation on partial replay — if the process crashes mid-replay, the WAL could contain a partial line; add a checksum per entry (e.g. CRC32) to detect and skip corrupt records
Read performance
Block cache (LRU) — cache recently read SSTable blocks in memory; hot keys stop touching disk entirely
Binary SSTable format — fixed-size blocks with a block index; enables efficient block-level caching and avoids line-by-line parsing
Multi-level compaction (LSM levels) — L0 files can overlap; L1+ are sorted and non-overlapping within a level; each level is ~10× the size of the previous; reads become O(levels) instead of O(files)
Write performance
Tiered compaction strategy — instead of one flat level, group SSTables by size tier; reduces write amplification at the cost of more files per read
Background compaction thread — run compaction off the write path entirely; requires Arc<Mutex<Db>> or a message-passing design
Features
Range scans — scan(start, end) is natural since SSTables are sorted; merge results across MemTable and all SSTables
Snapshots — point-in-time read views; assign a sequence number to each write and filter by it on read
Column families — separate MemTable/SSTable trees per logical namespace
Compression — compress SSTable blocks (e.g. LZ4, Snappy) to reduce I/O at the cost of CPU