Add DB compaction following the deletion of a DB prefix (#2003)

This commit is contained in:
Michael Sutton
2022-04-03 19:08:32 +03:00
committed by GitHub
parent ab73def07a
commit ca5c8549b9
4 changed files with 21 additions and 5 deletions

View File

@@ -14,6 +14,9 @@ type Database interface {
// Begin begins a new database transaction.
Begin() (Transaction, error)
// Compact compacts the database instance.
Compact() error
// Close closes the database.
Close() error
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/syndtr/goleveldb/leveldb"
ldbErrors "github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util"
)
// LevelDB defines a thin wrapper around leveldb.
@@ -47,6 +48,12 @@ func NewLevelDB(path string, cacheSizeMiB int) (*LevelDB, error) {
return db, nil
}
// Compact compacts the leveldb instance.
func (db *LevelDB) Compact() error {
err := db.ldb.CompactRange(util.Range{Start: nil, Limit: nil})
return errors.WithStack(err)
}
// Close closes the leveldb instance.
func (db *LevelDB) Close() error {
err := db.ldb.Close()