Skip to content
Browse files

Fix Raft Panic

The lastIndex cache I had introduced, caused Raft panics because it was
incorrect. This PR fixes that by updating it correctly in two places:
addEntries and setSnapshot.

With this PR, blockade runs OK.
  • Loading branch information...
manishrjain committed Mar 9, 2019
1 parent 60d9ef0 commit 8cb69eaea13ad7872b12daafbcc56131171c44e3
Showing with 11 additions and 2 deletions.
  1. +11 −2 raftwal/storage.go
@@ -313,7 +313,16 @@ func (w *DiskStorage) setSnapshot(batch *badger.WriteBatch, s pb.Snapshot) error
return err

// Cache it.
// Update the last index cache here. This is useful so when a follower gets a jump due to
// receiving a snapshot and Save is called, addEntries wouldn't have much. So, the last index
// cache would need to rely upon this update here.
if val, ok := w.cache.Load(lastKey); ok {
le := val.(uint64)
if le < e.Index {
w.cache.Store(lastKey, e.Index)
// Cache snapshot.
w.cache.Store(snapshotKey, proto.Clone(&s))
return nil
@@ -614,9 +623,9 @@ func (w *DiskStorage) addEntries(batch *badger.WriteBatch, entries []pb.Entry) e
laste := entries[len(entries)-1].Index
w.cache.Store(lastKey, laste) // Update the last index cache.
if laste < last {
return w.deleteFrom(batch, laste+1)
w.cache.Store(lastKey, laste)
return nil

1 comment on commit 8cb69ea


This comment has been minimized.

Copy link

skitzofrenic commented on 8cb69ea Apr 7, 2019


Please sign in to comment.
You can’t perform that action at this time.