talent-plan/tinykv

Questions about log replication, stage: project2AB

bobbai00 opened this issue · 0 comments

Dear developers,

I am currently working on project2AB, but I'm confused of some test cases in committed field's value. For example, in test case TestLogReplication2AB: ( tinykv/raft/raft_test.go)

func TestLogReplication2AB(t *testing.T) {
	tests := []struct {
		*network
		msgs       []pb.Message
		wcommitted uint64
	}{
		{
			newNetwork(nil, nil, nil),
			[]pb.Message{
				{From: 1, To: 1, MsgType: pb.MessageType_MsgPropose, Entries: []*pb.Entry{{Data: []byte("somedata")}}},
			},
			2,   // the expected committed value after leader use "MessageType_MsgPropose" to append and commit new log
		}
                               // .........
}

In this test case, node 1 is leader, and it executes the message: MessageType_MsgPropose to append new log with data "somedata" to other followers. According to my understanding, since the initial value of committed field is 0, meaning that no log is committed at the beginning of the cluster, the committed should be 1 after leader commits a new log. But the expected committed value is 2. Why is that?