Raft 论文梳理

2023年 7月 31日 17.1k 0

Raft梳理

此文第一部分是对 schedule 中 Question 的自己的解答,第二部分是自己对 Raft 的梳理,如有不对,欢迎指正!

Questions

Lecture 5

Suppose we have the scenario shown in the Raft paper's Figure 7: a cluster of seven servers, with the log contents shown. The first server crashes (the one at the top of the figure), and cannot be contacted. A leader election ensues. For each of the servers marked (a), (d), and (f), could that server be elected? If yes, which servers would vote for it? If no, what specific Raft mechanism(s) would prevent it from being elected?

假设 Raft论文图7的场景:一个由7个服务器组成的集群,其中显示了日志内容。第一个服务器崩溃了(图中最上面的那个),且网络无法链接,紧接着发生 leader 选举。对于编号为(a)、(d)和(f)的服务器,它们之一是否可以当选?如果是,哪些服务器会投票?如果没有,具体有哪些机制会阻止它当选?

image-20211230103647850.png

这个问题问的是 选举限制。在 5.4.1 Election restriction 中有提及,即

Raft 通过比较日志中最后一个条目的索引和任期来确定两个日志中哪一个是最新的。如果日志的最后一个条目具有不同的任期,那么后面更大任期的日志是最新的。如果日志以相同的任期结束,那么较长的日志是最新的。

同时还要考虑 votedFor 的话,用程序员的代码语言翻译过来就是

func (rf *raft) canVote(args *RequestVoteArgs) bool {
// If votedFor is null or candidateId, and CANDIDATE’s log is
// at least as up-to-date as receiver’s log, grant vote (§5.2, §5.4)
votedFor := rf.votedFor
if votedFor == votedForNil || votedFor == args.CandidateId {
lastLog, lastIndex := rf.logs.LastLog()
if lastLog.Term < args.LastLogTerm ||
(lastLog.Term == args.LastLogTerm && lastIndex

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论