Manifest & Version Management
The manifest is NoKV’s metadata log for:
- SST files (
EditAddFile/EditDeleteFile) - WAL checkpoint (
EditLogPointer) - value-log metadata (
EditValueLogHead,EditDeleteValueLog,EditUpdateValueLog)
Implementation: engine/manifest/manager.go, engine/manifest/codec.go, engine/manifest/types.go.
1. Files on Disk
WorkDir/
CURRENT
MANIFEST-000001
MANIFEST-000002
CURRENTstores the active manifest filename.CURRENTis updated viaCURRENT.tmp -> CURRENTrename.MANIFEST-*stores append-only encoded edits.
2. In-Memory Version Model
type Version struct {
Levels map[int][]FileMeta
LogSegment uint32
LogOffset uint64
ValueLogs map[ValueLogID]ValueLogMeta
ValueLogHead map[uint32]ValueLogMeta
}
Levels: per-level SST metadata.LogSegment/LogOffset: WAL replay checkpoint.ValueLogs+ValueLogHead: all known vlog segments and per-bucket active heads.
3. Edit Append Semantics
Manager.LogEdits(edits...) does:
- Encode edits to a buffer.
- Write encoded bytes to current manifest file.
- Conditionally call
manifest.Sync()when:Manager.syncWrites == true, and- at least one edit type requires sync (
Add/DeleteFile,LogPointer, value-log edits).
- Apply edits to in-memory
Version. - Trigger manifest rewrite if size crosses threshold.
SetSync(bool) and SetRewriteThreshold(int64) are configured by LSM options.
4. Rewrite Flow
When rewrite threshold is exceeded (or Rewrite() is called):
- Create next
MANIFEST-xxxxxx. - Write a full snapshot of current
Version. - Flush writer, and
Sync()the new manifest whensyncWritesis enabled. - Update
CURRENTto point to new file. - Reopen the new manifest for appends and remove old manifest file.
If rewrite fails before CURRENT update, restart continues using previous manifest.
5. Interaction with Other Modules
| Module | Manifest usage |
|---|---|
engine/lsm/level_manager.go::flush | Logs EditAddFile + EditLogPointer after SST install; compaction logs add/delete edits. |
engine/lsm/level_manager.go::build | During startup, missing/corrupt SST entries are marked stale and cleaned via EditDeleteFile. |
wal | Replays from manifest checkpoint (LogSegment, LogOffset). |
vlog | Persists head/update/delete metadata and uses manifest state for stale/orphan cleanup on startup. |
raftstore | Does not own manifest state. Store-local region catalogs and raft WAL replay checkpoints live in raftstore/localmeta; runtime routing state lives in Coordinator storage. |
6. Recovery-Relevant Guarantees
- Manifest append is ordered by single manager mutex.
- WAL replay starts from manifest checkpoint.
- Restart replays only storage-engine metadata.
CURRENTindirection protects against partial manifest rewrite publication.
7. Operational Commands
nokv manifest --workdir <dir>
Useful fields:
log_pointer.segment,log_pointer.offsetlevels[*].filesvalue_log_headsvalue_logs[*].valid
See recovery.md and flush.md for startup and flush ordering details.