2019-05-18 00:33:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/syndtr/goleveldb/leveldb"
|
2020-05-22 17:54:42 +00:00
|
|
|
"github.com/syndtr/goleveldb/leveldb/errors"
|
2019-05-18 00:33:49 +00:00
|
|
|
"github.com/syndtr/goleveldb/leveldb/opt"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
dir = flag.String("dir", ".", "data directory to store leveldb files")
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
opts := &opt.Options{
|
|
|
|
BlockCacheCapacity: 32 * 1024 * 1024, // default value is 8MiB
|
|
|
|
WriteBuffer: 16 * 1024 * 1024, // default value is 4MiB
|
|
|
|
CompactionTableSizeMultiplier: 10,
|
|
|
|
OpenFilesCacheCapacity: -1,
|
|
|
|
}
|
|
|
|
|
|
|
|
db, err := leveldb.OpenFile(*dir, opts)
|
2020-05-22 17:54:42 +00:00
|
|
|
if errors.IsCorrupted(err) {
|
|
|
|
db, err = leveldb.RecoverFile(*dir, opts)
|
|
|
|
}
|
2019-05-18 00:33:49 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
if err := db.CompactRange(util.Range{}); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|