summaryrefslogtreecommitdiffstats
path: root/src/remake/snapshot.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/remake/snapshot.rs')
-rw-r--r--src/remake/snapshot.rs36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/remake/snapshot.rs b/src/remake/snapshot.rs
index bd99854..e50a2a2 100644
--- a/src/remake/snapshot.rs
+++ b/src/remake/snapshot.rs
@@ -24,17 +24,19 @@
use std::collections::BTreeMap;
-use automerge::{transaction::CommitOptions, ActorId, AutoCommit, ChangeHash};
-use serde_json::{json, Map as JsonMap, Value as JsonValue};
+use automerge::{ActorId, AutoCommit, ChangeHash, transaction::CommitOptions};
+use serde_json::{Map as JsonMap, Value as JsonValue, json};
use sha2::{Digest, Sha256};
-use super::kind::{by_name, RemakeKind, Translator, DEFAULT_KIND};
+use super::kind::{DEFAULT_KIND, RemakeKind, Translator, by_name};
use super::records::{EpochRecord, Policy};
use crate::document::replica::Epoch;
use crate::document::store::{self, StoreError};
pub(crate) const META_ROOT: &str = "_continuum";
pub(crate) const REMAKES: &str = "remakes";
+/// The votes register (`records`).
+pub(crate) const VOTES: &str = "votes";
pub(crate) const EPOCHS: &str = "epochs";
/// Everything that determines a snapshot besides the base content.
@@ -51,8 +53,8 @@ pub(crate) struct SnapshotParams<'a> {
pub(crate) proposed_at: u64,
/// Name of the remake kind, which builds the user content.
pub(crate) kind: &'a str,
- /// The kind's build input, from the proposal.
- pub(crate) content: &'a JsonValue,
+ /// The kind's build input (the proposal's content).
+ pub(crate) content: Option<&'a [u8]>,
/// The kind's translation input; recorded in the epoch metadata.
pub(crate) translation: &'a JsonValue,
}
@@ -92,7 +94,7 @@ pub(crate) struct SnapshotRequest {
pub(crate) policy: JsonValue,
pub(crate) proposed_at: u64,
pub(crate) kind: String,
- pub(crate) content: JsonValue,
+ pub(crate) content: Option<std::sync::Arc<Vec<u8>>>,
pub(crate) translation: JsonValue,
}
@@ -105,7 +107,7 @@ impl SnapshotRequest {
policy: &self.policy,
proposed_at: self.proposed_at,
kind: &self.kind,
- content: &self.content,
+ content: self.content.as_deref().map(Vec::as_slice),
translation: &self.translation,
}
}
@@ -265,15 +267,18 @@ pub(crate) fn build(
kind.build(&base, params.content, &mut snapshot)?;
// Protocol data carries forward, whatever the kind: forget records, earlier epochs'
- // metadata (rejoining nodes need it). Remake records describe the old epoch's
- // protocol and stay behind.
+ // metadata (rejoining nodes need it). Remake records and the votes register describe
+ // the old epoch's protocol and stay behind.
match store::delete_path(&mut snapshot, &[META_ROOT.to_owned()], false) {
Ok(()) | Err(StoreError::NotFound) => {}
Err(error) => return Err(error.into()),
}
let mut protocol_keys = store::keys_at(&base, &[META_ROOT.to_owned()])?;
protocol_keys.sort();
- for key in protocol_keys.into_iter().filter(|key| key != REMAKES) {
+ for key in protocol_keys
+ .into_iter()
+ .filter(|key| key != REMAKES && key != VOTES)
+ {
store::copy_path(&base, &mut snapshot, &[META_ROOT.to_owned(), key])?;
}
@@ -353,7 +358,7 @@ pub(super) fn canonical(value: JsonValue) -> JsonValue {
#[cfg(test)]
mod tests {
use super::*;
- use automerge::{transaction::Transactable, ObjType, ReadDoc, ScalarValue, Value, ROOT};
+ use automerge::{ObjType, ROOT, ReadDoc, ScalarValue, Value, transaction::Transactable};
fn doc(actor: &[u8]) -> AutoCommit {
AutoCommit::new().with_actor(ActorId::from(actor))
@@ -367,7 +372,7 @@ mod tests {
policy,
proposed_at: 0,
kind: "compact",
- content: &NULL,
+ content: None,
translation: &NULL,
}
}
@@ -526,6 +531,12 @@ mod tests {
.unwrap();
store::write_path(
&mut a,
+ &[META_ROOT.into(), VOTES.into(), "pk".into()],
+ &json!({ "remake": "c-1", "at": 1 }),
+ )
+ .unwrap();
+ store::write_path(
+ &mut a,
&[META_ROOT.into(), "forgotten".into(), "pk".into()],
&json!({ "at": 1 }),
)
@@ -540,6 +551,7 @@ mod tests {
.unwrap()
.unwrap();
assert!(meta.get(REMAKES).is_none());
+ assert!(meta.get(VOTES).is_none());
assert_eq!(meta["forgotten"]["pk"]["at"], json!(1));
let epoch = &meta[EPOCHS]["1"];