Skip to content

Commit

Permalink
enhance the WAL file related error
Browse files Browse the repository at this point in the history
The `ErrFileNotFound` was used for for three cases:
1. There is no any WAL files (probably due to no read permission);
2. There is no WAL files matching the snapshot index;
3. The WAL file seqs do not increase continuously.

It's not good for debug when users see the `ErrFileNotFound` error,
so in this PR, a different error is returned for each case above.

Signed-off-by: Benjamin Wang <wachao@vmware.com>
  • Loading branch information
ahrtr committed Aug 2, 2022
1 parent 4f0e92d commit 7ab091c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions server/storage/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 seq (starting from %d) doesn't increase continuously", nameIndex)
}

return names, nameIndex, nil
Expand Down
5 changes: 3 additions & 2 deletions server/storage/wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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(), "doesn't increase continuously") {
t.Errorf("#%d: err = %v isn't expected, want: '* doesn't increase continuously'", i, err)
}
} else {
t.Errorf("#%d: err = %v, want nil", i, err)
Expand Down

0 comments on commit 7ab091c

Please sign in to comment.