2

当领导者获得日志条目时,它会将其复制到集群中的其他服务器。然后它提交条目并告诉其他服务器也提交。这里似乎有两种情况:
1)领导者提交条目,然后告诉其他服务器也提交。
2)领导者告诉每个人都承诺,然后它也这样做。

在#1中,如果领导者在告诉其他人提交之前崩溃了,那么成为新领导者的人是否会使用该条目,即使它没有提交?如果不是,那么我们有一些与最新条目不同步的日志。(老领导会应用它,而另一个不会。)如果是这样,那么它怎么知道可以提交它?

在#2中,如果leader在提交之前就崩溃了,那么所有其他节点在提交之后都崩溃了,然后在选举中,旧的leader再次成为新的leader,然后其他服务器已经提交了新leader没有提交的条目没有。在这种情况下会发生什么?

4

2 回答 2

3

重要的是要注意存储在服务器上的条目、提交的条目和应用的条目之间的区别。承诺实际上是一个理论概念。在大多数情况下,服务器不会做任何事情来提交条目。这是因为它存储在大多数服务器上,因此保证不会丢失。条目可以在提交时应用,也可以在稍后的某个时间应用,只要服务器按顺序应用它们。

由于分布式系统的性质,所有服务器不可能同时提交一个条目。相反,Raft 只保证在领导者将条目应用到其状态机时,它会在大多数服务器上持久化。大多数 Raft 实现采用方法 #1 以允许领导者将命令应用于其状态机并在其他服务器必须将其应用于其状态机之前响应客户端。

如果领导者应用命令然后失败会发生什么是这样的:

* We know that the command has been stored on a majority of servers therefore...
* Raft's election algorithm guarantees that the next server that's elected has that entry
* When the next leader is elected, it will append a no-op entry to its log and commit it
* Once the no-op entry is committed, the leader will increase its commitIndex to that of the no-op entry and thereby commit all entries remaining from the previous term (including the original leader's last commit)
* On the next heartbeat, the leader will send the index of the no-op as the `commitIndex`
* Remaining followers will be replicated entries up to the leader's no-op and commit entries from the previous leader's term

那有意义吗?

因此,需要注意的重要一点是,即使领导者没有机会通知追随者一个条目已提交,Raft 也保证下一个领导者将拥有第一个领导者已提交的条目,并且该领导者最终将复制这些条目到还没有它们的追随者,并且提交索引将继续超出前一个领导者的最后一个索引。

参考文献:有关从先前条款提交条目的信息,请参阅 Raft 论文 ( https://ramcloud.atlassian.net/wiki/download/attachments/6586375/raft.pdf ) 的第 5.4.2 节

于 2015-08-27T16:24:36.060 回答
0

回答#1。是的,新领导者将始终具有提交的值,因为“选举限制”用于确保领导者完整性,它定义了“如果一个条目在一个术语中提交,那么所有更高编号的术语的领导者的日志肯定会有那个入口 ”。

于 2017-11-18T23:53:12.740 回答