MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / dispatch_route

Function dispatch_route

nodedb/src/control/gateway/dispatcher.rs:39–84  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

37/// `deadline_ms` — remaining deadline in milliseconds.
38/// `version_set` — descriptor versions for the collections touched by the plan.
39pub 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.
87async fn dispatch_local(

Callers 1

Calls 2

dispatch_localFunction · 0.70
dispatch_remoteFunction · 0.70

Tested by

no test coverage detected