diff --git a/config/config.example.toml b/config/config.example.toml index c0a0634ea..5e35a3193 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -12,8 +12,10 @@ memory-cache-size = 4096 cache-ttl = 7200 [storage] -# enable value log gc will reduce disk storage usage +# enable badger value log gc will reduce disk storage usage value-log-gc = true +# compaction level should be increased when data too big can badger panic +max-compaction-levels = 7 [network] # the public endpoint to receive peer packets, may be a proxy or load balancer diff --git a/config/config.go b/config/config.go index 0ccc4f135..d81c7e6c2 100644 --- a/config/config.go +++ b/config/config.go @@ -48,7 +48,8 @@ type Custom struct { CacheTTL int `toml:"cache-ttl"` } `toml:"node"` Storage struct { - ValueLogGC bool `toml:"value-log-gc"` + ValueLogGC bool `toml:"value-log-gc"` + MaxCompactionLevels int `toml:"max-compaction-levels"` } `toml:"storage"` Network struct { Listener string `toml:"listener"` diff --git a/storage/badger.go b/storage/badger.go index 5d3f9ec67..7fab7a000 100644 --- a/storage/badger.go +++ b/storage/badger.go @@ -62,6 +62,10 @@ func openDB(dir string, sync bool, custom *config.Custom) (*badger.DB, error) { opts = opts.WithBaseLevelSize(16 << 20) opts = opts.WithLevelSizeMultiplier(16) opts = opts.WithMaxLevels(7) + if custom != nil && custom.Storage.MaxCompactionLevels > 0 { + opts = opts.WithMaxLevels(custom.Storage.MaxCompactionLevels) + } + db, err := badger.Open(opts) if err != nil { return nil, err