Raft 能否选出一个未提交日志的领导者?

Could Raft elect a leader with uncommitted log?

假设一个集群有5个节点(ABCDE),一开始node-A被选为leader,leader-A向follower(BCDE)发出AppendEntries RPC复制日志条目(log-X),只有node-B 收到 returns 成功,此时 leader-A 崩溃了。

如果节点 C(或 D 或 E)赢得下一次领导者选举那么一切都很好,因为只有节点 B 有 log-X,这意味着 log-X 未提交。

我的问题是,node-B(拥有最高任期和最长日志)能否赢得下一次领导选举?如果是这样,node-B是否会将log-X传播到其他节点?

Yes B could win the election, if it does become leader then the first thing it does it to create a log entry with the new term in its log, and start replicating its log to all the followers.由于 B 的日志包含 log-X,如果一切顺利,最终 log-X 条目将被复制并被视为已提交。

If node C wins the election, then when it becomes leader, it won't have the log-X entry, and it'll end up overwriting that entry on Node B.

有关详细信息,请参阅 raft paper 的第 5.4.2 节。

此外,这意味着您不能将失败视为尝试的输入肯定不存在,只是调用者不知道结果。第 8 节有一些处理此问题的建议。