Diffinery

homeflare/celldpublic

celld/crates/logic/dead_node_reconciliation.rs
43 lines · 1.7 KBRaw History
1//! Sans-I/O decisions for retiring compatibility ownership-index debris.
2//!
3//! celld does not create `node-cells/` markers, but it shares fleet buckets
4//! with celld and must retire markers left by dead historical generations.
5
6const MAX_BACKOFF_SHIFT: u32 = 6;
7
8/// Delay after `failure_count` consecutive incomplete passes.
9///
10/// Counts start at one and double through 64 ordinary waker ticks. Saturating
11/// arithmetic keeps a damaged store from turning reconciliation into a tight
12/// retry loop even at extreme configured intervals.
13pub fn retry_delay_ms(tick_ms: u64, failure_count: u32) -> u64 {
14 let shift = failure_count.saturating_sub(1).min(MAX_BACKOFF_SHIFT);
15 tick_ms.saturating_mul(1_u64 << shift)
16}
17
18/// Parse `node-cells/<node>/<generation>/<cell>` into its GC identity.
19///
20/// The generation is deliberately discarded. Once a node session is dead,
21/// every generation below its prefix is debris; matching only the generation
22/// named by the final node record permanently strands overlapping older
23/// generations after a same-ID restart.
24pub fn parse_marker_key(key: &str) -> Option<(&str, &str)> {
25 let rest = key.strip_prefix("node-cells/")?;
26 let mut parts = rest.splitn(3, '/');
27 let (node, generation, cell) = (parts.next()?, parts.next()?, parts.next()?);
28 if node.is_empty() || generation.is_empty() || cell.is_empty() {
29 return None;
30 }
31 Some((node, cell))
32}
33
34/// A listed node record is GC-eligible only when its identity still matches
35/// its object key and its wall-clock lease is no longer live.
36pub fn node_record_is_dead(
37 key_node: &str,
38 record_node: &str,
39 expires_ms: u64,
40 now_ms: u64,
41) -> bool {
42 key_node == record_node && expires_ms <= now_ms
43}