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

Method dispatch

nodedb/src/bridge/dispatch.rs:275–350  ·  view source on GitHub ↗

Dispatch a request to the correct Data Plane core. Enqueues into the per-core weighted-fair queue keyed by `DatabaseId`, then flushes WFQ → physical ring. Returns `Err` when the WFQ itself is full (total capacity reached across all active databases on that core).

(&mut self, request: envelope::Request)

Source from the content-addressed store, hash-verified

273 /// then flushes WFQ → physical ring. Returns `Err` when the WFQ itself is
274 /// full (total capacity reached across all active databases on that core).
275 pub fn dispatch(&mut self, request: envelope::Request) -> crate::Result<()> {
276 let tenant_id = request.tenant_id.as_u64();
277 let req_id = request.request_id.as_u64();
278 let database_id = request.database_id.as_u64();
279
280 // Per-tenant fairness: reject if this tenant has too many in-flight requests.
281 if self.max_per_tenant_inflight > 0 {
282 let inflight = self.tenant_inflight.get(&tenant_id).copied().unwrap_or(0);
283 if inflight >= self.max_per_tenant_inflight {
284 return Err(crate::Error::Dispatch {
285 detail: format!(
286 "tenant {tenant_id}: queue full ({inflight}/{} in-flight)",
287 self.max_per_tenant_inflight
288 ),
289 });
290 }
291 }
292
293 let core_id =
294 self.router
295 .resolve(request.vshard_id)
296 .ok_or_else(|| crate::Error::Dispatch {
297 detail: format!("no core for vshard {}", request.vshard_id),
298 })?;
299
300 let channel = &mut self.cores[core_id];
301
302 // Refresh priority for this DB in the WFQ.
303 let cls = self.priority_resolver.priority_for(database_id);
304 channel.wfq.set_priority(database_id, cls);
305
306 // Check per-DB suspended state (≥95% of fair share).
307 if channel.wfq.is_suspended_for(database_id) {
308 return Err(crate::Error::Dispatch {
309 detail: format!(
310 "database {database_id}: virtual queue suspended (≥95% of fair share on core {core_id})"
311 ),
312 });
313 }
314
315 // Enqueue into the WFQ — returns Err if total capacity is full.
316 channel
317 .wfq
318 .try_enqueue(database_id, request)
319 .map_err(|_| crate::Error::Dispatch {
320 detail: format!("core {core_id}: total WFQ capacity exhausted"),
321 })?;
322
323 // Update per-DB pressure.
324 channel.update_db_pressure(database_id);
325
326 // Flush WFQ → physical ring.
327 channel.flush_wfq();
328
329 // Update global backpressure based on ring utilization.
330 let util = channel.request_tx.utilization();
331 if let Some(new_state) = channel.backpressure.update(util) {
332 warn!(

Callers 15

execute_plan_innerMethod · 0.45
dispatch_localFunction · 0.45
apply_array_opFunction · 0.45
ensure_array_openFunction · 0.45
perform_kv_clone_copyupFunction · 0.45
perform_clone_copyupFunction · 0.45
handle_frameMethod · 0.45
submit_to_data_planeMethod · 0.45
dispatch_data_plane_rawFunction · 0.45

Calls 14

priority_forMethod · 0.80
set_priorityMethod · 0.80
is_suspended_forMethod · 0.80
try_enqueueMethod · 0.80
update_db_pressureMethod · 0.80
flush_wfqMethod · 0.80
entryMethod · 0.80
as_u64Method · 0.45
getMethod · 0.45
resolveMethod · 0.45
utilizationMethod · 0.45
updateMethod · 0.45

Tested by 4

response_roundtripFunction · 0.36
full_queue_returns_errorFunction · 0.36
per_db_pressure_reportedFunction · 0.36