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/document/events.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/document/events.rs') diff --git a/src/document/events.rs b/src/document/events.rs index 1079999..37f1c70 100644 --- a/src/document/events.rs +++ b/src/document/events.rs @@ -179,6 +179,30 @@ pub(crate) fn checkpoint(doc: &impl ReadDoc) -> Option> { } } +/// Writes into `write`, a remake's snapshot, the store it holds (`docs/store.md`, +/// Remakes): `checkpoint`, where it isn't the root, at `_continuum/checkpoint`, and +/// `events`, each at its ID, in the order of their IDs; all as bytes. +pub(crate) fn snapshot( + write: &mut impl super::Transactable, + checkpoint: Option<&[u8]>, + events: &std::collections::BTreeMap>, +) -> Result<(), store::StoreError> { + let bytes = |bytes: &[u8]| Val::Scalar(ScalarValue::Bytes(bytes.to_vec())); + let writing = || store::Writing::sticky(TimestampFormat::default()); + if let Some(checkpoint) = checkpoint { + store::write_val_path( + write, + &meta::path(&[meta::CHECKPOINT]), + &bytes(checkpoint), + writing(), + )?; + } + for (id, event) in events { + store::write_val_path(write, &self::event(id), &bytes(event), writing())?; + } + Ok(()) +} + /// The ID of the store `doc` holds, its swarm's, where it holds one. pub(crate) fn swarm(doc: &impl ReadDoc) -> Option { match store::read_plain(doc, &meta::path(&[meta::SWARM])) { -- cgit v1.3.1