Skip to main content

Router

Trait Router 

Source
pub trait Router:
    Send
    + Sync
    + 'static {
    // Required methods
    async fn resolve(&self, ctx: &RequestCtx<'_>) -> Result<Resolved, SpiError>;
    fn resolve_partition(
        &self,
        ctx: &RequestCtx<'_>,
        body: BodyDoc<'_>,
    ) -> Result<PartitionId, SpiError>;
    async fn resolve_placement(
        &self,
        ctx: &RequestCtx<'_>,
        partition: PartitionId,
        logical_index: &str,
    ) -> Result<Resolved, SpiError>;
    async fn admit_write(&self, partition: &PartitionId, epoch: Epoch) -> bool;

    // Provided method
    fn cluster_endpoint(&self, _cluster: &ClusterId) -> Option<String> { ... }
}
Expand description

The partition-aware routing seam the engine pipeline drives.

RoutingSpi yields only a RouteDecision; the engine needs more, the resolved partition (to construct _id/_routing and to demux bulk per document), the epoch and migration phase (the write gate), and a split resolve so a bulk request can resolve the partition per document but cache the placement per partition. This trait captures exactly that contract, so the pipeline is generic over any router that can provide it, not nailed to the concrete TenancyRouter. TenancyRouter is the in-tree implementation.

Required Methods§

Source

async fn resolve(&self, ctx: &RequestCtx<'_>) -> Result<Resolved, SpiError>

Resolves the full routing plan for a single-document request.

§Errors

Returns SpiError if the endpoint is not tenancy-aware, the partition cannot be resolved, no placement exists, or the transforms are invalid.

Source

fn resolve_partition( &self, ctx: &RequestCtx<'_>, body: BodyDoc<'_>, ) -> Result<PartitionId, SpiError>

Resolves just the partition id for a request and document (the bulk demux entry point).

§Errors

Returns SpiError::PartitionUnresolved if no source yields a partition.

Source

async fn resolve_placement( &self, ctx: &RequestCtx<'_>, partition: PartitionId, logical_index: &str, ) -> Result<Resolved, SpiError>

Resolves a known partition to its placement and routing plan.

§Errors

Returns SpiError if no placement exists or the transforms are invalid.

Source

async fn admit_write(&self, partition: &PartitionId, epoch: Epoch) -> bool

The migration write gate: may a write that resolved at epoch for partition still commit? false ⇒ reject as a retryable stale-epoch error.

Provided Methods§

Source

fn cluster_endpoint(&self, _cluster: &ClusterId) -> Option<String>

The base URL of a cluster by id, for the cursor-affinity and admin paths that route by cluster without a placement. Default None.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§