Skip to content

Commit 152de1f

Browse files
committed
Still return continuous WAL entries when running into ErrSliceOutOfRange
Signed-off-by: Benjamin Wang <[email protected]>
1 parent 40b856e commit 152de1f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

server/storage/wal/wal.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,10 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.
487487
// prevent "panic: runtime error: slice bounds out of range [:13038096702221461992] with capacity 0"
488488
offset := e.Index - w.start.Index - 1
489489
if offset > uint64(len(ents)) {
490-
// return error before append call causes runtime panic
491-
return nil, state, nil, fmt.Errorf("%w, snapshot[Index: %d, Term: %d], current entry[Index: %d, Term: %d], len(ents): %d",
490+
// return error before append call causes runtime panic.
491+
// We still return the continuous WAL entries that have already been read.
492+
// Refer to https://github.com/etcd-io/etcd/pull/19038#issuecomment-2557414292.
493+
return nil, state, ents, fmt.Errorf("%w, snapshot[Index: %d, Term: %d], current entry[Index: %d, Term: %d], len(ents): %d",
492494
ErrSliceOutOfRange, w.start.Index, w.start.Term, e.Index, e.Term, len(ents))
493495
}
494496
// The line below is potentially overriding some 'uncommitted' entries.

tests/robustness/report/wal.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ func ReadWAL(lg *zap.Logger, dataDir string) (state raftpb.HardState, ents []raf
114114
_, state, ents, err = w.ReadAll()
115115
w.Close()
116116
if err != nil {
117-
if errors.Is(err, wal.ErrSnapshotNotFound) {
117+
if errors.Is(err, wal.ErrSnapshotNotFound) || errors.Is(err, wal.ErrSliceOutOfRange) {
118+
lg.Info("Error occurred when reading WAL entries", zap.Error(err))
118119
return state, ents, nil
119120
}
120121
// we can only repair ErrUnexpectedEOF and we never repair twice.

0 commit comments

Comments
 (0)