aboutsummaryrefslogtreecommitdiffstats
path: root/src/remake/mod.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:56:13 +0100
commitc3ddce0106d19fc3d37465f71ce50444871655b6 (patch)
treea22b3d350bc4be9157ad4cf574eafee689b997c7 /src/remake/mod.rs
parentdfe0daa99e6e545f647715b73929cc3e244e8e0d (diff)
use Automerge as Document instead of AutoCommit
This allows a lot of operations to drop mut.
Diffstat (limited to 'src/remake/mod.rs')
-rw-r--r--src/remake/mod.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/remake/mod.rs b/src/remake/mod.rs
index 923cd72..0fed3ac 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<String>;
+ fn electorate(
+ &self,
+ doc: &impl crate::document::ReadDoc,
+ now: crate::clock::UnixMillis,
+ ) -> Vec<String>;
/// 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<T, E, F>(&self, f: F) -> impl Future<Output = Result<T, E>> + Send
where
- F: FnOnce(&mut Document) -> Result<T, E> + Send + 'static,
+ F: FnOnce(&mut Transaction<'_>) -> Result<T, E> + 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<Output = Result<(), String>> + 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<Output = Result<Document, E>> + Send
where
- F: FnOnce(&mut Document) -> Result<Document, E> + Send + 'static,
+ F: FnOnce(&Document) -> Result<Document, E> + Send + 'static,
E: Send + 'static;
}