Merge pull request #14300 from ahrtr/enhance_wal_find_error

Enhance the WAL file related error
This commit is contained in:
Sahdev Zala 2022-08-05 20:35:48 -04:00 committed by GitHub
commit 871d8fdaf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -377,9 +377,12 @@ func selectWALFiles(lg *zap.Logger, dirpath string, snap walpb.Snapshot) ([]stri
}
nameIndex, ok := searchIndex(lg, names, snap.Index)
if !ok || !isValidSeq(lg, names[nameIndex:]) {
err = ErrFileNotFound
return nil, -1, err
if !ok {
return nil, -1, fmt.Errorf("wal: file not found which matches the snapshot index '%d'", snap.Index)
}
if !isValidSeq(lg, names[nameIndex:]) {
return nil, -1, fmt.Errorf("wal: file sequence numbers (starting from %d) do not increase continuously", nameIndex)
}
return names, nameIndex, nil

View File

@ -25,6 +25,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -539,8 +540,8 @@ func TestRecoverAfterCut(t *testing.T) {
w, err := Open(zaptest.NewLogger(t), p, walpb.Snapshot{Index: uint64(i), Term: 1})
if err != nil {
if i <= 4 {
if err != ErrFileNotFound {
t.Errorf("#%d: err = %v, want %v", i, err, ErrFileNotFound)
if !strings.Contains(err.Error(), "do not increase continuously") {
t.Errorf("#%d: err = %v isn't expected, want: '* do not increase continuously'", i, err)
}
} else {
t.Errorf("#%d: err = %v, want nil", i, err)