aboutsummaryrefslogtreecommitdiffstats
path: root/src/remake
diff options
context:
space:
mode:
Diffstat (limited to 'src/remake')
-rw-r--r--src/remake/catchup.rs2
-rw-r--r--src/remake/coordinator.rs4
-rw-r--r--src/remake/mod.rs5
-rw-r--r--src/remake/records.rs2
-rw-r--r--src/remake/snapshot.rs42
-rw-r--r--src/remake/switch.rs4
6 files changed, 59 insertions, 0 deletions
diff --git a/src/remake/catchup.rs b/src/remake/catchup.rs
index 68fa117..35add67 100644
--- a/src/remake/catchup.rs
+++ b/src/remake/catchup.rs
@@ -753,6 +753,8 @@ mod tests {
kind: "compact",
content: None,
translation: &JsonValue::Null,
+ #[cfg(feature = "federation")]
+ held: None,
},
)
.unwrap();
diff --git a/src/remake/coordinator.rs b/src/remake/coordinator.rs
index 0d7a434..a235308 100644
--- a/src/remake/coordinator.rs
+++ b/src/remake/coordinator.rs
@@ -234,6 +234,10 @@ async fn commit<H: Host>(host: &H, id: &str, record: &Record) -> Result<(), Stor
};
let base_heads = fixed_now.then(|| records::encode_heads(&request.base_heads));
request.content = content;
+ #[cfg(feature = "federation")]
+ {
+ request.held = snapshot::Held(Some(host.holding()));
+ }
let snapshot = match snapshot::build_detached(copy, request).await {
Ok((snapshot, _copy)) => snapshot,
Err(error) => {
diff --git a/src/remake/mod.rs b/src/remake/mod.rs
index 9891760..bd814da 100644
--- a/src/remake/mod.rs
+++ b/src/remake/mod.rs
@@ -212,6 +212,11 @@ pub(crate) trait Host: Clone + Send + Sync + 'static {
/// This node's ID (its peers know it by this).
fn node_id(&self) -> String;
+ /// What this node holds of its store, where its swarm holds one
+ /// (`federation::held`).
+ #[cfg(feature = "federation")]
+ fn holding(&self) -> Arc<crate::federation::held::Holding>;
+
/// The epoch of the local replica.
fn current_epoch(&self) -> Epoch;
diff --git a/src/remake/records.rs b/src/remake/records.rs
index 21cf0ae..22aaee3 100644
--- a/src/remake/records.rs
+++ b/src/remake/records.rs
@@ -314,6 +314,8 @@ impl Record {
kind: self.proposal.kind.clone(),
content: None,
translation: self.proposal.translation.clone(),
+ #[cfg(feature = "federation")]
+ held: Default::default(),
})
}
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<std::sync::Arc<crate::federation::held::Holding>>);
+
+#[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<std::sync::Arc<Vec<u8>>>,
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,
}
}
diff --git a/src/remake/switch.rs b/src/remake/switch.rs
index df3fcc8..94956f6 100644
--- a/src/remake/switch.rs
+++ b/src/remake/switch.rs
@@ -189,6 +189,10 @@ async fn switch<H: Host>(
if let Some(reference) = &record.proposal.content {
request.content = Some(content::ensure(host, reference).await?);
}
+ #[cfg(feature = "federation")]
+ {
+ request.held = super::snapshot::Held(Some(host.holding()));
+ }
let translator = request
.translator()
.ok_or_else(|| format!("unknown remake kind {:?}", request.kind))?;