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

Unittest NodeTest.LeaderFailWithWitness is not stable. #445

Open ehds opened 3 months ago

ehds commented 3 months ago

NodeTest.LeaderFailWithWitness 测试用例: https://github.com/baidu/braft/blob/b37c610039aa34d6df2e5bda12f830003561b08b/test/test_node.cpp#L462-L477

这段逻辑应该是 2 个 Replica 和一个 Witness 节点,当选出 leader 后,杀死leader,并用 follower 进行日志提交。 但是在这个 for 循环之前,有可能该 follower 已经成为 leader 了,导致 followers 的个数只有 1 个,使用 nodes[1] 会越界。

image

@lintanghui

JayiceZ commented 1 month ago

Thanks for your report! We should temporarily disable followers' election before stop the leader to ensure that the raft group will be no-leader state for a period of time deterministically.