How saint-yellow/baradb works
baradb is a Bitcask-style key/value storage engine. Its core workflow appends encoded records to data files and indexes their positions; reads look up a position and fetch the record. Batch writes add transactional records, while startup rebuilds the index and merging compacts live records. The excerpts establish these core paths and the I/O/index implementations; batch, iterator, and some lifecycle wiring are represented only where the README or sampled code supports them.
Main entry points: db.go DB engine · index.go Index interface · data_file.go Data files · io_handler.go File I/O
Components 16
DB Engine
- DB engine
db.go - DB options
options.go
Log Storage
- Data files
data/data_file.go - Log records
data/log_record.go - File I/O
io_handler/io_handler.go - File handler
io_handler/file_io.go - Mapped reads
io_handler/mmap.go - Record position
data/log_record.go
Indexing
- Index interface
index/index.go - Tree indexes
index/btree.go - B+ tree index
index/bptree.go
DB Operations
- Write batch
batch.go - DB iterator
iterator.go - DB statistics
stat.go - Log merge
mergence.go
Other components
- DB client
Connections 24
- DB client → DB engine: calls API
- DB engine → DB options: uses settings
- DB engine → Log records: encodes writes
- DB engine → Data files: appends records
- DB engine → Index interface: updates index
- DB engine → Index interface: looks up key
- Index interface → Tree indexes: selects tree
- Index interface → B+ tree index: selects B+ tree
- Tree indexes → Record position: stores positions
- B+ tree index → Record position: stores positions
- DB engine → Record position: resolves location
- DB engine → Data files: reads value
- Data files → File I/O: uses handler
- File I/O → File handler: opens file
- File I/O → Mapped reads: opens mapped file
- DB engine → Data files: loads files
- DB engine → Index interface: rebuilds index
- DB engine → Write batch: creates batch
- Write batch → DB engine: commits writes
- DB engine → DB iterator: iterates keys
- DB engine → DB statistics: reports state
- DB client → Log merge: requests compaction
- Log merge → Data files: rewrites live records
- Log merge → Index interface: checks live positions