Spawn the Event Plane: one consumer Tokio task per Data Plane core. On startup, each consumer loads its persisted watermark and replays WAL entries from that point forward. `consumers_rx` must have exactly one entry per core, in core-ID order. `shutdown` is the node-wide [`ShutdownWatch`] from `SharedState`. All Event Plane subsystems subscribe to this watch instead of a private channel, so the
(
consumers_rx: Vec<EventConsumerRx>,
wal: Arc<WalManager>,
watermark_store: Arc<WatermarkStore>,
shared_state: Arc<SharedState>,
trigger_dlq: Arc<std::sync::Mu
| 49 | /// private channel, so the unified shutdown bus controls all drain |
| 50 | /// signalling. |
| 51 | pub fn spawn( |
| 52 | consumers_rx: Vec<EventConsumerRx>, |
| 53 | wal: Arc<WalManager>, |
| 54 | watermark_store: Arc<WatermarkStore>, |
| 55 | shared_state: Arc<SharedState>, |
| 56 | trigger_dlq: Arc<std::sync::Mutex<TriggerDlq>>, |
| 57 | cdc_router: Arc<CdcRouter>, |
| 58 | shutdown: Arc<ShutdownWatch>, |
| 59 | ) -> Self { |
| 60 | let num_cores = consumers_rx.len(); |
| 61 | |
| 62 | let slab_budget = Arc::new(super::slab_budget::SlabBudget::for_cores(num_cores)); |
| 63 | let mut slab_accounts: Vec<Arc<super::slab_budget::ConsumerSlabAccount>> = Vec::new(); |
| 64 | |
| 65 | let consumers: Vec<ConsumerHandle> = consumers_rx |
| 66 | .into_iter() |
| 67 | .enumerate() |
| 68 | .map(|(i, rx)| { |
| 69 | let account = Arc::new(super::slab_budget::ConsumerSlabAccount::new(i)); |
| 70 | slab_accounts.push(Arc::clone(&account)); |
| 71 | spawn_consumer(ConsumerConfig { |
| 72 | rx, |
| 73 | shutdown: shutdown.raw_receiver(), |
| 74 | wal: Arc::clone(&wal), |
| 75 | watermark_store: Arc::clone(&watermark_store), |
| 76 | shared_state: Arc::clone(&shared_state), |
| 77 | trigger_dlq: Arc::clone(&trigger_dlq), |
| 78 | cdc_router: Arc::clone(&cdc_router), |
| 79 | num_cores, |
| 80 | slab_account: account, |
| 81 | }) |
| 82 | }) |
| 83 | .collect(); |
| 84 | |
| 85 | // Spawn periodic slab budget enforcement (every 5s). |
| 86 | { |
| 87 | let budget = Arc::clone(&slab_budget); |
| 88 | let accounts = slab_accounts.clone(); |
| 89 | let mut shutdown_rx = shutdown.raw_receiver(); |
| 90 | let slab_budget_handle = tokio::spawn(async move { |
| 91 | loop { |
| 92 | tokio::select! { |
| 93 | _ = tokio::time::sleep(std::time::Duration::from_secs(5)) => { |
| 94 | let refs: Vec<&super::slab_budget::ConsumerSlabAccount> = |
| 95 | accounts.iter().map(|a| a.as_ref()).collect(); |
| 96 | budget.check_and_shed(&refs); |
| 97 | } |
| 98 | _ = shutdown_rx.changed() => { |
| 99 | if *shutdown_rx.borrow() { return; } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | }); |
| 104 | let _ = shared_state.loop_registry.register( |
| 105 | "event_plane::slab_budget", |
| 106 | crate::control::shutdown::LoopHandle::Async(slab_budget_handle), |
| 107 | ); |
| 108 | } |