Skip to content

Commit

Permalink
Merge pull request #4217 from dotnwat/backport-4211
Browse files Browse the repository at this point in the history
[21.11.x]: backport #4206
  • Loading branch information
dotnwat committed Apr 6, 2022
2 parents 1cda696 + 0a9b7fe commit 937b9fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/v/raft/consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,13 @@ void consensus::setup_metrics() {
labels)});
}

void consensus::do_step_down() {
void consensus::do_step_down(std::string_view ctx) {
_hbeat = clock_type::now();
if (_vstate == vote_state::leader) {
vlog(
_ctxlog.info,
"Stepping down as leader in term {}, dirty offset {}",
"[{}] Stepping down as leader in term {}, dirty offset {}",
ctx,
_term,
_log.offsets().dirty_offset);
}
Expand All @@ -156,7 +157,7 @@ void consensus::maybe_step_down() {
}

if (majority_hbeat + _jit.base_duration() < clock_type::now()) {
do_step_down();
do_step_down("heartbeats_majority");
if (_leader_id) {
_leader_id = std::nullopt;
trigger_leadership_notification();
Expand Down Expand Up @@ -1444,7 +1445,7 @@ ss::future<vote_reply> consensus::do_vote(vote_request&& r) {
reply.term = r.term;
_term = r.term;
_voted_for = {};
do_step_down();
do_step_down("voter_term_greater");
if (_leader_id) {
_leader_id = std::nullopt;
trigger_leadership_notification();
Expand Down Expand Up @@ -1532,7 +1533,7 @@ consensus::do_append_entries(append_entries_request&& r) {
* it updates its target priority to the initial value
*/
_target_priority = voter_priority::max();
do_step_down();
do_step_down("append_entries_term_greater");
if (r.meta.term > _term) {
vlog(
_ctxlog.debug,
Expand Down Expand Up @@ -1836,7 +1837,7 @@ consensus::do_install_snapshot(install_snapshot_request&& r) {
if (r.term > _term) {
_term = r.term;
_voted_for = {};
do_step_down();
do_step_down("install_snapshot_term_greater");
return do_install_snapshot(std::move(r));
}

Expand Down Expand Up @@ -2350,7 +2351,7 @@ ss::future<> consensus::maybe_commit_configuration(ss::semaphore_units<> u) {
vlog(
_ctxlog.trace,
"current node is not longer group member, stepping down");
do_step_down();
do_step_down("not_longer_member");
}
});
}
Expand Down Expand Up @@ -2834,7 +2835,7 @@ consensus::do_transfer_leadership(std::optional<model::node_id> target) {
// (If we accepted more writes, our log could get
// ahead of new leader, and it could lose election)
auto units = co_await _op_lock.get_units();
do_step_down();
do_step_down("leadership_transfer");
if (_leader_id) {
_leader_id = std::nullopt;
trigger_leadership_notification();
Expand Down
4 changes: 2 additions & 2 deletions src/v/raft/consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class consensus {
if (term > _term) {
_term = term;
_voted_for = {};
do_step_down();
do_step_down("external_stepdown");
}
});
}
Expand Down Expand Up @@ -335,7 +335,7 @@ class consensus {
= ss::bool_class<struct update_last_quorum_index>;
// all these private functions assume that we are under exclusive operations
// via the _op_sem
void do_step_down();
void do_step_down(std::string_view);
ss::future<vote_reply> do_vote(vote_request&&);
ss::future<append_entries_reply>
do_append_entries(append_entries_request&&);
Expand Down

0 comments on commit 937b9fe

Please sign in to comment.