aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 03:47:04 +0100
committertv <tv@krebsco.de>2026-10-31 03:47:04 +0100
commit787a5952794eb6927c7bc2244aa8fd8a403849c6 (patch)
tree19230e00f6b06a7cafa742b584a754b499e3450a /src
parent0e13c368f6214dabe99c987a98a990d4e4e0b3c8 (diff)
unify source reset
Diffstat (limited to 'src')
-rw-r--r--src/state/host.rs5
-rw-r--r--src/swarm/source.rs12
2 files changed, 11 insertions, 6 deletions
diff --git a/src/state/host.rs b/src/state/host.rs
index b55239d..ee67b80 100644
--- a/src/state/host.rs
+++ b/src/state/host.rs
@@ -13,7 +13,6 @@ use tracing::debug;
use super::{AppState, HelloState, NodeLifecycle, StaleView, Standing};
use crate::document::replica::Epoch;
-use crate::locks::MutexExt;
use crate::remake::{Host, PeerSummary, RemakeState};
use crate::swarm::sync::{ChangeSet, SyncEvent};
@@ -198,8 +197,8 @@ impl Host for AppState {
fn reset_initial_sync(&self) {
self.initial_sync_done
.store(false, std::sync::atomic::Ordering::Release);
- *self.catch_up_source.lock_or_recover() = None;
- *self.catch_up_preference.lock_or_recover() = None;
+ // The source chosen, and the one avoided, were for the catch-up before.
+ crate::swarm::source::reset(self);
}
fn subscribe_changes(&self) -> broadcast::Receiver<Arc<ChangeSet>> {
diff --git a/src/swarm/source.rs b/src/swarm/source.rs
index d80e4d7..5e428f2 100644
--- a/src/swarm/source.rs
+++ b/src/swarm/source.rs
@@ -286,12 +286,18 @@ pub(crate) fn probe_due(state: &AppState, peer: &str, now: Instant) -> bool {
due
}
-/// The initial sync is done: no source any more, and the peers we held back only need
-/// to learn our heads now.
-pub(crate) fn finished(state: &AppState, from: &str) {
+/// No catch-up going on: no source, no head start, nobody avoided. When one ends, and
+/// before one starts (a rejoin: `Host::reset_initial_sync`).
+pub(crate) fn reset(state: &AppState) {
*lock(state) = None;
*lock_preference(state) = None;
*lock_avoided(state) = None;
+}
+
+/// The initial sync is done: no source any more, and the peers we held back only need
+/// to learn our heads now.
+pub(crate) fn finished(state: &AppState, from: &str) {
+ reset(state);
let state = state.clone();
let from = from.to_owned();
tokio::spawn(async move {