diff options
Diffstat (limited to 'src/remake/catchup.rs')
| -rw-r--r-- | src/remake/catchup.rs | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/remake/catchup.rs b/src/remake/catchup.rs index e265d0b..695e4d7 100644 --- a/src/remake/catchup.rs +++ b/src/remake/catchup.rs @@ -31,7 +31,7 @@ use std::collections::{BTreeMap, HashMap}; use std::convert::Infallible; use std::time::Duration; -use automerge::{ActorId, AutoCommit, ChangeHash}; +use crate::document::{ActorId, ChangeHash, Document, ReadDoc}; use tokio::time::Instant; use tracing::{debug, error, info, warn}; @@ -181,7 +181,7 @@ async fn start<H: Host>(host: &H, local: Epoch, target: Epoch, attempts: u32) { host.remake().add_own_actor(actor.clone()); let old = match host .switch_epoch(target, move |_live| { - Ok::<_, Infallible>(AutoCommit::new().with_actor(actor)) + Ok::<_, Infallible>(Document::new().with_actor(actor)) }) .await { @@ -218,9 +218,7 @@ async fn fetch_snapshot<H: Host>(host: H, target: Epoch) { if still_rejoining { match outcome { Ok(change) => { - let applied = host - .commit_doc(move |doc| doc.apply_changes([change])) - .await; + let applied = host.apply_change(change).await; match applied { Ok(()) => { info!(epoch = %target, "Applied the epoch's snapshot; syncing the changes made since") @@ -258,10 +256,10 @@ enum Plan { #[allow(clippy::large_enum_variant)] enum Prepared { /// Caught up with someone, but not with the target epoch yet: keep waiting. - NotYet(AutoCommit), - Failed(AutoCommit, String), + NotYet(Document), + Failed(Document, String), Ready { - old: AutoCommit, + old: Document, metadata: EpochMetadata, plan: Plan, own_missing: usize, @@ -411,8 +409,8 @@ async fn finish<H: Host>(host: &H) { /// `own`: this node's actors (`RemakeState::own_actors`); the old document's own actor /// counts in any case. `now`: Unix milliseconds, by the node's clock. fn prepare( - mut copy: AutoCommit, - mut old: AutoCommit, + copy: Document, + old: Document, previous: Epoch, target: Epoch, mut own: Vec<ActorId>, @@ -421,7 +419,7 @@ fn prepare( if copy.get_change_by_hash(&ChangeHash(target.id)).is_none() { return Prepared::NotYet(old); } - let metadata = match snapshot::verify_document(&mut copy, target) { + let metadata = match snapshot::verify_document(©, target) { Ok(metadata) => metadata, Err(reason) => return Prepared::Failed(old, reason), }; @@ -447,7 +445,7 @@ fn prepare( let clock = next .as_ref() .map_or_else(BTreeMap::new, |next| next.clock.clone()); - let missing = delta::missing_from_snapshot(&mut old, &clock, &own); + let missing = delta::missing_from_snapshot(&old, &clock, &own); if missing.own == 0 { return Prepared::Ready { old, @@ -458,7 +456,7 @@ fn prepare( }; } - let paths = delta::changed_paths(&mut old, &missing.before, &old_heads); + let paths = delta::changed_paths(&old, &missing.before, &old_heads); let gap = target.generation - previous.generation; // Writes made in our epoch go through every remake since, in order. @@ -562,8 +560,8 @@ mod tests { /// An old-epoch document with one own change after the base, and the swarm's /// document of the next epoch (snapshot plus one foreign change). - fn scenario(policy: &JsonValue) -> (AutoCommit, AutoCommit, Epoch) { - let mut old = AutoCommit::new().with_actor(ActorId::from(&b"late-node"[..])); + fn scenario(policy: &JsonValue) -> (Document, Document, Epoch) { + let mut old = Document::new().with_actor(ActorId::from(&b"late-node"[..])); change(&mut old, |old| old.put(ROOT, "base", 1_i64).unwrap()); let base = old.get_heads(); @@ -640,7 +638,7 @@ mod tests { assert!(matches!( prepare( swarm, - AutoCommit::new(), + Document::new(), Epoch::GENESIS, target, Vec::new(), @@ -659,7 +657,7 @@ mod tests { let (old, _, target) = scenario(&json!({})); assert!(matches!( prepare( - AutoCommit::new(), + Document::new(), old, Epoch::GENESIS, target, |
