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

Function run_sweep_loop

nodedb-cluster/src/ghost_sweeper.rs:48–103  ·  view source on GitHub ↗

Run the ghost sweeper as a blocking loop (call from a dedicated thread or tokio::spawn_blocking). Sweeps all ghost tables periodically. `ghost_tables` is a map of vshard_id → GhostTable. Each vShard on this node has its own ghost table tracking migrated-away nodes. `verify_fn` checks whether a ghost should be purged by querying the target shard. In single-node mode, this always returns `Purge` (

(
    ghost_tables: Arc<Mutex<Vec<(u32, GhostTable)>>>,
    config: GhostSweeperConfig,
    verify_fn: V,
    shutdown: Arc<std::sync::atomic::AtomicBool>,
)

Source from the content-addressed store, hash-verified

46/// target shard. In single-node mode, this always returns `Purge` (no
47/// remote shards to check). In cluster mode, it sends an RPC.
48pub fn run_sweep_loop<V>(
49 ghost_tables: Arc<Mutex<Vec<(u32, GhostTable)>>>,
50 config: GhostSweeperConfig,
51 verify_fn: V,
52 shutdown: Arc<std::sync::atomic::AtomicBool>,
53) where
54 V: Fn(&str, u32) -> SweepVerdict + Send + 'static,
55{
56 info!(
57 interval_secs = config.interval.as_secs(),
58 "ghost sweeper started"
59 );
60
61 loop {
62 std::thread::sleep(config.interval);
63
64 if shutdown.load(std::sync::atomic::Ordering::Relaxed) {
65 info!("ghost sweeper shutting down");
66 break;
67 }
68
69 let mut tables = match ghost_tables.lock() {
70 Ok(t) => t,
71 Err(poisoned) => poisoned.into_inner(),
72 };
73
74 let mut total_purged = 0;
75 let mut total_checked = 0;
76
77 for (vshard_id, table) in tables.iter_mut() {
78 if table.is_empty() {
79 continue;
80 }
81 let report = table.sweep(|node_id, target_shard| verify_fn(node_id, target_shard));
82 total_purged += report.purged;
83 total_checked += report.checked;
84
85 if report.purged > 0 {
86 debug!(
87 vshard = vshard_id,
88 purged = report.purged,
89 remaining = table.len(),
90 "ghost sweep for vshard"
91 );
92 }
93 }
94
95 if total_checked > 0 {
96 info!(
97 checked = total_checked,
98 purged = total_purged,
99 "ghost sweep cycle complete"
100 );
101 }
102 }
103}
104
105#[cfg(test)]

Callers

nothing calls this directly

Calls 5

lockMethod · 0.80
iter_mutMethod · 0.80
sweepMethod · 0.80
loadMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected