mirror of
https://github.com/scylladb/scylladb.git
synced 2026-06-03 05:26:58 +00:00
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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -222,6 +222,14 @@ public:
|
||||
};
|
||||
using begin_mutate_result = std::variant<timestamp_with_term, raft::not_a_leader, need_wait_for_leader>;
|
||||
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<ok, raft::not_a_leader, need_wait_for_leader>;
|
||||
begin_read_result begin_read(abort_source&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user