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.
This commit is contained in:
Michael Litvak
2026-03-09 16:24:47 +01:00
parent 5f8322a820
commit 80bfc445a8

View File

@@ -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<raft_server::need_wait_for_leader>(&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);
});
});