From 38768e5396972213aa44d2f163ae3c1562961958 Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Tue, 2 Dec 2014 21:58:48 -0800 Subject: [PATCH] raft: panic if loaded commit is out of range --- raft/raft.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/raft/raft.go b/raft/raft.go index bd3347384..384af0775 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -628,6 +628,9 @@ func (r *raft) promotable() bool { } func (r *raft) loadState(state pb.HardState) { + if state.Commit < r.raftLog.committed || state.Commit > r.raftLog.lastIndex() { + log.Panicf("raft: %x state.commit %d is out of range [%d, %d]", r.id, state.Commit, r.raftLog.committed, r.raftLog.lastIndex()) + } r.raftLog.committed = state.Commit r.Term = state.Term r.Vote = state.Vote