在网络分区的情况下,Raft 保持一致。但是,如果只有一个节点仅失去与领导者的联系,成为候选人并要求投票,会发生什么?
这是设置,我调整了来自 http://thesecretlivesofdata.com/raft/ 的示例满足我的需求:
节点 B
是当前的领导者并向追随者发送心跳(红色)。 B
和 C
之间的连接丢失,在选举超时后 C
成为候选人,为自己投票并询问节点 A
、D
和 E
为其投票(绿色)。
发生了什么?
据我了解 Raft,节点 A
、D
和 E
应该投票给 C
,这使得C
下一位领导者(Term 2)。然后我们有两个领导者各自发送心跳,希望节点 A
、D
和 E
将忽略来自 B
因为术语较低。
这是正确的还是有更好的机制?
最佳答案
通过 Raft Paper 之后再次,看来我的上述方法是正确的。来自论文:
Terms act as a logical clock in Raft, and they allow servers to detect obsolete information such as stale leaders. Each server stores a current term number, which increases monotonically over time. Current terms are exchanged whenever servers communicate; if one server’s current term is smaller than the other’s, then it updates its current term to the larger value. If a candidate or leader discovers that its term is out of date, it immediately reverts to follower state. If a server receives a request with a stale term number, it rejects the request
突出显示的部分是我在上面遗漏的部分。所以流程是:
- 节点
C
成为候选者后,它将其任期数增加到 2 并请求可达节点 (A
,D
和E
)。 - 那些人会立即将他们的
current_term
变量更新为 2 并投票给C
。 - 因此,节点
A
、D
和E
将忽略来自B
的心跳,并告诉B
当前任期为2。 B
将返回到 follower 状态(直到C
和B
之间的网络连接恢复后才会更新)。
关于consensus - Raft 共识协议(protocol)是否处理与领导者失去联系但不与其他节点联系的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231048/