How sereinsos/tiny-lsm works
Tiny-LSM is a C++ key-value database built around an LSM-tree, with a partly Redis-compatible server and Python SDK. The main workflow accepts library or Redis commands, applies them through the engine, and serves reads from memory or sorted-table files; writes are buffered and later flushed and compacted. Transactions/MVCC, WAL recovery, and optional WiscKey value separation extend that path. The map preserves documented Redis command families and storage layers; some subsystem links are omitted or dashed where sampled source does not establish the runtime call.
Main entry points: engine.cpp LSM Engine · sst.cpp SSTables · memtable.cpp MemTable · vlog.cpp Value Log
Components 20
Client Access
- C++ API
include/lsm/engine.h - RESP Server
server/src/server.cpp - Command Handler
server/src/handler.cpp - Redis Commands
src/redis_wrapper/redis_wrapper.cpp - Python SDK
sdk/lsm_pybind.cpp
LSM Engine
- LSM Engine
src/lsm/engine.cpp - MVCC Transactions
src/lsm/transation.cpp - MemTable
src/memtable/memtable.cpp - Skip List
src/skiplist/skipList.cpp - Merge Iterators
src/lsm/two_merge_iterator.cpp - Level Iterator
src/lsm/level_iterator.cpp
Storage Format
- SSTables
src/sst/sst.cpp - Data Blocks
src/block/block.cpp - Block Cache
src/block/block_cache.cpp - Bloom Filter
src/utils/bloom_filter.cpp - Value Log
src/vlog/vlog.cpp
Durability & Config
- Write-Ahead Log
src/wal/wal.cpp - File I/O
src/utils/files.cpp - TOML Config
src/config/config.cpp
Other components
- Redis Client
Connections 24
- Redis Client → RESP Server: sends RESP
- RESP Server → Command Handler: dispatches commands
server/src/server.cpp - Command Handler → Redis Commands: invokes commands
server/src/handler.cpp - Redis Commands → LSM Engine: uses database
- C++ API → LSM Engine: calls API
src/lsm/engine.cpp - Python SDK → LSM Engine: binds API
sdk/lsm_pybind.cpp - LSM Engine → MemTable: checks reads
src/lsm/engine.cpp - LSM Engine → SSTables: queries SSTs
src/lsm/engine.cpp - MemTable → Skip List: stores entries
src/memtable/memtable.cpp - MemTable → SSTables: builds on flush
src/memtable/memtable.cpp - LSM Engine → MVCC Transactions: manages transactions
- LSM Engine → Merge Iterators: merges ranges
- LSM Engine → Level Iterator: exposes iteration
- SSTables → Data Blocks: encodes blocks
- SSTables → Block Cache: uses cache
- SSTables → Bloom Filter: filters lookups
- SSTables → Value Log: resolves values
- LSM Engine → Value Log: recreates log
src/lsm/engine.cpp - MVCC Transactions → Write-Ahead Log: uses WAL
- Write-Ahead Log → File I/O: persists records
- Value Log → File I/O: reads and appends
- SSTables → File I/O: reads and writes
- LSM Engine → TOML Config: reads settings
src/lsm/engine.cpp - MemTable → TOML Config: checks size limit
src/memtable/memtable.cpp