经常看到网上对Raft 论文 5.4.2 一节的讨论,这里记录一下我对这个问题的理解。
论文开头是这么描述的:
A leader knows that an entry from its current term is committed once that entry is stored on a majority of the servers. If a leader crashes before committing an entry, future leaders will attempt to finish replicating the entry. However, a leader cannot immediately conclude that an entry from a previous term is committed once it is stored on a majority of servers.
后续的领导人不能判断之前任期里的日志在被复制到多数派的服务器后,就一定被马上被提交了。换句话说,也就是说领导人并不知道之前的任期的日志是否已经被提交,即使这条日志已经被复制到了多数派的服务器上。根据 Raft 协议,这条日志是不能被直接提交的。
在探究为什么之前,我们先假设:如果后续的领导人在当选后,发现之前任期的一条日志已经被复制到多数派的服务器上,直接提交这些日志会发生什么?