如题。在编码的过程中,我的matchIndex初始值是0,nextIndex是1。newRaft函数里直接new了一条空日志,来保证日志的index是从1开始的。
但是在测试中,propMsg尚未被Step到raft实例中,他的检查点却是matchIndex=1。那么,这两个值的初始值到底应该是多少?
func TestProgressLeader2AB(t *testing.T) {
r := newTestRaft(1, []uint64{1, 2}, 5, 1, NewMemoryStorage())
r.becomeCandidate()
r.becomeLeader()
// Send proposals to r1. The first 5 entries should be appended to the log.
propMsg := pb.Message{From: 1, To: 1, MsgType: pb.MessageType_MsgPropose, Entries: []*pb.Entry{{Data: []byte("foo")}}}
for i := 0; i < 5; i++ {
if pr := r.Prs[r.id]; pr.Match != uint64(i+1) || pr.Next != pr.Match+1 {
t.Errorf("unexpected progress %v, expected: match(%v) == %v && next(%v) == match+1(%v)", pr, pr.Match, i+1, pr.Next, pr.Match+1)
}
if err := r.Step(propMsg); err != nil {
t.Fatalf("proposal resulted in error: %v", err)
}
}
}