From f11de14b4344ad6a75dcb2e0310c897ee070f1ee Mon Sep 17 00:00:00 2001 From: bowenxiaoCUHKSZ <931759898@qq.com> Date: Thu, 28 May 2020 09:50:54 +0800 Subject: [PATCH 1/2] fix title --- doc/project2-RaftKV.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/project2-RaftKV.md b/doc/project2-RaftKV.md index 16407f24e..bb12043e8 100644 --- a/doc/project2-RaftKV.md +++ b/doc/project2-RaftKV.md @@ -40,7 +40,7 @@ To implement log replication, you may want to start with handling `MsgAppend` an You can run `make project2ab` to test the implementation, and see some hints at the end of this part. -### Implement the raw node interface +#### Implement the raw node interface `raft.RawNode` in `raft/rawnode.go` is the interface we interact with the upper application, `raft.RawNode` contains `raft.Raft` and provide some wrapper functions like `RawNode.Tick()`and `RawNode.Step()`. It also provides `RawNode.Propose()` to let the upper application propose new raft logs. From e4710117e2d66243da81166feb40c1f439ab6837 Mon Sep 17 00:00:00 2001 From: bowenxiaoCUHKSZ <931759898@qq.com> Date: Fri, 29 May 2020 13:09:46 +0800 Subject: [PATCH 2/2] title suggestion --- doc/project2-RaftKV.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/project2-RaftKV.md b/doc/project2-RaftKV.md index bb12043e8..3edcab69e 100644 --- a/doc/project2-RaftKV.md +++ b/doc/project2-RaftKV.md @@ -28,19 +28,21 @@ This part can be broken down into 3 steps, including: `raft.Raft` in `raft/raft.go` provides the core of the Raft algorithm including message handling, driving the logic clock, etc. For more implementation guides, please check `raft/doc.go` which contains an overview design and what these `MessageTypes` are responsible for. -#### Leader election +#### Leader election (project2aa) To implement leader election, you may want to start with `raft.Raft.tick()` which is used to advance the internal logical clock by a single tick and hence drive the election timeout or heartbeat timeout. You don’t need to care about the message sending and receiving logic now. If you need to send out a message, just push it to `raft.Raft.msgs` and all messages the raft received will be passed to `raft.Raft.Step()`. The test code will get the messages from `raft.Raft.msgs` and pass response messages through `raft.Raft.Step()`. The `raft.Raft.Step()` is the entrance of message handling, you should handle messages like `MsgRequestVote`, `MsgHeartbeat` and their response. And please also implement test stub functions and get them called properly like `raft.Raft.becomeXXX` which used to update the raft internal state when the raft’s role changes. You can run `make project2aa` to test the implementation, and see some hints at the end of this part. -#### Log replication +#### Log replication (project2ab) To implement log replication, you may want to start with handling `MsgAppend` and `MsgAppendResponse` on both the sender and receiver side. Checkout `raft.RaftLog` in `raft/log.go` which is a helper struct that help you manage the raft log, in here you also need to interact with the upper application by the `Storage` interface defined in `raft/storage.go` to get the persisted data like log entries and snapshot. You can run `make project2ab` to test the implementation, and see some hints at the end of this part. -#### Implement the raw node interface +### Raw node interface + +#### Implement the raw node interface (project2ac) `raft.RawNode` in `raft/rawnode.go` is the interface we interact with the upper application, `raft.RawNode` contains `raft.Raft` and provide some wrapper functions like `RawNode.Tick()`and `RawNode.Step()`. It also provides `RawNode.Propose()` to let the upper application propose new raft logs.