diff options
| author | tv <tv@krebsco.de> | 2026-10-31 19:53:27 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-31 19:53:27 +0100 |
| commit | 9c12bf2e8815dc9b42be62f1e1fd2932dd02938b (patch) | |
| tree | 09cd985fae9142a247a2285c755f9d002a2c7b30 /src/remake/mod.rs | |
| parent | f4b0a7c5159d418e22682d2bd7d413fb3587ca7f (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.rs | 19 |
1 files changed, 15 insertions, 4 deletions
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<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; } |
