Skip to content

Commit

Permalink
truncate badger db if truncation error encountered [v0.6 backport]
Browse files Browse the repository at this point in the history
Same as #2388
  • Loading branch information
buck54321 authored and chappjc committed Jun 14, 2023
1 parent 1abd06d commit b9c9ece
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/asset/kvdb/kvdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ func NewFileDB(filePath string, log dex.Logger) (KeyValueDB, error) {
// .WithValueLogLoadingMode(options.FileIO) // default options.MemoryMap
// .WithMaxTableSize(sz int64); // bytes, default 6MB
// .WithValueLogFileSize(sz int64), bytes, default 1 GB, must be 1MB <= sz <= 1GB
db, err := badger.Open(badger.DefaultOptions(filePath).WithLogger(&badgerLoggerWrapper{log}))
opts := badger.DefaultOptions(filePath).WithLogger(&badgerLoggerWrapper{log})
db, err := badger.Open(opts)
if err == badger.ErrTruncateNeeded {
// Probably a Windows thing.
// https://github.com/dgraph-io/badger/issues/744
log.Warnf("NewFileDB badger db: %v", err)
// Try again with value log truncation enabled.
opts.Truncate = true
log.Warnf("Attempting to reopen badger DB with the Truncate option set...")
db, err = badger.Open(opts)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit b9c9ece

Please sign in to comment.