一致性算法探寻(扩展版)3

5 The Raft consensus algorithm

Raft is an algorithm for managing a replicated log of the form described in Section 2. Figure 2 summarizes the algorithm in condensed form for reference, and Figure 3 lists key properties of the algorithm; the elements of these figures are discussed piecewise over the rest of this section.

Raft implements consensus by first electing a distinguished leader, then giving the leader complete responsibility for managing the replicated log. The leader accepts log entries from clients, replicates them on other servers, and tells servers when it is safe to apply log entries to their state machines. Having a leader simplifies the management of the replicated log. For example, the leader can decide where to place new entries in the log without consulting other servers, and data flows in a simple fashion from the leader to other servers. A leader can fail or become disconnected from the other servers, in which case a new leader is elected.

Given the leader approach, Raft decomposes the consensus problem into three relatively independent subproblems, which are discussed in the subsections that follow:

  • Leader election: a new leader must be chosen when an existing leader fails (Section 5.2).
  • Log replication: the leader must accept log entries from clients and replicate them across the cluster, forcing the other logs to agree with its own (Section 5.3).
  • Safety: the key safety property for Raft is the State Machine Safety Property in Figure 3: if any server has applied a particular log entry to its state machine, then no other server may apply a different command for the same log index. Section 5.4 describes how Raft ensures this property; the solution involves an additional restriction on the election mechanism described in Section 5.2.

After presenting the consensus algorithm, this section discusses the issue of availability and the role of timing in the system.

5 一致性算法Raft

Raft是一种用于管理第2章描述的日志复制的算法。图2进行了简单概括以供参考,图3列出了算法的关键属性;在本文的其他章节讨论了这些图中的元素。

Raft首先选出一个杰出的leader,然后给予其管理日志复制的全部职责来实现一致性。该leader从客户端接收日志条目,将他们复制到其他服务器,并告诉他们它从状态机获取日志条目是安全的。只有一个leader简化了日志复制的管理。例如,该leader不需要和其他服务器沟通就决定将日志条目防于日志的位置,并且数据流以一个简单的方式从leader流向其他服务器。一个leader可能挂了或者链接断了,这时候就选举一个新的leader。

确定了leader策略,Raft将一致性问题分解成了三个独立的部分,请看下面的讨论:

  • leader选举:当前leader挂了的时候必须选举出一个新的leader(5.2章)。
  • 日志复制:leader必须从客户端接收日志条目并在集群中复制,强制替换其他不同的日志(5.3章)。
  • 安全性:Raft的关键安全属性就是图3中的the State Machine Safety Property:假如随便一台服务器传递了一个特定的日志条目给它的状态机,然后其他服务器再也不能传递同一个日志索引的不同命令。第5.4章描述了Raft确保这个属性,该解决方案包含了第5.2章中选举机制的一个额外限制。

呈现了一致性算法后,本章节将讨论可用性问题和定时在系统中的角色。

时间: 2024-10-12 14:04:05

一致性算法探寻(扩展版)3的相关文章

一致性算法探寻(扩展版)图解

首先,翻一下图1的注释:复制状态机架构.一致性算法管理日志复制包括从可短接收的状态机命令.状态机处理日志里相同序列的命令,所以他们产生相同的输出. 正式图解,首先图1分为2个部分,客户端和服务器.箭头1由客户端指向服务器的一致性模块,表示由客户端发送请求至服务器由一致性模块接收,然后才有箭头2进行分发日志处理的命令.可以看到箭头2指向多层的log模块,表示多个服务器接收了该信息.日志处理完成后,出现箭头3,日志模块发送消息给状态机,最后由状态机返回结果给客户端.这里主要阐述状态机的实现. 再来由

一致性算法探寻(扩展版)8

6 Cluster membership changes Up until now we have assumed that the cluster configuration (the set of servers participating in the consensus algorithm) is fixed. In practice, it will occasionally be necessary to change the configuration, for example t

一致性算法探寻(扩展版)5

5.3 Log replication Once a leader has been elected, it begins servicing client requests. Each client request contains a command to be executed by the replicated state machines. The leader appends the command to its log as a new entry, then issues App

一致性算法探寻(扩展版)11

9 Implementation and evaluation We have implemented Raft as part of a replicated state machine that stores configuration information for RAMCloud [33] and assists in failover of the RAMCloud coordinator. The Raft implementation contains roughly 2000

一致性算法探寻(扩展版)4

5.2 Leader election Raft uses a heartbeat mechanism to trigger leader election. When servers start up, they begin as followers. A server remains in follower state as long as it receives valid RPCs from a leader or candidate. Leaders send periodic hea

一致性算法探寻(扩展版)13

11 Conclusion Algorithms are often designed with correctness, efficiency, and/or conciseness as the primary goals. Although these are all worthy goals, we believe that understandability is just as important. None of the other goals can be achieved un

一致性算法探寻(扩展版)9

7 Log compaction Raft's log grows during normal operation to incorporate more client requests, but in a practical system, it cannot grow without bound. As the log grows longer, it occupies more space and takes more time to replay. This will eventuall

一致性算法探寻(扩展版)7

5.5 Follower and candidate crashes Until this point we have focused on leader failures. Follower and candidate crashes are much simpler to handle than leader crashes, and they are both handled in the same way. If a follower or candidate crashes, then

分布式一致性算法:Raft 算法

Raft 算法是可以用来替代 Paxos 算法的分布式一致性算法,而且 raft 算法比 Paxos 算法更易懂且更容易实现.本文对 raft 论文进行翻译,希望能有助于读者更方便地理解 raft 的思想.如果对 Paxos 算法感兴趣,可以看我的另一篇文章:分布式系列文章--Paxos算法原理与推导 摘要Raft 是用来管理复制日志(replicated log)的一致性协议.它跟 multi-Paxos 作用相同,效率也相当,但是它的组织结构跟 Paxos 不同.这使得 Raft 比 Pax