From 1f91524547ca56861ae7d290f011c187d40140d2 Mon Sep 17 00:00:00 2001 From: Wojciech Mitros Date: Tue, 21 Apr 2026 03:26:06 +0200 Subject: [PATCH] strong_consistency: add begin_read() to raft_server Add begin_read() method to raft_server that checks leadership for read operations. Unlike begin_mutate(), it does not need to compute a timestamp or interact with leader_info. It simply checks current_leader() and returns one of three dispositions: - ok: this node is the leader, proceed with read_barrier() locally - raft::not_a_leader: redirect to the indicated leader - need_wait_for_leader: leader unknown, caller must wait and retry This will be used by the read forwarding logic in subsequent commits. --- service/strong_consistency/groups_manager.cc | 11 +++++++++++ service/strong_consistency/groups_manager.hh | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/service/strong_consistency/groups_manager.cc b/service/strong_consistency/groups_manager.cc index c395f0716f..0083ea0dec 100644 --- a/service/strong_consistency/groups_manager.cc +++ b/service/strong_consistency/groups_manager.cc @@ -89,6 +89,17 @@ auto raft_server::begin_mutate(abort_source& as) -> begin_mutate_result { return timestamp_with_term{new_ts, term}; } +auto raft_server::begin_read(abort_source& as) -> begin_read_result { + const auto leader = _state.server->current_leader(); + if (!leader) { + return need_wait_for_leader{_state.server->wait_for_leader(&as)}; + } + if (leader != _state.server->id()) { + return raft::not_a_leader{leader}; + } + return ok{}; +} + groups_manager::groups_manager(netw::messaging_service& ms, raft_group_registry& raft_gr, cql3::query_processor& qp, replica::database& db, service::migration_manager& mm, db::system_keyspace& sys_ks, gms::feature_service& features, diff --git a/service/strong_consistency/groups_manager.hh b/service/strong_consistency/groups_manager.hh index e81de65c75..22734eb850 100644 --- a/service/strong_consistency/groups_manager.hh +++ b/service/strong_consistency/groups_manager.hh @@ -222,6 +222,14 @@ public: }; using begin_mutate_result = std::variant; begin_mutate_result begin_mutate(abort_source&); + + // Possible results: + // ok - this node is the leader, proceed with read_barrier() locally + // raft::not_a_leader - this node is not a leader, redirect to the leader + // need_wait_for_leader - the leader is unknown, the caller needs to wait and retry + struct ok {}; + using begin_read_result = std::variant; + begin_read_result begin_read(abort_source&); }; }