aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 03:54:45 +0100
committertv <tv@krebsco.de>2026-10-31 03:54:45 +0100
commitd59cec8e6fd56bfbe91e251ec35e3e3e1f3f95dd (patch)
treeb5b2f79179b8b70c5fd0caa6a7c7b76bf853df75
parent0bb3924836205a0364aaf0959c7cf387db004794 (diff)
move ChangeSet from swarm to document
-rw-r--r--src/api/dashboard/mod.rs2
-rw-r--r--src/api/store.rs3
-rw-r--r--src/document/store.rs11
-rw-r--r--src/remake/coordinator.rs2
-rw-r--r--src/remake/mod.rs2
-rw-r--r--src/remake/switch.rs2
-rw-r--r--src/state/host.rs3
-rw-r--r--src/state/mod.rs3
-rw-r--r--src/swarm/sync.rs11
9 files changed, 21 insertions, 18 deletions
diff --git a/src/api/dashboard/mod.rs b/src/api/dashboard/mod.rs
index 0a502a3..86f349a 100644
--- a/src/api/dashboard/mod.rs
+++ b/src/api/dashboard/mod.rs
@@ -200,7 +200,7 @@ const MAX_CHANGED: usize = 256;
/// Where the document changed since last asked (`Hub::documents`), if anywhere.
fn document_changes(
- changes: &mut broadcast::Receiver<Arc<crate::swarm::sync::ChangeSet>>,
+ changes: &mut broadcast::Receiver<Arc<crate::document::store::ChangeSet>>,
) -> Option<JsonValue> {
let mut paths = BTreeSet::new();
let mut all = false;
diff --git a/src/api/store.rs b/src/api/store.rs
index 9c8cafd..0b0a40f 100644
--- a/src/api/store.rs
+++ b/src/api/store.rs
@@ -20,9 +20,8 @@ use tracing::{debug, error, instrument};
use super::auth::AuthenticatedUser;
use super::{parse_key_path, parse_write_path, response_for_value, store_status};
-use crate::document::store::{self, StoreError};
+use crate::document::store::{self, StoreError, paths_related};
use crate::state::{AppState, ReadSource};
-use crate::swarm::sync::paths_related;
#[derive(Debug, Default, Deserialize)]
pub(crate) struct ReadQuery {
diff --git a/src/document/store.rs b/src/document/store.rs
index 061df35..eeebda8 100644
--- a/src/document/store.rs
+++ b/src/document/store.rs
@@ -10,6 +10,17 @@ use serde::Serialize;
use serde_json::Value as JsonValue;
use std::collections::BTreeSet;
+/// Store paths touched by one batch of document changes (`AppState::change_events`).
+#[derive(Debug)]
+pub(crate) struct ChangeSet {
+ pub(crate) paths: Vec<Vec<String>>,
+}
+
+/// Whether one path is within the other (a change at either touches both).
+pub(crate) fn paths_related(a: &[String], b: &[String]) -> bool {
+ a.starts_with(b) || b.starts_with(a)
+}
+
#[derive(Debug, thiserror::Error)]
pub(crate) enum StoreError {
#[error("path crosses a non-map value")]
diff --git a/src/remake/coordinator.rs b/src/remake/coordinator.rs
index 50ed4a3..01937c7 100644
--- a/src/remake/coordinator.rs
+++ b/src/remake/coordinator.rs
@@ -38,7 +38,7 @@ use super::snapshot;
use super::vote;
use crate::document::meta::{self, REMAKES, VOTES};
use crate::document::store::StoreError;
-use crate::swarm::sync::paths_related;
+use crate::document::store::paths_related;
const TICK: Duration = Duration::from_secs(1);
diff --git a/src/remake/mod.rs b/src/remake/mod.rs
index 7b98f47..4a27ff4 100644
--- a/src/remake/mod.rs
+++ b/src/remake/mod.rs
@@ -51,7 +51,7 @@ use axum::{
use tokio::sync::broadcast;
use crate::document::replica::Epoch;
-use crate::swarm::sync::ChangeSet;
+use crate::document::store::ChangeSet;
/// Remakes and their aftermath on this node, in numbers (`/admin/stats`).
#[derive(Debug, Clone, Copy, Default)]
diff --git a/src/remake/switch.rs b/src/remake/switch.rs
index 6c90f44..1238499 100644
--- a/src/remake/switch.rs
+++ b/src/remake/switch.rs
@@ -38,8 +38,8 @@ use super::vote;
use crate::document::meta::{self, REMAKES};
use crate::document::replica::Epoch;
use crate::document::store;
+use crate::document::store::paths_related;
use crate::locks::MutexExt;
-use crate::swarm::sync::paths_related;
const TICK: Duration = Duration::from_secs(1);
diff --git a/src/state/host.rs b/src/state/host.rs
index 04b328c..a165637 100644
--- a/src/state/host.rs
+++ b/src/state/host.rs
@@ -13,8 +13,9 @@ use tracing::debug;
use super::{AppState, HelloState, NodeLifecycle, StaleView, Standing};
use crate::document::replica::Epoch;
+use crate::document::store::ChangeSet;
use crate::remake::{Host, PeerSummary, RemakeState};
-use crate::swarm::sync::{ChangeSet, SyncEvent};
+use crate::swarm::sync::SyncEvent;
impl AppState {
/// After the document was replaced: every peer's sync state refers to the old
diff --git a/src/state/mod.rs b/src/state/mod.rs
index 2f3d433..e8975e2 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -42,9 +42,10 @@ use tracing::{debug, error, warn};
use crate::document::lock::DocumentLock;
use crate::document::replica::{Epoch, Stamp};
+use crate::document::store::ChangeSet;
use crate::locks::MutexExt;
use crate::remake::{Host, RemakeState};
-use crate::swarm::sync::{ChangeSet, SyncEvent};
+use crate::swarm::sync::SyncEvent;
use crate::swarm::throughput::ThroughputTable;
use crate::transport;
use crate::transport::firewall::Firewall;
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index df4bb2d..05c0c34 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -10,6 +10,7 @@ use tokio::sync::mpsc;
use tokio::time::Instant;
use tracing::{debug, info, trace, warn};
+use crate::document::store::ChangeSet;
use crate::locks::MutexExt;
use crate::state::{AppState, Liveness, PeerState, Standing};
use crate::swarm::peer::{peer_swarm, send_hello_once};
@@ -25,12 +26,6 @@ pub(crate) enum SyncEvent {
PeerNeedsSync(String),
}
-/// Store paths touched by one batch of document changes.
-#[derive(Debug)]
-pub(crate) struct ChangeSet {
- pub(crate) paths: Vec<Vec<String>>,
-}
-
async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> {
if state.remake.fetching_snapshot() {
// Rejoining: the snapshot comes as a download, not in a sync message. Sync
@@ -645,10 +640,6 @@ fn patch_store_path(patch: &automerge::Patch) -> Vec<String> {
path
}
-pub(crate) fn paths_related(a: &[String], b: &[String]) -> bool {
- a.starts_with(b) || b.starts_with(a)
-}
-
pub(crate) async fn run_change_publisher(state: AppState) {
let mut changed = state.change_tx.subscribe();
let mut last_heads = state.write_doc(|doc| doc.get_heads()).await;