aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-29 02:48:25 +0000
committertv <tv@krebsco.de>2026-11-29 02:48:25 +0000
commit8a29efed857991417d12b8e21884dbbcb53ff4a0 (patch)
treef57da52ac22090146c3f3baac23fb0b5dd2938dc
parentb259ee75fbbbf8e265a0bf2a0b79c4f6a75f395a (diff)
document: the writers a node wrote under are the document's, not a remake's
The actors a node writes or wrote with in its current document (document::own::OwnWriters, AppState::own_writers) were kept by the remake state, which signing, the document file, sync and a dropped change read them from. They are the engine's: a document of a kind without writers of this sort has none, and needs no remake state for them.
-rw-r--r--src/access/screen.rs2
-rw-r--r--src/document/file.rs2
-rw-r--r--src/document/mod.rs1
-rw-r--r--src/document/own.rs33
-rw-r--r--src/document/replica.rs2
-rw-r--r--src/node.rs5
-rw-r--r--src/remake/catchup.rs8
-rw-r--r--src/remake/local.rs25
-rw-r--r--src/remake/mod.rs3
-rw-r--r--src/remake/switch.rs4
-rw-r--r--src/state/host.rs14
-rw-r--r--src/state/mod.rs3
-rw-r--r--src/swarm/document_file.rs2
-rw-r--r--src/swarm/sync.rs8
14 files changed, 67 insertions, 45 deletions
diff --git a/src/access/screen.rs b/src/access/screen.rs
index e37f2b9..050b23f 100644
--- a/src/access/screen.rs
+++ b/src/access/screen.rs
@@ -740,7 +740,7 @@ pub(crate) struct Outcome {
/// Changes the bytes carried forged under another node's actor: their sender's.
pub(crate) forged: usize,
/// The fresh actor the node writes as from now on, where the bytes carried a change
- /// of its own actor that it doesn't hold: for its own actors (`add_own_actor`).
+ /// of its own actor that it doesn't hold: for its own actors (`OwnWriters::add`).
pub(crate) fresh_actor: Option<crate::document::ActorId>,
}
diff --git a/src/document/file.rs b/src/document/file.rs
index a21aa17..80c76e6 100644
--- a/src/document/file.rs
+++ b/src/document/file.rs
@@ -245,7 +245,7 @@ pub(crate) struct DocumentFile {
#[derive(Debug, Clone)]
struct Written {
epoch: Epoch,
- /// This node's actors when the file was last rewritten (`RemakeState::own_actors`).
+ /// This node's actors when the file was last rewritten (`document::own::OwnWriters`).
actors: usize,
heads: Vec<ChangeHash>,
/// How many of the document's signatures (`Signatures::count`).
diff --git a/src/document/mod.rs b/src/document/mod.rs
index 530e6b6..fd44331 100644
--- a/src/document/mod.rs
+++ b/src/document/mod.rs
@@ -63,6 +63,7 @@ pub(crate) mod file;
pub(crate) mod inspect;
pub(crate) mod lock;
pub(crate) mod meta;
+pub(crate) mod own;
pub(crate) mod replica;
pub(crate) mod signatures;
pub(crate) mod signed;
diff --git a/src/document/own.rs b/src/document/own.rs
new file mode 100644
index 0000000..2910616
--- /dev/null
+++ b/src/document/own.rs
@@ -0,0 +1,33 @@
+//! The writers this node writes or wrote under in its current document.
+
+use std::sync::Mutex;
+
+use super::ActorId;
+use crate::locks::MutexExt;
+
+/// The actors this node writes or wrote with in the current document: this run's, and
+/// those of earlier runs it knows of (`--document-file`). Its own writes, for a rejoin,
+/// for signing and for dropping what it took. A switch or rejoin starts the list over
+/// with the new document's actor, so it only grows with restarts within one epoch.
+#[derive(Debug, Default)]
+pub(crate) struct OwnWriters(Mutex<Vec<ActorId>>);
+
+impl OwnWriters {
+ /// This node writes with `actor` from now on (or did, in an earlier run).
+ pub(crate) fn add(&self, actor: ActorId) {
+ let mut own = self.0.lock_or_recover();
+ if !own.contains(&actor) {
+ own.push(actor);
+ }
+ }
+
+ /// The current document is a new one, written with `actor` only (a switch or rejoin
+ /// is done).
+ pub(crate) fn reset(&self, actor: ActorId) {
+ *self.0.lock_or_recover() = vec![actor];
+ }
+
+ pub(crate) fn all(&self) -> Vec<ActorId> {
+ self.0.lock_or_recover().clone()
+ }
+}
diff --git a/src/document/replica.rs b/src/document/replica.rs
index cdf789c..ba94ca9 100644
--- a/src/document/replica.rs
+++ b/src/document/replica.rs
@@ -493,7 +493,7 @@ fn run<T, E>(
/// Makes `node` the author of `doc`'s changes from now on. Setting an author gives the
/// document a new actor; this node keeps its own (`with_actor`), which it tracks
-/// (`RemakeState::own_actors`, the document file), as only it writes with it.
+/// (`document::own::OwnWriters`, the document file), as only it writes with it.
pub(crate) fn authored(doc: &mut Document, node: &str) {
if doc
.get_author()
diff --git a/src/node.rs b/src/node.rs
index 3d1c882..5cf72c8 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -181,6 +181,7 @@ impl Node {
change_events,
timing: config.timing,
remake: Arc::new(remake::RemakeState::new(config.clock.now_millis())),
+ own_writers: Default::default(),
swarm_key: config.swarm_key,
run_id: uuid::Uuid::new_v4().into_bytes(),
handshakes: Default::default(),
@@ -253,9 +254,9 @@ impl Node {
clock: config.clock,
};
for actor in config.earlier_actors {
- state.remake.add_own_actor(actor);
+ state.own_writers.add(actor);
}
- state.remake.add_own_actor(initial_actor);
+ state.own_writers.add(initial_actor);
trace!("Application state initialized");
Self { state, sync_rx }
}
diff --git a/src/remake/catchup.rs b/src/remake/catchup.rs
index b8dc1b9..685385a 100644
--- a/src/remake/catchup.rs
+++ b/src/remake/catchup.rs
@@ -279,7 +279,7 @@ async fn start<H: Host>(host: &H, local: Epoch, target: Epoch, attempts: u32) {
}));
let actor = ActorId::random();
- host.remake().add_own_actor(actor.clone());
+ host.own_writers().add(actor.clone());
// At once: the fresh document takes no writes until the rejoin is done; a ready
// node's document so far answers reads, marked stale, and takes its writes
// meanwhile (`Host::begin_rejoin`).
@@ -386,7 +386,7 @@ async fn finish<H: Host>(host: &H) {
// meanwhile, and those after `began` are replayed under the lock in the end.
let copy = host.read_doc(|doc| doc.clone()).await;
let kept = host.rejoin_document().await;
- let own = host.remake().own_actors();
+ let own = host.own_writers().all();
let now = host.now_millis();
#[cfg(feature = "federation")]
let (holding, store) = (host.holding(), host.store_id());
@@ -560,7 +560,7 @@ async fn finish<H: Host>(host: &H) {
);
host.remake().set_catch_up(None);
let actor = host.read_doc(|doc| doc.get_actor().clone()).await;
- host.remake().reset_own_actors(actor);
+ host.own_writers().reset(actor);
info!(
from = %previous,
@@ -578,7 +578,7 @@ async fn finish<H: Host>(host: &H) {
/// Verifies the synced document `copy` and decides about the old document's own
/// changes: those up to `began` (when the rejoin began) by the replay window, those
/// after it (made during the rejoin) whatever it says. `own`: this node's actors
-/// (`RemakeState::own_actors`); the old document's own actor counts in any case.
+/// (`document::own::OwnWriters`); the old document's own actor counts in any case.
/// `now`: Unix milliseconds, by the node's clock.
fn prepare(
copy: &Document,
diff --git a/src/remake/local.rs b/src/remake/local.rs
index cdf2d6f..cf6f566 100644
--- a/src/remake/local.rs
+++ b/src/remake/local.rs
@@ -16,7 +16,7 @@ use super::records::Retention;
use super::snapshot::Snapshot;
use crate::clock::UnixMillis;
use crate::document::replica::Epoch;
-use crate::document::{ActorId, ChangeHash, Document};
+use crate::document::{ChangeHash, Document};
use crate::locks::MutexExt;
pub(crate) struct RemakeState {
@@ -68,11 +68,6 @@ struct Inner {
missed: HashSet<String>,
/// Strict remakes this node won't vote for (`vote::cast`), each logged once.
refused_strict: HashSet<String>,
- /// The actors this node writes or wrote with in the current document: this run's,
- /// and those of earlier runs it knows of (`--document-file`). Its own writes, for a
- /// rejoin. A switch or rejoin starts the list over with the new document's actor, so
- /// it only grows with restarts within one epoch.
- own_actors: Vec<ActorId>,
}
/// Content no remake refers to any more is kept this long after it was stored, for
@@ -170,24 +165,6 @@ impl RemakeState {
self.started_at
}
- /// This node writes with `actor` from now on (or did, in an earlier run).
- pub(crate) fn add_own_actor(&self, actor: ActorId) {
- let mut inner = self.lock();
- if !inner.own_actors.contains(&actor) {
- inner.own_actors.push(actor);
- }
- }
-
- /// The current document is a new one, written with `actor` only (a switch or rejoin
- /// is done).
- pub(crate) fn reset_own_actors(&self, actor: ActorId) {
- self.lock().own_actors = vec![actor];
- }
-
- pub(crate) fn own_actors(&self) -> Vec<ActorId> {
- self.lock().own_actors.clone()
- }
-
/// Whether this node starts coordinating `id` now (false if it already does).
pub(crate) fn start_coordinating(&self, id: &str) -> bool {
self.lock().coordinating.insert(id.to_owned())
diff --git a/src/remake/mod.rs b/src/remake/mod.rs
index 1f7a644..6b1103e 100644
--- a/src/remake/mod.rs
+++ b/src/remake/mod.rs
@@ -200,6 +200,9 @@ pub(crate) trait Host: Clone + Send + Sync + 'static {
/// This node's in-memory remake state.
fn remake(&self) -> &RemakeState;
+ /// The writers this node writes or wrote under in its current document.
+ fn own_writers(&self) -> &crate::document::own::OwnWriters;
+
/// This node's wall clock (`clock`): deadlines, votes and decisions are stamped and
/// judged with it. Shared, so closures run under the document lock can read it.
fn clock(&self) -> Arc<crate::clock::Clock>;
diff --git a/src/remake/switch.rs b/src/remake/switch.rs
index e56cd8c..ef616dc 100644
--- a/src/remake/switch.rs
+++ b/src/remake/switch.rs
@@ -254,7 +254,7 @@ async fn switch<H: Host>(
.filter(|snapshot| snapshot.epoch == expected);
let actor = ActorId::random();
- host.remake().add_own_actor(actor.clone());
+ host.own_writers().add(actor.clone());
let new_actor = actor.clone();
let node = host.node_id();
@@ -309,7 +309,7 @@ async fn switch<H: Host>(
// 3. Swap, replaying what arrived since the copy.
let (old, late) = swap_in(host, expected, new_doc, copy_heads, late_translator).await?;
stats.absorb(late);
- host.remake().reset_own_actors(new_actor);
+ host.own_writers().reset(new_actor);
// 4. Writes the remake had no place for wait for an operator (the old document
// holds them); the old document is kept as configured either way.
diff --git a/src/state/host.rs b/src/state/host.rs
index 0b2b27d..34ed7ed 100644
--- a/src/state/host.rs
+++ b/src/state/host.rs
@@ -30,7 +30,7 @@ impl AppState {
replica.signatures = replica.signatures.kept_for(&replica.doc);
if let Some(key) = &self.node_key {
let replica = &mut *replica;
- let own = self.remake.own_actors();
+ let own = self.own_writers.all();
replica
.signatures
.sign_own_actors(&mut replica.doc, key, &own);
@@ -110,7 +110,7 @@ impl AppState {
/// of the document (past `SMALL_DROP`), wait for another's.
const BIG_DROP: usize = 100;
const SMALL_DROP: usize = 10;
- let own = self.remake.own_actors();
+ let own = self.own_writers.all();
// Another member to hear it from: a node with one neighbour, the one telling, has
// only its word (a swarm of two, a leaf), and waiting would hold the drop for good.
let another = crate::swarm::topology::our_neighbours(self)
@@ -221,7 +221,7 @@ impl AppState {
},
})
.collect();
- state.remake.add_own_actor(actor);
+ state.own_writers.add(actor);
let epoch = replica.epoch;
let old = state.swap_document(&mut replica, epoch, fresh);
{
@@ -297,6 +297,10 @@ impl Host for AppState {
&self.remake
}
+ fn own_writers(&self) -> &crate::document::own::OwnWriters {
+ &self.own_writers
+ }
+
fn clock(&self) -> Arc<crate::clock::Clock> {
Arc::clone(&self.clock)
}
@@ -533,7 +537,7 @@ impl Host for AppState {
// What it replayed, vouched for at once.
if let Some(key) = &state.node_key {
let replica = &mut *replica;
- let own = state.remake.own_actors();
+ let own = state.own_writers.all();
replica
.signatures
.sign_own_actors(&mut replica.doc, key, &own);
@@ -617,7 +621,7 @@ impl Host for AppState {
)
.map(|outcome| {
if let Some(actor) = outcome.fresh_actor {
- state.remake.add_own_actor(actor);
+ state.own_writers.add(actor);
}
})
.map_err(|error| format!("{error:#}"))
diff --git a/src/state/mod.rs b/src/state/mod.rs
index a812b91..4187654 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -111,6 +111,9 @@ pub(crate) struct AppState {
/// Per-node remake state (prebuilt snapshots, switch status, archive).
pub(crate) remake: Arc<RemakeState>,
+ /// The writers this node writes or wrote under in its current document.
+ pub(crate) own_writers: Arc<crate::document::own::OwnWriters>,
+
/// Pre-shared key every member must prove in the handshake; None admits any node
/// that reaches us.
pub(crate) swarm_key: Option<Arc<crate::swarm::auth::SwarmKey>>,
diff --git a/src/swarm/document_file.rs b/src/swarm/document_file.rs
index c833656..6c71e42 100644
--- a/src/swarm/document_file.rs
+++ b/src/swarm/document_file.rs
@@ -66,7 +66,7 @@ pub(crate) async fn flush(state: &AppState) {
if !state.is_ready().await {
return;
}
- let own = state.remake.own_actors();
+ let own = state.own_writers.all();
let (epoch, heads, signatures) = {
let replica = state.doc.read().await;
(
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index ad8c0a0..45698fa 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -621,7 +621,7 @@ pub(crate) async fn handle_sync(
let peer = peer.to_owned();
let clock = Arc::clone(&state.clock);
let ahead_ms = state.clock_ahead_ms.load(Ordering::Relaxed);
- let remake = Arc::clone(&state.remake);
+ let own_writers = Arc::clone(&state.own_writers);
// Some((level with a ready peer, heads changed, carried changes, the new changes'
// authors with theirs, and whether any has none, how long to wait before answering
@@ -707,7 +707,7 @@ pub(crate) async fn handle_sync(
tracing::warn!(peer = %peer, forged = outcome.forged, "A peer brought changes forged under another node's actor: refused");
}
if let Some(actor) = outcome.fresh_actor {
- remake.add_own_actor(actor);
+ own_writers.add(actor);
}
sync.lacks(screening.lock_or_recover().waiting.lacking(doc));
}
@@ -1016,7 +1016,7 @@ async fn download_and_apply_delta(
let clock = Arc::clone(&state.clock);
let ahead_ms = state.clock_ahead_ms.load(Ordering::Relaxed);
let screening = Arc::clone(&state.screening);
- let remake = Arc::clone(&state.remake);
+ let own_writers = Arc::clone(&state.own_writers);
tokio::task::spawn_blocking(move || -> Result<bool> {
let mut replica = doc.blocking_write();
if replica.epoch != epoch {
@@ -1040,7 +1040,7 @@ async fn download_and_apply_delta(
&mut crate::document::PatchLog::inactive(),
)?;
if let Some(actor) = outcome.fresh_actor {
- remake.add_own_actor(actor);
+ own_writers.add(actor);
}
}
replica.refresh_heads();