From 152de1fa7e90559c4bd964f965faf18be315c2c9 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Sat, 21 Dec 2024 15:20:56 +0000 Subject: [PATCH] Still return continuous WAL entries when running into ErrSliceOutOfRange Signed-off-by: Benjamin Wang --- server/storage/wal/wal.go | 6 ++++-- tests/robustness/report/wal.go | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/storage/wal/wal.go b/server/storage/wal/wal.go index b364cab63e8..f3d7bc5f4d4 100644 --- a/server/storage/wal/wal.go +++ b/server/storage/wal/wal.go @@ -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. diff --git a/tests/robustness/report/wal.go b/tests/robustness/report/wal.go index e152be5450b..68da5f80fea 100644 --- a/tests/robustness/report/wal.go +++ b/tests/robustness/report/wal.go @@ -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.