panic if we fail to correctly setup the db paths.
we can't really continue and leave a ticking bomb for the next restart; the user might not see it.
This commit is contained in:
parent
d6ace68540
commit
649fc62863
@ -322,29 +322,26 @@ func (b *Blockstore) movingGC() error {
|
|||||||
|
|
||||||
err = db1.Close()
|
err = db1.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("error closing badger db: %s", err)
|
log.Warnf("error closing old badger db: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbpath := b.opts.Dir
|
dbpath := b.opts.Dir
|
||||||
oldpath := fmt.Sprintf("%s.old.%d", dbpath, time.Now().Unix())
|
oldpath := fmt.Sprintf("%s.old.%d", dbpath, time.Now().Unix())
|
||||||
|
|
||||||
ok := true
|
if err = os.Rename(dbpath, oldpath); err != nil {
|
||||||
err = os.Rename(dbpath, oldpath)
|
// this is not catastrophic in the sense that we have not lost any data.
|
||||||
if err != nil {
|
// but it is pretty bad, as the db path points to the old db, while we are now using to the new
|
||||||
// this is bad, but not catastrophic; new data will be written in db2 and user can fix
|
// db; we can't continue and leave a ticking bomb for the next restart.
|
||||||
log.Errorf("error renaming badger db dir from %s to %s; USER ACTION REQUIRED", dbpath, oldpath)
|
// so a panic is appropriate and user can fix.
|
||||||
ok = false
|
panic(fmt.Errorf("error renaming old badger db dir from %s to %s: %w; USER ACTION REQUIRED", dbpath, oldpath, err)) //nolint
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok {
|
if err = os.Symlink(path, dbpath); err != nil {
|
||||||
err = os.Symlink(path, dbpath)
|
// same here; the db path is pointing to the void. panic and let the user fix.
|
||||||
if err != nil {
|
panic(fmt.Errorf("error symlinking new badger db dir from %s to %s: %w; USER ACTION REQUIRED", path, dbpath, err)) //nolint
|
||||||
// ditto, this is bad, but not catastrophic; user can fix
|
|
||||||
log.Errorf("error symlinking badger db dir from %s to %s; USER ACTION REQUIRED", path, dbpath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b.deleteDB(oldpath)
|
b.deleteDB(oldpath)
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("moving blockstore done")
|
log.Info("moving blockstore done")
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user