From a8ee4d543a693fe358862559902d6e65aa08fc4f Mon Sep 17 00:00:00 2001 From: Piotr Dulikowski Date: Mon, 30 Oct 2023 16:05:11 +0100 Subject: [PATCH] raft: transfer information about group0 liveness in direct_fd_ping Add a new variant of the reply to the direct_fd_ping which specifies whether the local group0 is alive or not, and start actively using it. There is no need to introduce a cluster feature. Due to how our serialization framework works, nodes which do not recognize the new variant will treat it as the existing std::monostate. The std::monostate means "the node and group0 is alive"; nodes before the changes in this commit would send a std::monostate anyway, so this is completely transparent for the old nodes. --- idl/raft.idl.hh | 6 +++++- service/raft/group0_fwd.hh | 6 +++++- service/raft/raft_group_registry.cc | 24 +++++++++++++++++++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/idl/raft.idl.hh b/idl/raft.idl.hh index 658a190812..81845257c5 100644 --- a/idl/raft.idl.hh +++ b/idl/raft.idl.hh @@ -121,8 +121,12 @@ struct wrong_destination { raft::server_id reached_id; }; +struct group_liveness_info { + bool group0_alive; +}; + struct direct_fd_ping_reply { - std::variant result; + std::variant result; }; verb [[with_client_info, cancellable]] direct_fd_ping (raft::server_id dst_id) -> service::direct_fd_ping_reply; diff --git a/service/raft/group0_fwd.hh b/service/raft/group0_fwd.hh index 815b86abaf..bc42a5c42e 100644 --- a/service/raft/group0_fwd.hh +++ b/service/raft/group0_fwd.hh @@ -75,8 +75,12 @@ struct wrong_destination { raft::server_id reached_id; }; +struct group_liveness_info { + bool group0_alive; +}; + struct direct_fd_ping_reply { - std::variant result; + std::variant result; }; } // namespace service diff --git a/service/raft/raft_group_registry.cc b/service/raft/raft_group_registry.cc index 4b3c9bcc51..3b7f4378f8 100644 --- a/service/raft/raft_group_registry.cc +++ b/service/raft/raft_group_registry.cc @@ -297,15 +297,27 @@ void raft_group_registry::init_rpc_verbs() { // XXX: update address map here as well? if (_my_id != dst) { - co_return direct_fd_ping_reply { + return make_ready_future(direct_fd_ping_reply { .result = wrong_destination { .reached_id = _my_id, }, - }; + }); } - co_return direct_fd_ping_reply { - .result = std::monostate{}, - }; + + return container().invoke_on(0, [] (raft_group_registry& me) -> future { + bool group0_alive = false; + if (me._group0_id) { + auto* group0_server = me.find_server(*me._group0_id); + if (group0_server && group0_server->is_alive()) { + group0_alive = true; + } + } + co_return direct_fd_ping_reply { + .result = service::group_liveness_info{ + .group0_alive = group0_alive, + } + }; + }); }); } @@ -513,6 +525,8 @@ future direct_fd_pinger::ping(direct_failure_detector::pinger::endpoint_id rslog.trace("ping(id = {}, ip_addr = {}): wrong destination (reached {})", dst_id, *addr, wrong_dst->reached_id); co_return false; + } else if (auto* info = std::get_if(&reply.result)) { + co_return info->group0_alive; } } catch (seastar::rpc::closed_error&) { co_return false;