Storage Engine

The storage engine lives entirely in db/. It is a classic LSM-tree (Log-Structured Merge-tree) with a custom binary encoding layer.

Components at a glance

ComponentFile(s)Role
Binary encodingcell.goTyped value encoding for keys and values
Row/schema encodingrow.goMulti-column key and value encoding
Write-Ahead Loglog.go, kv_entry.goCrash-safe mutation log
Memtablesorted_array.goIn-memory sorted key-value buffer
SSTablessorted_file.goImmutable on-disk sorted key-value files
Merge iteratormerge.goMulti-level sorted merge
KV storekv.goLSM engine: transactions, compaction, cache
Metadatametadata.goDouble-buffered SSTable version tracking
SQL layersql_parser.go, eval.go, table.goSQL parsing, expression evaluation, table ops

On-disk layout

For a data directory ./data, PallasDB creates:

SSTable filenames are sstable_<version> where version is a monotonically increasing uint64 tracked in the metadata.

Data flow summary

Storage Data Flow

The sections below document each component in detail.