mirror of
https://github.com/talent-plan/tinykv.git
synced 2025-03-24 00:30:38 +08:00
raft: keep leader term consistent with log entries (#299)
* raft: keep leader term consistent with log entries Signed-off-by: unconsolable <chenzhipeng2012@gmail.com> * Set leader's term to be greater than/equal to follower Co-authored-by: NingLin-P <linning@pingcap.com> Co-authored-by: NingLin-P <linning@pingcap.com>
This commit is contained in:
parent
08ded5e967
commit
556518011f
@ -617,30 +617,31 @@ func TestFollowerCheckMessageType_MsgAppend2AB(t *testing.T) {
|
|||||||
func TestFollowerAppendEntries2AB(t *testing.T) {
|
func TestFollowerAppendEntries2AB(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
index, term uint64
|
index, term uint64
|
||||||
|
lterm uint64
|
||||||
ents []*pb.Entry
|
ents []*pb.Entry
|
||||||
wents []*pb.Entry
|
wents []*pb.Entry
|
||||||
wunstable []*pb.Entry
|
wunstable []*pb.Entry
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
2, 2,
|
2, 2, 3,
|
||||||
[]*pb.Entry{{Term: 3, Index: 3}},
|
[]*pb.Entry{{Term: 3, Index: 3}},
|
||||||
[]*pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}, {Term: 3, Index: 3}},
|
[]*pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}, {Term: 3, Index: 3}},
|
||||||
[]*pb.Entry{{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: 3, Index: 2}, {Term: 4, Index: 3}},
|
||||||
[]*pb.Entry{{Term: 1, Index: 1}, {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}},
|
[]*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}},
|
||||||
[]*pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}},
|
[]*pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}},
|
||||||
[]*pb.Entry{},
|
[]*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}},
|
[]*pb.Entry{{Term: 3, Index: 1}},
|
||||||
[]*pb.Entry{{Term: 3, Index: 1}},
|
[]*pb.Entry{{Term: 3, Index: 1}},
|
||||||
@ -652,7 +653,7 @@ func TestFollowerAppendEntries2AB(t *testing.T) {
|
|||||||
r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, storage)
|
r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, storage)
|
||||||
r.becomeFollower(2, 2)
|
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))
|
wents := make([]pb.Entry, 0, len(tt.wents))
|
||||||
for _, ent := range tt.wents {
|
for _, ent := range tt.wents {
|
||||||
|
Loading…
Reference in New Issue
Block a user