Skip to main content

Module sync_loop

Module sync_loop 

Source
Expand description

The sync layer’s loop on the LAN (SPEC_USER_DATA_SYNC_LAYER §4.2): the sending half of the sync.* ops. Every few seconds (or at once when something calls wake) this machine looks at the collections it is a member of and, for each other member it can see on the LAN, runs one round (backend::user_sync::round) when something changed here since the last round with it, when it has not been synced for a while (to heal a lost push), or when it was never synced. A peer that is offline, unproven or without the ops is left alone until a retry time. Nothing is sent when nothing changed, so the audit trails carry only real work.

Only an install that holds the computer’s sync lock plans anything, and a round lends the store to the sync layer one step at a time (never across a call to the peer), so this machine keeps answering the peer’s own requests while its round is running.

Structs§

Last 🔒
What the last round with one peer left behind.
Mine 🔒
Peer 🔒
The calls to one peer, as signed remote ops sent by one of this machine’s agents.
Plan 🔒
A collection this machine is a member of, the other machines in it and what this machine holds of it now.
Seen 🔒
A machine seen on the LAN: the install id it advertises (what a chain names it by) and the host a send takes.
Target 🔒
One round to run: a collection with one of its members that is reachable now.

Constants§

REASON 🔒
RESYNC 🔒
A peer is synced again after this long even if nothing here changed, to heal a lost push.
RETRY 🔒
A peer that failed is left alone this long.
TICK 🔒
How often this machine checks whether it has something new for its peers.

Statics§

WAKE 🔒

Functions§

answer_of 🔒
A peer’s answer as the round reads it: what it says, a refusal with its code, or the machine not answering.
due 🔒
Whether a round with this peer is due: it never ran, or its retry time has come, or what this machine holds changed, or it has been a while.
install 🔒
Start the loop. Does nothing while remote operations are off.
plans 🔒
The collections to sync, read from this machine’s state under the lock: none unless this install holds it.
remember 🔒
What to remember of a round: a peer that answered is left alone until something changes; one that did not is left alone for a while. A round that changed what this machine holds is looked at again at the next tick, so what it took goes on to the other members.
report 🔒
run_round 🔒
One round on a blocking thread: its calls to the peer wait on this runtime, and its steps on this machine’s state each take the store for their own length.
seen_on_lan 🔒
sync_once 🔒
targets 🔒
The rounds to run: each collection with each of its members that is on the LAN now.
wake 🔒
Wakes the loop now: something here changed a collection, so its peers should hear of it within a second instead of at the next tick.