fix(defrag): handle defragdb failure
Signed-off-by: Thomas Gosteli <thomas.gosteli@protonmail.ch>
This commit is contained in:
@ -490,8 +490,8 @@ func (b *backend) defrag() error {
|
||||
options = *boltOpenOptions
|
||||
}
|
||||
options.OpenFile = func(_ string, _ int, _ os.FileMode) (file *os.File, err error) {
|
||||
// gofail: var defragNoSpace string
|
||||
// return nil, fmt.Errorf(defragNoSpace)
|
||||
// gofail: var defragOpenFileError string
|
||||
// return nil, fmt.Errorf(defragOpenFileError)
|
||||
return temp, nil
|
||||
}
|
||||
// Don't load tmp db into memory regardless of opening options
|
||||
@ -526,6 +526,11 @@ func (b *backend) defrag() error {
|
||||
if rmErr := os.RemoveAll(tmpdb.Path()); rmErr != nil {
|
||||
b.lg.Error("failed to remove db.tmp after defragmentation completed", zap.Error(rmErr))
|
||||
}
|
||||
|
||||
// restore the bbolt transactions if defragmentation fails
|
||||
b.batchTx.tx = b.unsafeBegin(true)
|
||||
b.readTx.tx = b.unsafeBegin(false)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -578,6 +583,9 @@ func (b *backend) defrag() error {
|
||||
}
|
||||
|
||||
func defragdb(odb, tmpdb *bolt.DB, limit int) error {
|
||||
// gofail: var defragdbFail string
|
||||
// return fmt.Errorf(defragdbFail)
|
||||
|
||||
// open a tx on tmpdb for writes
|
||||
tmptx, err := tmpdb.Begin(true)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user