5

Suppose a cluster of 5 nodes(ABCDE), node-A is elected leader at the beginning, and while leader-A issues AppendEntries RPCs to the follower(BCDE) to replicate log entry(log-X),only node-B receives and returns success, at this point leader-A crashes.

If node C(or D or E) wins the next leader election then everything's fine, because only node B has log-X, and that means log-X is not committed.

My question is, could node-B (which has the highest term and longest log) win the next leader election? If so, will node-B spread log-X to other nodes?

4

1 回答 1

3

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.

更多详细信息,请参见草稿纸的第 5.4.2 节。

这也意味着您不能将失败视为意味着尝试的条目绝对不存在,只是调用者不知道结果。第 8 节有一些处理这个问题的建议。

于 2018-06-14T23:28:10.750 回答