From 2a475153b715c954935ae46d3773ffbf3d007f03 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 04:05:41 +0000 Subject: document: where a document stands, and a peer, is the document's to compare document::passing: a Mark, where a document stood, by which what changed since and the node's own units since are told (changed_since, own_since: the change publisher, the sync worker); and of where a peer says it stands, what the document lacks, whether the peer holds what the document held, a pull of what is lacking, and what it has counting as sent no more (lacking, peer_holds, pull, heard: the relay, keepalives). The published stamp gives its summary and its mark. --- src/swarm/changes.rs | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'src/swarm/changes.rs') diff --git a/src/swarm/changes.rs b/src/swarm/changes.rs index a04ce7d..fd0d32a 100644 --- a/src/swarm/changes.rs +++ b/src/swarm/changes.rs @@ -7,56 +7,35 @@ use std::sync::Arc; use tracing::{info, warn}; -use crate::document::changes; -use crate::document::store::{ChangeSet, InLists}; +use crate::document::store::ChangeSet; use crate::state::AppState; pub(crate) async fn run_change_publisher(state: AppState) { let mut changed = state.change_tx.subscribe(); - // The replica's heads (sorted, as of its last refresh: every change refreshes them). - let mut last_heads = state.doc.read().await.heads().to_vec(); + // Where the document stood when last looked at. + let mut last = crate::document::passing::mark(&*state.doc.read().await); info!("Starting change publisher"); while changed.changed().await.is_ok() { - let before = last_heads.clone(); + let before = last.clone(); let doc = Arc::clone(&state.doc); let looked = tokio::task::spawn_blocking(move || { - let replica = doc.blocking_read(); - let heads = replica.heads().to_vec(); - if heads == before { - return (heads, Vec::new(), Vec::new()); - } - - // After an epoch switch the previous heads belong to the old document: - // report the root as changed, which every stream is related to. - if !changes::missing(&replica.doc, &before).is_empty() { - return (heads, vec![Vec::new()], Vec::new()); - } - - let mut paths = Vec::new(); - let mut conflicts = Vec::new(); - for changed in replica.changed_since(&before, InLists::Index) { - if changed.conflict { - conflicts.push(changed.path.clone()); - } - paths.push(changed.path); - } - (heads, paths, conflicts) + crate::document::passing::changed_since(&doc.blocking_read(), &before) }) .await; - let (heads, paths, conflicts) = match looked { + let (now, paths, conflicts) = match looked { Ok(looked) => looked, // The runtime is shutting down (the node stops): nothing to publish to. Err(error) if error.is_cancelled() => return, Err(error) => std::panic::resume_unwind(error.into_panic()), }; - if heads == last_heads { + if now == last { continue; } - last_heads = heads; + last = now; for path in &conflicts { warn!(path = ?path, "Concurrent writes produced a conflict"); -- cgit v1.3.1