Dispatch a single route and return the raw payload bytes. `tenant_id` — the authenticated tenant for this query. `trace_id` — distributed trace ID propagated from the client request. `deadline_ms` — remaining deadline in milliseconds. `version_set` — descriptor versions for the collections touched by the plan.
(
route: TaskRoute,
shared: &Arc<SharedState>,
tenant_id: TenantId,
database_id: DatabaseId,
trace_id: TraceId,
deadline_ms: u64,
version_set: &GatewayVersionSet,
)
| 37 | /// `deadline_ms` — remaining deadline in milliseconds. |
| 38 | /// `version_set` — descriptor versions for the collections touched by the plan. |
| 39 | pub async fn dispatch_route( |
| 40 | route: TaskRoute, |
| 41 | shared: &Arc<SharedState>, |
| 42 | tenant_id: TenantId, |
| 43 | database_id: DatabaseId, |
| 44 | trace_id: TraceId, |
| 45 | deadline_ms: u64, |
| 46 | version_set: &GatewayVersionSet, |
| 47 | ) -> Result<Vec<Vec<u8>>, Error> { |
| 48 | match route.decision { |
| 49 | RouteDecision::Local => dispatch_local(route, shared, tenant_id, trace_id).await, |
| 50 | RouteDecision::Remote { node_id, vshard_id } => { |
| 51 | dispatch_remote(RemoteDispatchArgs { |
| 52 | plan: route.plan, |
| 53 | shared, |
| 54 | node_id, |
| 55 | vshard_id, |
| 56 | tenant_id, |
| 57 | database_id, |
| 58 | trace_id, |
| 59 | deadline_ms, |
| 60 | version_set, |
| 61 | }) |
| 62 | .await |
| 63 | } |
| 64 | RouteDecision::Broadcast { .. } => { |
| 65 | // Broadcast routes are split into individual Local/Remote routes |
| 66 | // by the router before dispatch. This arm should not be reached. |
| 67 | Err(Error::Internal { |
| 68 | detail: "dispatcher: Broadcast route reached dispatch — should have been split" |
| 69 | .into(), |
| 70 | }) |
| 71 | } |
| 72 | RouteDecision::LeaderUnknown { vshard_id } => { |
| 73 | // Cluster mode with no leader currently known for this vShard. |
| 74 | // Surface as NotLeader so the gateway retry loop sleeps and |
| 75 | // re-resolves the routing table on the next attempt — never |
| 76 | // silently serve from a possibly-stale local replica. |
| 77 | Err(Error::NotLeader { |
| 78 | vshard_id: VShardId::new(vshard_id as u32), |
| 79 | leader_node: 0, |
| 80 | leader_addr: String::new(), |
| 81 | }) |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /// Local dispatch via SPSC bridge. |
| 87 | async fn dispatch_local( |
no test coverage detected