Diffinery

homeflare/celldpublic

celld/crates/logic/restore.rs
29 lines · 1.6 KBRaw History
1// Copyright 2026 Deno Land Inc. Apache-2.0 license.
2
3//! Restore-source durability predicates, reified sans-IO. Activation restores a
4//! cell's SQLite from the newest SAFE source — a local eviction snapshot or
5//! the replicated bucket. Which source is a durability decision: pick a stale
6//! one over a newer replica and the cell serves lost writes; pick a
7//! needlessly-remote one and pay dozens of sequential round trips (measured:
8//! 46, 0 local reuses in 910 activations, before the previous-epoch lookup).
9//! The AVAILABILITY of each source is I/O (file checks, S3 LIST); this
10//! predicate is the pure choice among them.
11//!
12//! Two siblings (`local_epoch_wins`, `recoverable`) guarded the local
13//! crash-epoch restore, a source the external litestream backend needed and
14//! the in-process ltx replicator deliberately does not have: a restart
15//! re-acquires the next epoch from the bucket, so a committed-but-unacked
16//! write is discarded and RPO=0 covers exactly the acknowledged ones. They
17//! were deleted with their mechanism.
18
19pub type Epoch = u64;
20
21/// May an eviction snapshot from the PREVIOUS epoch be reused? Ordinary idle
22/// eviction is followed by an epoch advance, so its cache sits under
23/// `epoch - 1` — safe to reuse only when we did NOT take the cell over from
24/// another node. A takeover means someone else may have written the cell while
25/// we slept, so their newer durable state, not our stale snapshot, is
26/// authoritative. Epoch 1 has no previous epoch.
27pub fn previous_epoch_reusable(epoch: Epoch, took_over: bool) -> bool {
28 epoch > 1 && !took_over
29}