Skip to content

Commit

Permalink
raft: keep leader term consistent with log entries (talent-plan#299)
Browse files Browse the repository at this point in the history
* raft: keep leader term consistent with log entries

Signed-off-by: unconsolable <[email protected]>

* Set leader's term to be greater than/equal to follower

Co-authored-by: NingLin-P <[email protected]>

Co-authored-by: NingLin-P <[email protected]>
  • Loading branch information
unconsolable and NingLin-P authored Nov 2, 2021
1 parent 08ded5e commit 5565180
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions raft/raft_paper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,30 +617,31 @@ func TestFollowerCheckMessageType_MsgAppend2AB(t *testing.T) {
func TestFollowerAppendEntries2AB(t *testing.T) {
tests := []struct {
index, term uint64
lterm uint64
ents []*pb.Entry
wents []*pb.Entry
wunstable []*pb.Entry
}{
{
2, 2,
2, 2, 3,
[]*pb.Entry{{Term: 3, Index: 3}},
[]*pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}, {Term: 3, Index: 3}},
[]*pb.Entry{{Term: 3, Index: 3}},
},
{
1, 1,
1, 1, 4,
[]*pb.Entry{{Term: 3, Index: 2}, {Term: 4, Index: 3}},
[]*pb.Entry{{Term: 1, Index: 1}, {Term: 3, Index: 2}, {Term: 4, Index: 3}},
[]*pb.Entry{{Term: 3, Index: 2}, {Term: 4, Index: 3}},
},
{
0, 0,
0, 0, 2,
[]*pb.Entry{{Term: 1, Index: 1}},
[]*pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}},
[]*pb.Entry{},
},
{
0, 0,
0, 0, 3,
[]*pb.Entry{{Term: 3, Index: 1}},
[]*pb.Entry{{Term: 3, Index: 1}},
[]*pb.Entry{{Term: 3, Index: 1}},
Expand All @@ -652,7 +653,7 @@ func TestFollowerAppendEntries2AB(t *testing.T) {
r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, storage)
r.becomeFollower(2, 2)

r.Step(pb.Message{From: 2, To: 1, MsgType: pb.MessageType_MsgAppend, Term: 2, LogTerm: tt.term, Index: tt.index, Entries: tt.ents})
r.Step(pb.Message{From: 2, To: 1, MsgType: pb.MessageType_MsgAppend, Term: tt.lterm, LogTerm: tt.term, Index: tt.index, Entries: tt.ents})

wents := make([]pb.Entry, 0, len(tt.wents))
for _, ent := range tt.wents {
Expand Down

0 comments on commit 5565180

Please sign in to comment.