mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #989 from coreos/fix_ignore_term
raft: fix ignore term
This commit is contained in:
commit
5ddfe18cda
@ -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
|
||||
|
@ -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 doesn’t contain an entry at prevLogIndex whose term matches prevLogTerm.
|
||||
// 2. If an existing entry conflicts with a new one (same index but different terms),
|
||||
|
Loading…
x
Reference in New Issue
Block a user