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 f752b96
Show file tree
Hide file tree
Showing 2 changed files with 5 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
2 changes: 1 addition & 1 deletion tests/robustness/report/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ 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) {
return state, ents, nil
}
// we can only repair ErrUnexpectedEOF and we never repair twice.
Expand Down

0 comments on commit f752b96

Please sign in to comment.