aboutsummaryrefslogtreecommitdiffstats
path: root/src/remake/switch.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 19:53:27 +0100
committertv <tv@krebsco.de>2026-10-31 19:53:27 +0100
commit6105507200231e67ba544c12aa10b988e1c23826 (patch)
tree880530b7401cb5d43f52e06a68b4d704326aa272 /src/remake/switch.rs
parent8d7adfbdb7798cca9d9783761f290e3bd85d9a3a (diff)
use Automerge as Document instead of AutoCommit
This allows a lot of operations to drop mut.
Diffstat (limited to 'src/remake/switch.rs')
-rw-r--r--src/remake/switch.rs17
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(&copy, &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(&copy, &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(&copy, &mut doc, &record_path) {
+ if carry_record
+ && let Err(error) = store::copy_path(&copy, &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(&copy, &mut transaction, &paths, &translator);
+ transaction.commit();
Ok((doc, heads, stats))
},
)