#[non_exhaustive]pub enum ReadRouting {
Any,
Primary,
Replica {
max_lag_ms: Option<u64>,
},
}Expand description
Where one compiled query’s reads may be served from.
§Why this exists as a schema field
Read-replica routing is otherwise a whole-server decision: the pin window and the staleness budget apply to every query alike, so an operator sizing them for the strictest query gives up the offload on all the others, and sizing them for the common case silently serves the strict one stale. A per-query override is the only way to have both.
§The contract
FraiseQL defines and enforces this shape; an authoring language emits it.
A @reads_from(...) directive is one spelling
of it, and the spelling is that project’s to choose — what is fixed here is
what the runtime can actually guarantee, which is exactly these three
answers. Replica topology deliberately stays out: URLs are server
configuration and secrets, not compiled schema.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Any
Server policy decides: replicas when configured and eligible, primary inside the read-your-writes pin window or when no replica qualifies.
The default, and what every query did before this field existed.
Primary
Never serve this query from a replica.
For reads where staleness is a correctness problem rather than a performance trade — a balance before a transfer, an authorization decision, the row a client is about to act on.
Also bypasses the result cache. A cached row is stale data by
construction, so a query that asked not to be served stale from a replica
and was then served stale from memory would have got the opposite of what
it asked for. Primary means “fresh”, not “from a particular host”.
Replica
Prefer a replica even inside the read-your-writes pin window, optionally under a tighter (or looser) staleness budget than the server’s.
For reads that are explicitly allowed to be behind — feeds, dashboards, exports — where paying primary capacity for freshness nobody needs is the waste worth naming.
Still falls back to the primary when no replica qualifies: this is a statement about which server should answer, and refusing to answer at all would turn a capacity preference into an outage.
Fields
max_lag_ms: Option<u64>Staleness budget for this query alone, in milliseconds.
None uses the server’s read_replica_max_lag_ms. A value here
replaces it rather than intersecting with it — a query that knows it
tolerates ten minutes is as legitimate as one that needs 50 ms, and
both are the schema author’s call.
A budget on a server with no measurement configured is still honoured: probing is unconditional, so the reading exists whether or not the server set a global budget.
Implementations§
Source§impl ReadRouting
impl ReadRouting
Sourcepub const fn is_default(&self) -> bool
pub const fn is_default(&self) -> bool
Whether this is Any — the serde skip predicate, so a schema
that never mentions routing round-trips byte-identically.
Sourcepub const fn allows_replica(&self) -> bool
pub const fn allows_replica(&self) -> bool
Whether a replica may serve this query at all.
Sourcepub const fn honours_write_pin(&self) -> bool
pub const fn honours_write_pin(&self) -> bool
Whether the read-your-writes pin window applies to this query.
Replica opts out of it: the pin exists so a client
reads its own writes, and a query annotated as tolerating staleness has
said that is not what it is for.
Sourcepub const fn allows_cached_result(&self) -> bool
pub const fn allows_cached_result(&self) -> bool
Whether a result-cache hit may serve this query.
See Primary for why it may not.
Trait Implementations§
Source§impl Clone for ReadRouting
impl Clone for ReadRouting
Source§fn clone(&self) -> ReadRouting
fn clone(&self) -> ReadRouting
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ReadRouting
Source§impl Debug for ReadRouting
impl Debug for ReadRouting
Source§impl Default for ReadRouting
impl Default for ReadRouting
Source§fn default() -> ReadRouting
fn default() -> ReadRouting
Source§impl<'de> Deserialize<'de> for ReadRouting
impl<'de> Deserialize<'de> for ReadRouting
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ReadRouting, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ReadRouting, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for ReadRouting
Source§impl PartialEq for ReadRouting
impl PartialEq for ReadRouting
Source§impl Serialize for ReadRouting
impl Serialize for ReadRouting
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for ReadRouting
Auto Trait Implementations§
impl Freeze for ReadRouting
impl RefUnwindSafe for ReadRouting
impl Send for ReadRouting
impl Sync for ReadRouting
impl Unpin for ReadRouting
impl UnsafeUnpin for ReadRouting
impl UnwindSafe for ReadRouting
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.