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

Function spawn_background_loops

nodedb/src/bootstrap/background_loops.rs:67–328  ·  view source on GitHub ↗
(
    shared: &Arc<SharedState>,
    components: EventPlaneComponents,
    config: &ServerConfig,
    num_cores: usize,
    shutdown_rx: tokio::sync::watch::Receiver<bool>,
)

Source from the content-addressed store, hash-verified

65/// loses every WriteEvent emitted by the Data Plane until process exit.
66#[must_use = "EventPlane must be held for the server's lifetime; dropping it stops all event consumers"]
67pub fn spawn_background_loops(
68 shared: &Arc<SharedState>,
69 components: EventPlaneComponents,
70 config: &ServerConfig,
71 num_cores: usize,
72 shutdown_rx: tokio::sync::watch::Receiver<bool>,
73) -> crate::event::EventPlane {
74 let EventPlaneComponents {
75 wal,
76 event_consumers,
77 watermark_store,
78 trigger_dlq,
79 } = components;
80 // Mirror restart: enumerate databases that need observer links re-established
81 // and log the decisions. The cluster layer processes these asynchronously
82 // via the mirror_link_registry once QUIC transport is available.
83 log_mirror_restart_decisions(shared);
84
85 // Event trigger processor.
86 crate::control::event_trigger::spawn_event_trigger_processor(Arc::clone(shared));
87
88 // Mirror lag monitor (5-second interval).
89 // Reads `_system.mirror_lag` for every active mirror and updates
90 // the `nodedb_database_mirror_lag_ms` metric. Also drives status
91 // transitions (Following → Degraded → Disconnected) and clears the
92 // metric when a mirror is promoted.
93 {
94 let shared_mirror = Arc::clone(shared);
95 crate::control::shutdown::spawn_loop(
96 &shared.loop_registry,
97 &shared.shutdown,
98 "mirror_lag_monitor",
99 move |mut shutdown| async move {
100 let mut tick = tokio::time::interval(Duration::from_secs(5));
101 loop {
102 tokio::select! {
103 _ = shutdown.wait_cancelled() => break,
104 _ = tick.tick() => {}
105 }
106 if shutdown.is_cancelled() {
107 break;
108 }
109 let catalog = match shared_mirror.credentials.catalog() {
110 Some(c) => c,
111 None => continue,
112 };
113 let databases = match catalog.list_databases() {
114 Ok(d) => d,
115 Err(e) => {
116 tracing::warn!(error = %e, "mirror_lag_monitor: catalog list error");
117 continue;
118 }
119 };
120 for db in databases {
121 let origin = match db.mirror_origin.as_ref() {
122 Some(o) => o,
123 None => continue,
124 };

Callers 1

mainFunction · 0.85

Calls 15

spawn_loopFunction · 0.85
update_lag_statusFunction · 0.85
spawn_collection_gcFunction · 0.85
spawn_l2_cleanupFunction · 0.85
spawn_idle_sweep_loopFunction · 0.85
spawn_checkpoint_taskFunction · 0.85
spawn_flush_taskFunction · 0.85
run_scheduled_sweepFunction · 0.85
spawn_cold_tier_taskFunction · 0.85
is_cancelledMethod · 0.80

Tested by

no test coverage detected