From 80bfc445a8f1a09f083f8675459cd54fe2cda4ca Mon Sep 17 00:00:00 2001 From: Michael Litvak Date: Mon, 9 Mar 2026 16:24:47 +0100 Subject: [PATCH] strong_consistency: wait for leader when starting a group When starting the raft server for a group, wait for the leader before completing the start operation. We want the group to be ready to accept writes by the time the start is reported to be completed without the additional latency of waiting for leader. --- service/strong_consistency/groups_manager.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/service/strong_consistency/groups_manager.cc b/service/strong_consistency/groups_manager.cc index da0ad265c1..bc94a61d01 100644 --- a/service/strong_consistency/groups_manager.cc +++ b/service/strong_consistency/groups_manager.cc @@ -385,7 +385,22 @@ void groups_manager::update(token_metadata_ptr new_tm) { co_await start_raft_group(tablet, id, std::move(new_tm)); state.server = &_raft_gr.get_server(id); state.leader_info_updater = leader_info_updater(state, tablet, id); + + // We want to make sure the server is ready to serve requests before + // we report it as started in wait_for_groups_to_start(). + abort_on_expiry aoe(lowres_clock::now() + std::chrono::seconds(60)); + while (true) { + auto srv = raft_server(state, state.gate->hold()); + auto res = srv.begin_mutate(aoe.abort_source()); + if (auto w = get_if(&res)) { + co_await std::move(w->future); + } else { + break; + } + } + _starting_groups.erase(_starting_groups.iterator_to(state)); + logger.info("update(): raft server for tablet {} and group id {} is started", tablet, id); }); });