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.release-2.1
parent
b374f93bb8
commit
7fe608532a
|
@ -255,7 +255,7 @@ func TestMultiNodeStart(t *testing.T) {
|
||||||
wants := []Ready{
|
wants := []Ready{
|
||||||
{
|
{
|
||||||
SoftState: &SoftState{Lead: 1, RaftState: StateLeader},
|
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{
|
Entries: []raftpb.Entry{
|
||||||
{Type: raftpb.EntryConfChange, Term: 1, Index: 1, Data: ccdata},
|
{Type: raftpb.EntryConfChange, Term: 1, Index: 1, Data: ccdata},
|
||||||
{Term: 2, Index: 2},
|
{Term: 2, Index: 2},
|
||||||
|
@ -266,7 +266,7 @@ func TestMultiNodeStart(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")}},
|
Entries: []raftpb.Entry{{Term: 2, Index: 3, Data: []byte("foo")}},
|
||||||
CommittedEntries: []raftpb.Entry{{Term: 2, Index: 3, Data: []byte("foo")}},
|
CommittedEntries: []raftpb.Entry{{Term: 2, Index: 3, Data: []byte("foo")}},
|
||||||
},
|
},
|
||||||
|
|
|
@ -304,7 +304,7 @@ func TestNodeStart(t *testing.T) {
|
||||||
wants := []Ready{
|
wants := []Ready{
|
||||||
{
|
{
|
||||||
SoftState: &SoftState{Lead: 1, RaftState: StateLeader},
|
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{
|
Entries: []raftpb.Entry{
|
||||||
{Type: raftpb.EntryConfChange, Term: 1, Index: 1, Data: ccdata},
|
{Type: raftpb.EntryConfChange, Term: 1, Index: 1, Data: ccdata},
|
||||||
{Term: 2, Index: 2},
|
{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")}},
|
Entries: []raftpb.Entry{{Term: 2, Index: 3, Data: []byte("foo")}},
|
||||||
CommittedEntries: []raftpb.Entry{{Term: 2, Index: 3, Data: []byte("foo")}},
|
CommittedEntries: []raftpb.Entry{{Term: 2, Index: 3, Data: []byte("foo")}},
|
||||||
},
|
},
|
||||||
|
|
|
@ -358,9 +358,11 @@ func (r *raft) maybeCommit() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *raft) reset(term uint64) {
|
func (r *raft) reset(term uint64) {
|
||||||
r.Term = term
|
if r.Term != term {
|
||||||
|
r.Term = term
|
||||||
|
r.Vote = None
|
||||||
|
}
|
||||||
r.lead = None
|
r.lead = None
|
||||||
r.Vote = None
|
|
||||||
r.elapsed = 0
|
r.elapsed = 0
|
||||||
r.votes = make(map[uint64]bool)
|
r.votes = make(map[uint64]bool)
|
||||||
for i := range r.prs {
|
for i := range r.prs {
|
||||||
|
|
Loading…
Reference in New Issue