mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-30 03:30:49 +00:00
Strongly consistent reads currently call read_barrier() on whichever replica happens to process the request. When a follower runs read_barrier(), it sends an RPC to the leader to get the current read index, then waits for its local apply index to catch up. If the follower is behind, this wait can be significant. By forwarding linearizable reads to the leader, we don't need an RPC from replica to leader to get the index to wait for apply -- it's available locally. Note that read_barrier() is still required on the leader to confirm it is still the leader and guarantee linearizability. A future optimization would be to implement leases in the raft library, which could eliminate read_barrier() on the leader entirely. The CL-to-behavior mapping is isolated in a single parse_consistency_level() function: - CL=(LOCAL_)QUORUM -> linearizable: forwarded to the raft leader - CL=(LOCAL_)ONE -> non-linearizable: existing behavior (no read_barrier()/forwarding, may return stale results) - All other CLs -> invalid request Read forwarding reuses the same CQL-layer bounce_to_node() mechanism that write forwarding already uses. The transport layer's existing requests_forwarded_* metrics automatically count forwarded reads. Coordinator-level metrics (linearizable_reads, non_linearizable_reads, writes) are added for visibility into the strong consistency workload. Fixes: SCYLLADB-1157 Closes scylladb/scylladb#29575 * github.com:scylladb/scylladb: strong_consistency: test read forwarding to leader strong_consistency: skip read_barrier() for non-linearizable reads strong_consistency: split coordinator-level read latency metrics strong_consistency: forward linearizable reads to raft leader strong_consistency: classify reads by consistency level strong_consistency: add begin_read() to raft_server