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

Function dispatch_task

nodedb/src/control/server/native/dispatch/sql.rs:256–299  ·  view source on GitHub ↗

Dispatch a single PhysicalTask. Broadcast plans (scans, InsertSelect) are handled locally; all other tasks flow through `dispatch_task_via_gateway` which routes via the gateway when available, or falls back to the local SPSC path on single-node boot.

(ctx: &DispatchCtx<'_>, task: PhysicalTask)

Source from the content-addressed store, hash-verified

254/// flow through `dispatch_task_via_gateway` which routes via the gateway when
255/// available, or falls back to the local SPSC path on single-node boot.
256async fn dispatch_task(ctx: &DispatchCtx<'_>, task: PhysicalTask) -> crate::Result<Response> {
257 if matches!(
258 task.plan,
259 crate::bridge::envelope::PhysicalPlan::Document(
260 nodedb_physical::physical_plan::DocumentOp::InsertSelect { .. }
261 )
262 ) {
263 return broadcast_count_to_all_cores(
264 ctx.state,
265 task.tenant_id,
266 task.plan,
267 TraceId::ZERO,
268 "inserted",
269 )
270 .await;
271 }
272
273 // `DROP ARRAY` fans out to every core so per-core stores are released.
274 if matches!(
275 task.plan,
276 crate::bridge::envelope::PhysicalPlan::Array(
277 nodedb_physical::physical_plan::ArrayOp::DropArray { .. }
278 )
279 ) {
280 return broadcast_count_to_all_cores(
281 ctx.state,
282 task.tenant_id,
283 task.plan,
284 TraceId::ZERO,
285 "dropped",
286 )
287 .await;
288 }
289
290 // Broadcast scans must fan-out to all cores regardless of gateway state.
291 if task.plan.is_broadcast_scan() {
292 return broadcast_to_all_cores(ctx.state, task.tenant_id, task.plan, TraceId::ZERO).await;
293 }
294
295 // All other tasks — point ops, writes, Raft-replicated writes — route
296 // through the gateway when available (cluster-aware routing + retry),
297 // or via the local SPSC path when the gateway is not yet wired.
298 dispatch_task_via_gateway(ctx, task).await
299}
300
301// ─── SET / SHOW / RESET (SQL form) ─────────────────────────────────
302

Callers 1

execute_plannedFunction · 0.85

Calls 4

broadcast_to_all_coresFunction · 0.85
is_broadcast_scanMethod · 0.80

Tested by

no test coverage detected