aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 04:16:12 +0000
committertv <tv@krebsco.de>2026-11-20 05:29:48 +0100
commit7926a9764626878f5cc244286cce9eb502358929 (patch)
tree7ba6082872afd464490feb296c4f54afbc5c80a9 /src/swarm
parent00cac6466057c2a8a92dae9e4cd46369e72bcad9 (diff)
keep-actor by default: the writer kept across a clean stop, writes held till a sync
A node that stopped cleanly writes on as the writer of before, as `--keep-actor` had it, now by default: an epoch gathers a writer per node and per crash, drop or rejoin, not per start. `keep-actor = false`, in a configuration file, has a node write as a fresh writer each start; a node without a document file has nothing to keep, which is no longer an error. Writing on as the writer of before, a node holds its writes (`mutate_doc` and the API's through it) until it synced once with a ready neighbour, level with it, or 10 seconds passed (`AppState::hold_writes`, `KEPT_WRITER_WAIT`): a neighbour holding later changes of that writer, which a copy of the node's files made (a backup restored, a disk rolled back), hands them over first, and the node takes a fresh writer then, as it did. A node that reaches no neighbour within the wait writes on.
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/sync.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index 5f30440..ad8c0a0 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -602,6 +602,10 @@ pub(crate) async fn handle_sync(
return Ok(());
}
+ let check_caught_up = !state.initial_sync_done.load(Ordering::Acquire);
+ // Writes held until a ready neighbour is synced with once (`AppState::hold_writes`).
+ let writes_held = *state.writes_held.borrow();
+ let check_level = check_caught_up || writes_held;
let applied = {
let doc = Arc::clone(&state.doc);
let peer_state_mutex = Arc::clone(&peer_state_mutex);
@@ -611,7 +615,6 @@ pub(crate) async fn handle_sync(
let rtt = state
.lock_rtt()
.effective(peer, Instant::now(), state.timing.rtt_fresh_for());
- let check_caught_up = !state.initial_sync_done.load(Ordering::Acquire);
// While catching up, everything arrives late; that says nothing about propagation.
let measure_propagation = !check_caught_up;
let message = payload;
@@ -620,9 +623,9 @@ pub(crate) async fn handle_sync(
let ahead_ms = state.clock_ahead_ms.load(Ordering::Relaxed);
let remake = Arc::clone(&state.remake);
- // Some((caught_up, heads changed, carried changes, the new changes' authors with
- // theirs, and whether any has none, how long to wait before answering if it
- // brought only changes refused before)) when applied, None when the message
+ // 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
+ // if it brought only changes refused before)) when applied, None when the message
// belongs to another epoch.
type Applied = (
bool,
@@ -810,7 +813,7 @@ pub(crate) async fn handle_sync(
// catching up has them, and so does a ready peer whose document is empty
// (a misconfigured second swarm, or a genesis node in its first seconds,
// before it registered itself).
- check_caught_up && from_ready && peer_state.sync.have_all_theirs(&replica.doc),
+ check_level && from_ready && peer_state.sync.have_all_theirs(&replica.doc),
changed,
carried,
authors,
@@ -822,7 +825,7 @@ pub(crate) async fn handle_sync(
.context("Sync task panicked")??
};
- let Some((caught_up, changed, carried, (authors, unauthored), back_off, tell)) = applied else {
+ let Some((level, changed, carried, (authors, unauthored), back_off, tell)) = applied else {
debug!(peer = %peer, epoch = %epoch_label, "Dropped sync message from another epoch");
return Ok(());
};
@@ -840,6 +843,10 @@ pub(crate) async fn handle_sync(
source::reported(state, peer, from_ready, None);
+ if level && writes_held {
+ state.release_writes(peer);
+ }
+ let caught_up = level && check_caught_up;
let just_caught_up = caught_up && !state.initial_sync_done.swap(true, Ordering::AcqRel);
if just_caught_up {
info!(peer = %peer, "Initial sync complete");