aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
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");