From c2f47d6f4cb37d482eddf9e2c31e40161c4111de Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 03:30:43 +0000 Subject: remake: a holding swarm's snapshot holds the store read at its base A compaction's snapshot in a swarm holding a store holds the store as the node reads it from the document at the base, by its own refusals and its operator's drops (`docs/store.md`, Remakes): the checkpoint it reaches there, where it isn't the root, at `_continuum/checkpoint`; the root, the events that checkpoint keeps and those after it, each at its ID; and of the entries, the members'. What the checkpoint forgot, events nobody takes, and the entries of nodes that aren't members stay behind (`Holding::at_base`, `events::snapshot`, `Host::holding`). --- src/remake/snapshot.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/remake/snapshot.rs') diff --git a/src/remake/snapshot.rs b/src/remake/snapshot.rs index fa1fa39..0c3b658 100644 --- a/src/remake/snapshot.rs +++ b/src/remake/snapshot.rs @@ -52,6 +52,22 @@ pub(crate) struct SnapshotParams<'a> { pub(crate) content: Option<&'a [u8]>, /// The kind's translation input; recorded in the epoch metadata. pub(crate) translation: &'a JsonValue, + /// The node's store, where its swarm holds one: the snapshot holds it as the node + /// reads it at the base (`Holding::at_base`). + #[cfg(feature = "federation")] + pub(crate) held: Option<&'a crate::federation::held::Holding>, +} + +/// The node's store, for a snapshot request (`SnapshotParams::held`). +#[cfg(feature = "federation")] +#[derive(Clone, Default)] +pub(crate) struct Held(pub(crate) Option>); + +#[cfg(feature = "federation")] +impl std::fmt::Debug for Held { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(if self.0.is_some() { "Held" } else { "None" }) + } } pub(crate) struct Snapshot { @@ -96,6 +112,8 @@ pub(crate) struct SnapshotRequest { pub(crate) kind: String, pub(crate) content: Option>>, pub(crate) translation: JsonValue, + #[cfg(feature = "federation")] + pub(crate) held: Held, } impl SnapshotRequest { @@ -110,6 +128,8 @@ impl SnapshotRequest { kind: &self.kind, content: self.content.as_deref().map(Vec::as_slice), translation: &self.translation, + #[cfg(feature = "federation")] + held: self.held.0.as_deref(), } } @@ -369,6 +389,9 @@ pub(crate) fn build( let base = source.fork_at(params.base_heads)?; let clock = clock_of(&base); + // A swarm holding a store: the store as the node reads it there. + #[cfg(feature = "federation")] + let held = params.held.and_then(|held| held.at_base(&base)); let generation = params.previous.generation + 1; let kind = @@ -395,8 +418,25 @@ pub(crate) fn build( .into_iter() .filter(|key| key != REMAKES && key != VOTES && key != EPOCHS) { + #[cfg(feature = "federation")] + if held.is_some() && [meta::EVENTS, meta::CHECKPOINT, meta::MEMBERS].contains(&key.as_str()) + { + continue; + } store::copy_path(&base, &mut target, &meta::path(&[key.as_str()]))?; } + // Of the store, its checkpoint, what that keeps and what came after; of the entries, + // the members'. What the checkpoint forgot, and events nobody takes, stay behind. + #[cfg(feature = "federation")] + if let Some(held) = &held { + crate::document::events::snapshot(&mut target, held.checkpoint.as_deref(), &held.events)?; + for node in &held.members { + let entry = meta::path(&[meta::MEMBERS, node]); + if store::read_path(&base, &entry)?.is_some() { + store::copy_path(&base, &mut target, &entry)?; + } + } + } // Earlier epochs' metadata as the base's epoch built it, whatever was written there // since (with no policy, a member's own change could): copied from there, and judged // there which to leave out. The first epoch follows none and carries none. @@ -533,6 +573,8 @@ mod tests { kind: "compact", content: None, translation: &NULL, + #[cfg(feature = "federation")] + held: None, } } -- cgit v1.3.1