筏如何保证可以始终选出领导者?

发布于 2025-01-20 05:32:50 字数 577 浏览 0 评论 0原文

Raft 论文 说:

Raft 使用投票过程来阻止候选人赢得选举 选举,除非其日志包含所有已提交的条目。候选人 必须联系集群的大多数才能当选,这 意味着每个提交的条目必须至少出现在以下之一中 那些服务器。如果候选人的日志至少是最新的 其他登录占多数,那么它将保留所有已提交的 条目。 RequestVote RPC 实现了这个限制:RPC 包含有关候选人日志的信息,但选民否认 如果自己的日志比候选人的日志更新,则投票

然而,它如何保证总是甚至有一个可以当选的领导者(即与最新的领导者一样)日期作为集群的大多数)?

例如,假设我们有一个由三台服务器 A、B、C 组成的集群,其中 A 为领导者。第一个日志条目存储在 A 和 B 中,第二个日志条目存储在 A 和 C 中。然后 A 崩溃,B 和 C 尝试选举领导者。但此时不存在大多数(即三分之二)服务器同时具有第一和第二条目。所以看起来领导者选举永远不会发生(除非 A 重新启动,但 Raft 应该能够适应三分之一服务器的故障..)

The Raft paper says:

Raft uses the voting process to prevent a candidate from winning an
election unless its log contains all committed entries. A candidate
must contact a majority of the cluster in order to be elected, which
means that every committed entry must be present in at least one of
those servers. If the candidate’s log is at least as up-to-date as any
other log in that majority, then it will hold all the committed
entries. The RequestVote RPC implements this restriction: the RPC
includes information about the candidate’s log, and the voter denies
its vote if its own log is more up-to-date than that of the candidate

How does it guarantee, however, that there will always even be an electable leader (i.e. one that's as up-to-date as a majority of cluster)?

For example, let's say we have a cluster of three servers A, B, C with A as the leader. First log entry is stored in A and B, second log entry is stored in A and C. Then A crashes, and B and C try to elect a leader. But at this point there is no majority (i.e. 2 out of 3) servers that have both first and second entries. So it seems like leader election can't ever happen (unless A restarts, but Raft's supposed to be resilient to a failure of 1 out of 3 servers..)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

油饼 2025-01-27 05:32:50

论文定义了一个与该场景相关的“日志匹配属性”:

• [..]
• 如果不同日志中的两个条目具有相同的索引
和 term,那么前面所有的日志都是相同的
条目。

由于 A 和 C 都包含相同的第二个条目,因此 C 也必须包含第一个条目。这是可以保证的,因为:

第二个属性由 AppendEntries 执行的简单一致性检查保证。当发送 AppendEntries RPC 时,领导者包含索引
以及其日志中紧邻的条目的术语
新条目。如果关注者没有找到条目
它的日志具有相同的索引和术语,然后它拒绝
新条目。

在 C 拥有 B 拥有的条目之前,它将拒绝进一步的追加。因此,在您的场景中的某个时刻,C 必须收到该条目才能最终接受来自 A 的新条目。

因此,C 是 B 和 C 之间最新的条目。(它将拒绝 B 的领导投票。)

The paper defines a "Log Matching Property" that is relevant to this scenario:

• [..]
• If two entries in different logs have the same index
and term, then the logs are identical in all preceding
entries.

Since A and C both contain the same second entry, C must also contain the first entry. This is ensured because:

The second property is guaranteed by a simple consistency check performed by AppendEntries. When sending an AppendEntries RPC, the leader includes the index
and term of the entry in its log that immediately precedes
the new entries. If the follower does not find an entry in
its log with the same index and term, then it refuses the
new entries.

Until C has the entry that B has, it will reject further appends. So at some point in your scenario, C must have received that entry to finally accept the newer entry from A.

Therefore, C is the most up to date between B and C. (It would reject a leadership vote from B.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文