raft: do not reset vote if term is not changed

raft MUST keep the voting information for the same term. reset
should not reset vote if term is not changed.
This commit is contained in:
Xiang Li 2015-03-07 22:31:09 -08:00 committed by Yicheng Qin
parent 4c86ab4868
commit 78e0149f41
2 changed files with 6 additions and 4 deletions

View File

@ -304,7 +304,7 @@ func TestNodeStart(t *testing.T) {
wants := []Ready{
{
SoftState: &SoftState{Lead: 1, RaftState: StateLeader},
HardState: raftpb.HardState{Term: 2, Commit: 2},
HardState: raftpb.HardState{Term: 2, Commit: 2, Vote: 1},
Entries: []raftpb.Entry{
{Type: raftpb.EntryConfChange, Term: 1, Index: 1, Data: ccdata},
{Term: 2, Index: 2},
@ -315,7 +315,7 @@ func TestNodeStart(t *testing.T) {
},
},
{
HardState: raftpb.HardState{Term: 2, Commit: 3},
HardState: raftpb.HardState{Term: 2, Commit: 3, Vote: 1},
Entries: []raftpb.Entry{{Term: 2, Index: 3, Data: []byte("foo")}},
CommittedEntries: []raftpb.Entry{{Term: 2, Index: 3, Data: []byte("foo")}},
},

View File

@ -306,9 +306,11 @@ func (r *raft) maybeCommit() bool {
}
func (r *raft) reset(term uint64) {
r.Term = term
if r.Term != term {
r.Term = term
r.Vote = None
}
r.lead = None
r.Vote = None
r.elapsed = 0
r.votes = make(map[uint64]bool)
for i := range r.prs {