Diffinery

homeflare/celldpublic

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