Skip to content

Commit

Permalink
r/hb_mgr: check if current replica is a leader when collecting hbeats
Browse files Browse the repository at this point in the history
Some time ago we made collecting heartbeats an asynchronous process
(added yields in between creating hb requests for individual nodes).
This made it possible for leadership to be already lost while the
request for group is created as the yield happened and previously
validated condition no longer holds. Trying to suppress the heartbeat
while the replica is not leader lead to assertion.

Added a check to make sure the leadership is not lost when actually
creating a heartbeat request for the follower.

Signed-off-by: Michał Maślanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed Aug 26, 2024
1 parent 435ae65 commit 0d22322
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/v/raft/heartbeat_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ heartbeat_manager::requests_for_range() {
r->_fstats.end(),
[this, r, last_heartbeat, &pending_beats, &reconnect_nodes](
follower_stats::value_type& p) {
// we need to check again as the leadership might have been lost
// while we yield.
if (!r->is_elected_leader()) {
return;
}

auto& [id, follower_metadata] = p;
if (
follower_metadata.last_received_reply_timestamp
Expand Down

0 comments on commit 0d22322

Please sign in to comment.