baidu / braft

An industrial-grade C++ implementation of RAFT consensus algorithm based on brpc, widely used inside Baidu to build highly-available distributed systems.
Apache License 2.0
3.84k stars 862 forks source link

Solve the problem that when changing the cluster configuration through the joint consensus algorithm, a new leader cannot be elected under abnormal circumstances. #432

Open walterzhaoJR opened 6 months ago

walterzhaoJR commented 6 months ago

背景

假设有一个raft group有3个节点ABC,其中A是leader,现在通过联合共识将成员配置变更成ABD,当复制最新的配置(ABD)时,A节点退出,这条log只复制到了C节点(即将被移除的节点),此时集群将无法选举出新的leader。因为,选举成leader的必要条件是:存在最新的log(term大或者term相同的情况下,index更大)。当前的现状:只有C有最新的log,BD发起选举,C不会为他们投票。C发起选举的时候,按照目前的实现,C不在最新配置列表中,无法发起选举,此时集群将无法选举出新的leader。

解决方案

在查询了raft的论文后发现,并没有要求参与选举的节点一定要处于配置列表中,这个问题有点类似于原集群的leader不在新的配置列表中,当新配置commit后,原leader会stepdown。

请确认这个问题。

image

image