compact_leveldb.go 705 B

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. "github.com/syndtr/goleveldb/leveldb"
  6. "github.com/syndtr/goleveldb/leveldb/opt"
  7. "github.com/syndtr/goleveldb/leveldb/util"
  8. )
  9. var (
  10. dir = flag.String("dir", ".", "data directory to store leveldb files")
  11. )
  12. func main() {
  13. flag.Parse()
  14. opts := &opt.Options{
  15. BlockCacheCapacity: 32 * 1024 * 1024, // default value is 8MiB
  16. WriteBuffer: 16 * 1024 * 1024, // default value is 4MiB
  17. CompactionTableSizeMultiplier: 10,
  18. OpenFilesCacheCapacity: -1,
  19. }
  20. db, err := leveldb.OpenFile(*dir, opts)
  21. if err != nil {
  22. log.Fatal(err)
  23. }
  24. defer db.Close()
  25. if err := db.CompactRange(util.Range{}); err != nil {
  26. log.Fatal(err)
  27. }
  28. }