| 1 | //! Retry policy for incomplete dead-node reconciliation passes. |
| 2 | //! |
| 3 | //! Reconciliation may fail because storage is transiently unavailable or |
| 4 | //! because a historical cell is incompatible with the current deployment. |
| 5 | //! Neither case may turn the elected waker into a tight restore loop. The |
| 6 | //! async executor owns timers and deployment-change wakeups; this module owns |
| 7 | //! only the pure, saturating backoff decision. |
| 8 | |
| 9 | const MAX_BACKOFF_SHIFT: u32 = 6; |
| 10 | |
| 11 | /// Delay after `failure_count` consecutive incomplete reconciliation passes. |
| 12 | /// |
| 13 | /// Counts start at one: the first failure waits one ordinary waker tick, then |
| 14 | /// delays double through 64 ticks. A successful pass removes the caller's |
| 15 | /// retry state. |
| 16 | pub fn retry_delay_ms(tick_ms: u64, failure_count: u32) -> u64 { |
| 17 | let shift = failure_count.saturating_sub(1).min(MAX_BACKOFF_SHIFT); |
| 18 | tick_ms.saturating_mul(1_u64 << shift) |
| 19 | } |
| 20 | |
| 21 | /// Parse one `node-cells/<node>/<generation>/<cell>` marker key into its GC |
| 22 | /// identity: the owning node and the indexed cell. The generation component |
| 23 | /// is deliberately discarded — ANY generation under a dead node's prefix is |
| 24 | /// debris. Matching only the node record's current generation permanently |
| 25 | /// strands every superseded generation's markers: a same-ID restart rolls |
| 26 | /// the record, and the old markers become unreachable garbage while the |
| 27 | /// record itself is retired. |
| 28 | pub fn parse_marker_key(key: &str) -> Option<(&str, &str)> { |
| 29 | let rest = key.strip_prefix("node-cells/")?; |
| 30 | let mut parts = rest.splitn(3, '/'); |
| 31 | let (node, generation, cell) = (parts.next()?, parts.next()?, parts.next()?); |
| 32 | if node.is_empty() || generation.is_empty() || cell.is_empty() { |
| 33 | return None; |
| 34 | } |
| 35 | Some((node, cell)) |
| 36 | } |