diff options
| author | tv <tv@krebsco.de> | 2026-11-01 19:29:26 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-01 19:29:26 +0100 |
| commit | a9838a756fa7730e887598592a2f1b5b294e68a7 (patch) | |
| tree | aa1f75eafadd7e89a6b5679fc10a918bad55ac03 /src/state | |
| parent | 75f34a6b1c1c77e92aaf95f3ddb0751b190a9fce (diff) | |
LWW everywhere, mostly
Diffstat (limited to 'src/state')
| -rw-r--r-- | src/state/host.rs | 29 | ||||
| -rw-r--r-- | src/state/mod.rs | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/state/host.rs b/src/state/host.rs index 30ebcdb..eb7db35 100644 --- a/src/state/host.rs +++ b/src/state/host.rs @@ -226,6 +226,35 @@ impl Host for AppState { async move { state.mutate_doc(f).await } } + fn superseded(&self) -> crate::remake::Superseded { + self.superseded_writes + } + + fn commit_changes<T, F>(&self, f: F) -> impl Future<Output = Result<T, StoreError>> + Send + where + F: FnOnce(&mut Document) -> T + Send + 'static, + T: Send + 'static, + { + let state = self.clone(); + async move { + tokio::task::spawn_blocking(move || { + let result = { + let mut replica = state.doc.blocking_write(); + if !replica.writable { + return Err(StoreError::Rejoining); + } + let result = f(&mut replica.doc); + replica.refresh_heads(); + result + }; + state.publish_change(); + Ok(result) + }) + .await + .expect("document write task panicked") + } + } + fn refuse_writes(&self, copy: bool) -> impl Future<Output = Option<Document>> + Send { let state = self.clone(); async move { diff --git a/src/state/mod.rs b/src/state/mod.rs index 5e4a4d3..6e6e48c 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -112,6 +112,8 @@ pub(crate) struct AppState { /// This node's clock is off when it differs from most of its peers' by more than /// this (`--clock-skew-warn`, `swarm::skew`); 0: never. pub(crate) clock_skew_warn: Duration, + /// What a replay does with writes a newer one superseded (`--superseded-writes`). + pub(crate) superseded_writes: crate::remake::Superseded, /// How far this node's clock is ahead of its peers' (their median, `swarm::skew`), as /// last measured; 0 before. The propagation figures take it off. pub(crate) clock_ahead_ms: Arc<std::sync::atomic::AtomicI64>, |
