From 6105507200231e67ba544c12aa10b988e1c23826 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 19:53:27 +0100 Subject: use Automerge as Document instead of AutoCommit This allows a lot of operations to drop mut. --- src/remake/mod.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/remake/mod.rs') diff --git a/src/remake/mod.rs b/src/remake/mod.rs index 9206bbf..e9d3021 100644 --- a/src/remake/mod.rs +++ b/src/remake/mod.rs @@ -52,9 +52,9 @@ use axum::{ }; use tokio::sync::broadcast; -use crate::document::Document; use crate::document::replica::Epoch; use crate::document::store::ChangeSet; +use crate::document::{Document, Transaction}; /// Remakes and their aftermath on this node, in numbers (`/admin/stats`). #[derive(Debug, Clone, Copy, Default)] @@ -129,7 +129,11 @@ pub(crate) trait Host: Clone + Send + Sync + 'static { /// The electorate of a remake proposed now (`vote`): the members that said they are /// alive recently enough, read from `doc`. - fn electorate(&self, doc: &Document, now: crate::clock::UnixMillis) -> Vec; + fn electorate( + &self, + doc: &impl crate::document::ReadDoc, + now: crate::clock::UnixMillis, + ) -> Vec; /// Downloads a change from peers on the local epoch, in chunks from several at once, /// checked against its hash. @@ -183,10 +187,17 @@ pub(crate) trait Host: Clone + Send + Sync + 'static { /// One committed change (rolled back on error), published and replicated. fn commit_doc(&self, f: F) -> impl Future> + Send where - F: FnOnce(&mut Document) -> Result + Send + 'static, + F: FnOnce(&mut Transaction<'_>) -> Result + Send + 'static, T: Send + 'static, E: Send + 'static; + /// Applies a change downloaded from peers (`fetch_change`), then publishes it like + /// a change received by sync. + fn apply_change( + &self, + change: crate::document::Change, + ) -> impl Future> + Send; + /// Replaces the document and its epoch atomically. Under the write lock, `f` gets /// the live document and returns the new one. Afterwards the node resets every /// peer's sync state and publishes the change. Returns the old document. @@ -196,7 +207,7 @@ pub(crate) trait Host: Clone + Send + Sync + 'static { f: F, ) -> impl Future> + Send where - F: FnOnce(&mut Document) -> Result + Send + 'static, + F: FnOnce(&Document) -> Result + Send + 'static, E: Send + 'static; } -- cgit v1.3.1