Skip to content

Commit

Permalink
badger max compaction levels config
Browse files Browse the repository at this point in the history
  • Loading branch information
vanessaviolet committed Aug 12, 2023
1 parent fe5a771 commit e888c51
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions storage/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e888c51

Please sign in to comment.