Merge pull request #989 from coreos/fix_ignore_term

raft: fix ignore term
This commit is contained in:
Xiang Li 2014-09-04 14:36:56 -07:00
commit 5ddfe18cda
2 changed files with 17 additions and 0 deletions

View File

@ -348,6 +348,7 @@ func (r *raft) Step(m pb.Message) error {
r.becomeFollower(m.Term, lead)
case m.Term < r.Term:
// ignore
return nil
}
r.step(r, m)
return nil

View File

@ -458,6 +458,22 @@ func TestCommit(t *testing.T) {
}
}
// ensure that the Step function ignores the message from old term and does not pass it to the
// acutal stepX function.
func TestStepIgnoreOldTermMsg(t *testing.T) {
called := false
fakeStep := func(r *raft, m pb.Message) {
called = true
}
sm := newRaft(0, []int64{0}, 0, 0)
sm.step = fakeStep
sm.Term = 2
sm.Step(pb.Message{Type: msgApp, Term: sm.Term - 1})
if called == true {
t.Errorf("stepFunc called = %v , want %v", called, false)
}
}
// TestHandleMsgApp ensures:
// 1. Reply false if log doesnt contain an entry at prevLogIndex whose term matches prevLogTerm.
// 2. If an existing entry conflicts with a new one (same index but different terms),