From 0a9b7fe9d8478392dd75175f921cfcd7c7b1a5f0 Mon Sep 17 00:00:00 2001 From: Michal Maslanka Date: Wed, 6 Apr 2022 12:44:17 +0200 Subject: [PATCH] r/consensus: added more context to stepdown log Added more context to `stepping down` log entry. Now we will be able to check what was the actual reason of a node stepping down. Signed-off-by: Michal Maslanka (cherry picked from commit ca799725115b2bf9c3798978896374a124a2a9ce) --- src/v/raft/consensus.cc | 17 +++++++++-------- src/v/raft/consensus.h | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/v/raft/consensus.cc b/src/v/raft/consensus.cc index 4957efa8c7e3..018170bd19e4 100644 --- a/src/v/raft/consensus.cc +++ b/src/v/raft/consensus.cc @@ -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); } @@ -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(); @@ -1444,7 +1445,7 @@ ss::future 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(); @@ -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, @@ -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)); } @@ -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"); } }); } @@ -2834,7 +2835,7 @@ consensus::do_transfer_leadership(std::optional 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(); diff --git a/src/v/raft/consensus.h b/src/v/raft/consensus.h index cb9e20104357..6c5f09952301 100644 --- a/src/v/raft/consensus.h +++ b/src/v/raft/consensus.h @@ -240,7 +240,7 @@ class consensus { if (term > _term) { _term = term; _voted_for = {}; - do_step_down(); + do_step_down("external_stepdown"); } }); } @@ -335,7 +335,7 @@ class consensus { = ss::bool_class; // 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 do_vote(vote_request&&); ss::future do_append_entries(append_entries_request&&);