Configuration & Options
NoKV exposes two configuration surfaces:
- Runtime options for the embedded engine (
Optionsinoptions.go). - Cluster topology for distributed mode (
raft_config.example.jsonviaconfig.LoadFile/Validate).
1. Runtime Options (Embedded Engine)
NoKV.NewDefaultOptions() returns a tuned baseline. Override fields before
calling NoKV.Open(opt).
Key option groups (see options.go for the full list):
- Paths & durability
WorkDir,SyncWrites,ManifestSync,ManifestRewriteThreshold
- Write pipeline
WriteBatchMaxCount,WriteBatchMaxSize,WriteBatchWait
- Value log
ValueThreshold,ValueLogFileSize,ValueLogMaxEntriesValueLogGCInterval,ValueLogGCDiscardRatioValueLogGCParallelism,ValueLogGCReduceScore,ValueLogGCSkipScoreValueLogGCReduceBacklog,ValueLogGCSkipBacklogValueLogGCSampleSizeRatio,ValueLogGCSampleCountRatio,ValueLogGCSampleFromHeadValueLogBucketCount,ValueLogHotBucketCount,ValueLogHotKeyThreshold
- LSM & compaction
MemTableSize,MemTableEngine,SSTableMaxSz,NumCompactorsNumLevelZeroTables,IngestCompactBatchSize,IngestBacklogMergeScoreCompactionValueWeight,CompactionValueAlertThreshold
- Caches
BlockCacheSize,BloomCacheSize
- Hot key throttling
WriteHotKeyLimit,HotWriteBurstThreshold,HotWriteBatchMultiplierHotRingEnabled,HotRingTopK, decay/window settingsHotRingNodeCap,HotRingNodeSampleBits,HotRingRotationIntervalValueLogHotRingOverride+ValueLogHotRing*overrides
- WAL watchdog
EnableWALWatchdog,WALAutoGCIntervalWALAutoGCMinRemovable,WALAutoGCMaxBatchWALTypedRecordWarnRatio,WALTypedRecordWarnSegments
- Raft lag warnings (stats only)
RaftLagWarnSegments
Example:
opt := NoKV.NewDefaultOptions()
opt.WorkDir = "./data"
opt.SyncWrites = true
opt.ValueThreshold = 1024
opt.WriteBatchMaxCount = 128
db := NoKV.Open(opt)
defer db.Close()
Load Options From TOML
For convenience, you can load engine options from a TOML file. Unspecified
fields keep their defaults from NewDefaultOptions.
opt, err := NoKV.LoadOptionsFile("nokv.options.toml")
if err != nil {
log.Fatal(err)
}
db := NoKV.Open(opt)
defer db.Close()
Example (TOML):
work_dir = "./data"
mem_table_engine = "art"
value_threshold = 1024
write_hot_key_limit = 128
value_log_gc_interval = "30s"
Notes:
- Field names are case-insensitive;
_/-/.are ignored. - Durations accept Go-style strings (e.g.
"30s","200ms"). Numeric durations are interpreted as nanoseconds. - File extensions
.tomland.tmlare accepted. - JSON option files are rejected by design.
- Unknown fields return an error so typos do not silently pass.
2. Raft Topology File
raft_config.example.json is the single source of truth for distributed
topology. It is consumed by scripts, cmd/nokv-redis, and the config package.
Precedence rule: when a value can be provided by both CLI flags and config file, CLI flags take precedence; config acts as startup defaults.
Minimal shape:
{
"max_retries": 8,
"pd": {
"addr": "127.0.0.1:2379",
"docker_addr": "nokv-pd:2379",
"work_dir": "./artifacts/cluster/pd",
"docker_work_dir": "/var/lib/nokv-pd"
},
"stores": [
{ "store_id": 1, "listen_addr": "127.0.0.1:20170", "addr": "127.0.0.1:20170" }
],
"regions": [
{
"id": 1,
"start_key": "-",
"end_key": "-",
"epoch": { "version": 1, "conf_version": 1 },
"peers": [{ "store_id": 1, "peer_id": 101 }],
"leader_store_id": 1
}
]
}
Notes:
start_key/end_keyaccept plain strings,hex:<bytes>, or base64. Use"-"or empty for unbounded ranges.storesdefine both host and docker addresses for local runs vs containers.pd.addris the default PD endpoint for host scope;pd.docker_addris used when tools run in docker scope.pd.work_dir/pd.docker_work_dirare optional PD persistence directories used by bootstrap tooling andnokv pd --config ...when--workdiris not set explicitly.leader_store_idis optional bootstrap metadata. Runtime routing in cluster mode is resolved through PD (GetRegionByKey), not static leader hints.
Programmatic loading:
cfg, _ := config.LoadFile("raft_config.example.json")
if err := cfg.Validate(); err != nil { /* handle */ }
Related tools:
scripts/run_local_cluster.sh --config raft_config.example.jsongo run ./cmd/nokv-redis --raft-config raft_config.example.json