aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/changes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/changes.rs')
-rw-r--r--src/swarm/changes.rs37
1 files changed, 8 insertions, 29 deletions
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");