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.93k stars 879 forks source link

raft 节点处理CANDIDATE 阶段,一直无法选举leader #86

Closed ghost closed 5 years ago

ghost commented 5 years ago

default

ghost commented 5 years ago

上图中为啥会有votedfor 0.0.0.0:0:0 这个 PeerId?

Edward-xk commented 5 years ago

上图中为啥会有votedfor 0.0.0.0:0:0 这个 PeerId?

0.0.0.0:0:0这个是节点在提升term时会有一个step_down过程,重置投票信息。 你这里candidate一直没选主成功,可能是因为log的问题,但提供的日志有限,还不能确认。 建议把raft_step_down_when_vote_timedout设为true,可以解决极端case下vote反复失败无法选主的问题

ghost commented 5 years ago

我看了源代码, 有个地方判断日志时出问题了,代码, 这里日志出问题,有哪些原因导致呢?

Edward-xk commented 5 years ago

我看了源代码, 有个地方判断日志时出问题了,代码, 这里日志出问题,有哪些原因导致呢?

一种case是vote过程中follower写了新日志导致投票失败,我们线上环境出现过这种异常case,你这里具体原因要仔细分析日志,才能确认是不是相同的case

ghost commented 5 years ago

我看了源代码, 有个地方判断日志时出问题了,代码, 这里日志出问题,有哪些原因导致呢?

一种case是vote过程中follower写了新日志导致投票失败,我们线上环境出现过这种异常case,你这里具体原因要仔细分析日志,才能确认是不是相同的case

我好像找到原因了, 因为我调用了 NodeImpl::read_committed_user_log 这个函数, 此函数性能导致