Skip to content

Commit 66b09ea

Browse files
authored
Merge pull request #19067 from ahrtr/wal_error_20241216
Add more debug info when running into ErrSliceOutOfRange when reading WAL
2 parents 3acf3e5 + 9143bef commit 66b09ea

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

server/storage/wal/wal.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,14 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.
485485
// 0 <= e.Index-w.start.Index - 1 < len(ents)
486486
if e.Index > w.start.Index {
487487
// prevent "panic: runtime error: slice bounds out of range [:13038096702221461992] with capacity 0"
488-
up := e.Index - w.start.Index - 1
489-
if up > uint64(len(ents)) {
488+
offset := e.Index - w.start.Index - 1
489+
if offset > uint64(len(ents)) {
490490
// return error before append call causes runtime panic
491-
return nil, state, nil, ErrSliceOutOfRange
491+
return nil, state, nil, fmt.Errorf("%w, snapshot[Index: %d, Term: %d], current entry[Index: %d, Term: %d], len(ents): %d",
492+
ErrSliceOutOfRange, w.start.Index, w.start.Term, e.Index, e.Term, len(ents))
492493
}
493494
// The line below is potentially overriding some 'uncommitted' entries.
494-
ents = append(ents[:up], e)
495+
ents = append(ents[:offset], e)
495496
}
496497
w.enti = e.Index
497498

0 commit comments

Comments
 (0)