lab2 Raft
Publish on

Raft paper summarization

(」゚ロ゚)」 Raft paper summarization

Part 2A: leader election

Implement Raft leader election and heartbeats (AppendEntries RPCs with no log entries). The goal for Part 2A is for a single leader to be elected, for the leader to remain the leader if there are no failures, and for a new leader to take over if the old leader fails or if packets to/from the old leader are lost. Run go test -run 2A to test your 2A code.

Goal

figure2-2A.png

Steps:

Add the state for leader election to the Raft struct in raft.go
define a struct to hold information about each log entry
Fill in the RequestVoteArgs and RequestVoteReply structs
Modify Make() to create a background goroutine that will kick off leader election periodically by sending out RequestVote RPCs when it hasn't heard from another peer for a while.
Implement the RequestVote() RPC handler so that servers will vote for one another
To implement heartbeats, define an AppendEntries RPC struct, and have the leader send them out periodically.
Write an AppendEntries RPC handler method that resets the election timeout so that other servers don't step forward as leaders when one has already been elected.
The tester requires that the leader send heartbeat RPCs no more than ten times per second.

Part 2B: log

  • 从当前的Leader处收到AppendEntries RPCs或向Candidate投票的时候reset ElectionTimeout()
All you need to know about index

Part 2C: persistence

Part 2D: log compaction

实现Snapshot,index意味着所有index之前的log都将被丢弃

Follower应该使用快照来赶上整体的进度

忽略CondInstallSnapshot

可以先将index设为0,慢慢增大来尝试通过2D的第一个test

如果leader没有能让follower up-to-date的条目,则发送快照

不要实现论文中figure 13的offset

需要让GC可以access被丢弃的条目,即不存在可访问被丢弃条目的指针

保存最新快照的lastIncludedTerm和lastIncludedIndex

© 2024 humbornjo :: based on 
nobloger  ::  rss