diff options
Diffstat (limited to 'src/remake/switch.rs')
| -rw-r--r-- | src/remake/switch.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/remake/switch.rs b/src/remake/switch.rs index 9aae748..e60c942 100644 --- a/src/remake/switch.rs +++ b/src/remake/switch.rs @@ -219,10 +219,10 @@ async fn switch<H: Host>( // 2. Build (or reuse), verify and replay without holding any lock. let (new_doc, copy_heads, mut stats) = tokio::task::spawn_blocking( move || -> Result<(Document, Vec<ChangeHash>, ReplayStats), String> { - let mut copy = copy; + let copy = copy; let snapshot = match prebuilt { Some(snapshot) => snapshot, - None => snapshot::build(&mut copy, &request.params()) + None => snapshot::build(©, &request.params()) .map_err(|error| format!("snapshot build failed: {error}"))?, }; if snapshot.epoch != expected { @@ -235,13 +235,20 @@ async fn switch<H: Host>( // A fresh actor: this node's writes in the new epoch. let mut doc = snapshot.doc.with_actor(actor); + // The carried record and the replayed writes go into one change. + let heads = copy.get_heads(); + let paths = delta::changed_paths(©, &base, &heads); + let mut transaction = doc.transaction(); + // Keep this remake's record visible in the new epoch, for its history. - if carry_record && let Err(error) = store::copy_path(©, &mut doc, &record_path) { + if carry_record + && let Err(error) = store::copy_path(©, &mut transaction, &record_path) + { warn!(error = %error, "Could not carry the remake record into the new epoch"); } - let heads = copy.get_heads(); - let stats = delta::replay(&mut copy, &base, &heads, &mut doc, &translator); + let stats = delta::replay_paths(©, &mut transaction, &paths, &translator); + transaction.commit(); Ok((doc, heads, stats)) }, ) |
