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.99k stars 886 forks source link

check follower's log gap before transfer leader to it #443

Open JayiceZ opened 8 months ago

JayiceZ commented 8 months ago

In braft's current implementation. if user call transfer_leadership_to a follower, The original leader will call on_leader_stop then wait for the destination follower to catch up log and become new leader. During this time, the raft group can not serve writes.

If there's a big gap between leader's log and the destination follower's log, it will take a long time to wait for the follower to catch up until transfer timeout.

Similar issue: https://github.com/baidu/braft/issues/422

Checking if follower's log is new enough before we actually do transfer_leader may be a nice improvement.

If the improvement is needed, I can submit a PR for it