Dispatch a request directly to a specific core by index. Bypasses vShard routing. Used by the checkpoint manager to send checkpoint requests to every core regardless of vShard assignment.
(
&mut self,
core_id: usize,
request: envelope::Request,
)
| 369 | /// Bypasses vShard routing. Used by the checkpoint manager to send |
| 370 | /// checkpoint requests to every core regardless of vShard assignment. |
| 371 | pub fn dispatch_to_core( |
| 372 | &mut self, |
| 373 | core_id: usize, |
| 374 | request: envelope::Request, |
| 375 | ) -> crate::Result<()> { |
| 376 | if core_id >= self.cores.len() { |
| 377 | return Err(crate::Error::Dispatch { |
| 378 | detail: format!("core {core_id} out of range (have {})", self.cores.len()), |
| 379 | }); |
| 380 | } |
| 381 | |
| 382 | let tenant_id = request.tenant_id.as_u64(); |
| 383 | let req_id = request.request_id.as_u64(); |
| 384 | let database_id = request.database_id.as_u64(); |
| 385 | let channel = &mut self.cores[core_id]; |
| 386 | |
| 387 | let cls = self.priority_resolver.priority_for(database_id); |
| 388 | channel.wfq.set_priority(database_id, cls); |
| 389 | |
| 390 | channel |
| 391 | .wfq |
| 392 | .try_enqueue(database_id, request) |
| 393 | .map_err(|_| crate::Error::Dispatch { |
| 394 | detail: format!("core {core_id}: total WFQ capacity exhausted"), |
| 395 | })?; |
| 396 | |
| 397 | channel.update_db_pressure(database_id); |
| 398 | channel.flush_wfq(); |
| 399 | |
| 400 | let util = channel.request_tx.utilization(); |
| 401 | if let Some(new_state) = channel.backpressure.update(util) { |
| 402 | warn!( |
| 403 | core_id, |
| 404 | utilization = util, |
| 405 | state = ?new_state, |
| 406 | "backpressure transition" |
| 407 | ); |
| 408 | } |
| 409 | |
| 410 | *self.tenant_inflight.entry(tenant_id).or_insert(0) += 1; |
| 411 | self.request_tenant.insert(req_id, tenant_id); |
| 412 | |
| 413 | if let Some(ref notifier) = channel.wake_notifier { |
| 414 | notifier.notify(); |
| 415 | } |
| 416 | |
| 417 | Ok(()) |
| 418 | } |
| 419 | |
| 420 | /// Maximum SPSC request queue utilization across all cores (0-100). |
| 421 | pub fn max_utilization(&self) -> u8 { |