Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO-3129 reinit badger localstore in case of known corruption errors #1324

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion pkg/lib/datastore/clientds/clientds.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ func openBadgerWithRecover(opts badger.Options) (db *badger.DB, err error) {
return db, err
}

func isBadgerCorrupted(err error) bool {
if strings.Contains(err.Error(), "checksum mismatch") {
return true
}
if strings.Contains(err.Error(), "checksum is empty") {
return true
}
if strings.Contains(err.Error(), "EOF") {
return true
}
if strings.Contains(err.Error(), "file does not exist") {
return true
}
if strings.Contains(err.Error(), "Unable to parse log") {
return true
}
if strings.Contains(err.Error(), "Level validation err") {
return true
}
if strings.Contains(err.Error(), "failed to read index") {
return true
}
return false
}

func (r *clientds) Init(a *app.App) (err error) {
// TODO: looks like we do a lot of stuff on Init here. We should consider moving it to the Run
r.closing = make(chan struct{})
Expand Down Expand Up @@ -144,7 +169,7 @@ func (r *clientds) Init(a *app.App) (err error) {

r.localstoreDS, err = openBadgerWithRecover(opts)
err = oserror.TransformError(err)
if err != nil && strings.Contains(err.Error(), "checksum mismatch") {
if err != nil && isBadgerCorrupted(err) {
// because localstore contains mostly recoverable info (with th only exception of objects' lastOpenedDate)
// we can just remove and recreate it
err2 := os.Rename(opts.Dir, filepath.Join(opts.Dir, "-corrupted"))
Expand Down
Loading