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&); }; }