Skip to content

Commit

Permalink
Still return continuous WAL entries when running into ErrSliceOutOfRange
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Dec 21, 2024
1 parent 40b856e commit 152de1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions server/storage/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,10 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.
// prevent "panic: runtime error: slice bounds out of range [:13038096702221461992] with capacity 0"
offset := e.Index - w.start.Index - 1
if offset > uint64(len(ents)) {
// return error before append call causes runtime panic
return nil, state, nil, fmt.Errorf("%w, snapshot[Index: %d, Term: %d], current entry[Index: %d, Term: %d], len(ents): %d",
// return error before append call causes runtime panic.
// We still return the continuous WAL entries that have already been read.
// Refer to https://github.com/etcd-io/etcd/pull/19038#issuecomment-2557414292.
return nil, state, ents, fmt.Errorf("%w, snapshot[Index: %d, Term: %d], current entry[Index: %d, Term: %d], len(ents): %d",
ErrSliceOutOfRange, w.start.Index, w.start.Term, e.Index, e.Term, len(ents))
}
// The line below is potentially overriding some 'uncommitted' entries.
Expand Down
3 changes: 2 additions & 1 deletion tests/robustness/report/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ func ReadWAL(lg *zap.Logger, dataDir string) (state raftpb.HardState, ents []raf
_, state, ents, err = w.ReadAll()
w.Close()
if err != nil {
if errors.Is(err, wal.ErrSnapshotNotFound) {
if errors.Is(err, wal.ErrSnapshotNotFound) || errors.Is(err, wal.ErrSliceOutOfRange) {
lg.Info("Error occurred when reading WAL entries", zap.Error(err))
return state, ents, nil
}
// we can only repair ErrUnexpectedEOF and we never repair twice.
Expand Down

0 comments on commit 152de1f

Please sign in to comment.