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

Method spawn

nodedb/src/event/plane.rs:51–230  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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 }

Callers 11

spawn_coreFunction · 0.45
execute_ts_aggregateMethod · 0.45
scan_partitions_parallelFunction · 0.45
parallel_mapFunction · 0.45
parallel_reduceFunction · 0.45
try_spawnMethod · 0.45
spawn_and_waitFunction · 0.45

Calls 15

spawn_consumerFunction · 0.85
spawn_schedulerFunction · 0.85
spawn_enforcement_loopFunction · 0.85
spawn_alert_eval_loopFunction · 0.85
spawn_compaction_taskFunction · 0.85
spawn_persist_taskFunction · 0.85
spawn_dispatcher_taskFunction · 0.85
set_origin_peer_idFunction · 0.85
collectMethod · 0.80
raw_receiverMethod · 0.80