Architecture Overview
PallasDB is structured as three independent layers that can be used separately or stacked together.

Data flow - write path
- Client calls
KV.Set(key, val)(or via gRPCPut, or SQLINSERT). - A transaction (
KVTX) is opened with a snapshot of the current state. - The mutation is staged in
tx.updates(aSortedArray). - On
Commit(): a. A conflict check compares updated keys against keys modified by concurrent transactions since this snapshot. b. Each mutation is appended to the WAL (Log.Write) as aEntryAddorEntryDelrecord. c. AEntryCommitrecord is written and fsync'd - the write is now durable. d. The transaction's updates are merged into the in-memory memtable (kv.mem). - If auto-compact is enabled, a compaction signal is sent on
kv.updated.
In cluster mode, mutating commands are first encoded as a Command protobuf, submitted to raft.Apply, and only reach the FSM's Apply() method after consensus. The FSM then calls db.KV.SetEx / db.KV.Del directly.
Data flow - read path
KV.Get(key)checks the optional Ristretto LRU cache first.- A transaction is opened, creating a
MergedSortedKVview spanning:tx.updates(pending mutations, if any)kv.mem(memtable snapshot)kv.main[0..n](SSTable snapshots, newest first)
- The merged view performs
getExact(key):- For
SortedArray: binary search on the in-memory key slice. - For
SortedFile: bloom filter pre-check, then binary search using the on-disk offset index.
- For
- The first level that returns
found=truewins; deleted markers suppress the result. - On cache miss the result is inserted into the Ristretto cache.
Compaction
Compaction has two sub-operations that are triggered by KV.Compact():

Both operations update the double-buffered metadata files atomically before closing old files.
Key dependencies
