Expand description
The change log and the state tables beside it (SPEC_USER_DATA_SYNC_LAYER §3.2, §5). Every change, made here or
taken from another machine, is one row of db_sync_log, keyed by its origin machine and that machine’s
sequence number, so a catch-up is “everything after these sequences” and applying a record twice changes
nothing. db_sync_state points at the log row that is each record’s current state. db_sync_mark is the
high-water mark of the head last accepted from a store, so an older head is refused (rollback).
Functions take a &Connection so the whole layer is tested against in-memory stores of fake machines.
Structs§
- Head
- The newest head accepted from a store: a generation (it rises when a store compacts or re-seals) and the vector.
- History
Entry - A line of a collection’s change history: who (which machine), when, what kind of change; never a value.
- SealAt
- What the header of a record being written will carry, handed to the caller before the body is made so it can seal the body for exactly that place (the associated data of the seal is these fields).
- Signer
- The machine writing: its identifier, its signing key’s seed and its clock.
Enums§
- Change
- What kind of change a history line is.
- Outcome
- What applying a record did.
- Refused
- Why a record was refused.
- Sync
Error
Constants§
- HORIZON_
BOARD_ DAYS - Days a deleted record’s tombstone is kept: a board, and a Vault.
- HORIZON_
VAULT_ DAYS
Functions§
- accept_
head - Takes a head served by a store as the new high-water mark; refuses one lower than the mark (a lower generation, or the same generation with any origin behind where it was).
- append_
local - A change made here: the next sequence of this machine’s log, the next version of its clock, signed. The clock is first raised to the highest version the log holds, so a clock made fresh after a restart (or a wall clock that stepped back) still makes a version after the record’s current state, and the new write may point it.
- append_
local_ with append_localwith the body made bysealonce the version, base and epoch are known. A tombstone has no body:sealis not called. An error fromsealwrites nothing.- apply_
remote - A record from another machine. Refused unless it is at this collection’s key epoch, from a pinned origin, correctly signed, not too far ahead of this clock and the next in its origin’s sequence; applying one already held changes nothing. The adapter says whether it becomes the record’s state.
- collection_
epoch - current
- A record’s current state, as a whole record.
- cut_off
- What this machine wrote at an older key epoch beyond the end the membership change named for it, and that is still a record’s current state: the writes the others refuse, to be written again at the current epoch.
- ensure_
collection - expired_
tombstones - Records whose current state is a tombstone older than the collection’s horizon: safe to forget once every member has acknowledged them.
- history
- The collection’s change history, newest first, from its log.
- horizon_
days - init
- live_
elsewhere - Whether a collection other than
collectionholdsrecordas a live record (not a tombstone): a record the log has moved to another collection is live in the new one while the old one ends it. - mark
- needs_
full_ resync - A member that was last in contact before the horizon resyncs from scratch; what it changed offline goes to the conflict inbox, not silently lost.
- recheck
- Settles the records that a change of the epoch ends moved rows in or out of (
reset_epochsnotes them): a write stored as void under a removal that then lost a fork counts now and is merged as it would have been, and one that no longer counts stops being its record’s state. What counts is merged oldest version first, as the adapter would have taken the records in; whatmewrote is kept whether or not it counts (it is written again at the current epoch, which supersedes it). Answers how many records’ state moved. - reset_
epochs - Sets the collection’s key epoch and the ends of the epochs before it to exactly what the membership chain says now,
in either direction: a removal that lost a fork to another entry leaves no epoch and no ends behind.
cutsholds, for each epoch left, what each remaining member had written at it. Several statements: the caller makes them one (ops::sync_epochandops::store_chaindo), so a failure part-way leaves nothing changed. - set_
epoch - A member left: the collection moves to the next key epoch.
endedis what the membership change says each remaining member had written at the epoch being left: a record at that old epoch is still taken (a member that had not yet caught up completes its catch-up) when it is within its origin’s end; any other record at an old epoch is refused, so a removed member (which has no end) cannot write on at the old key. - since
- What a peer lacks: the records after the sequences in
vector, per origin, at mostlimit, oldest version first. A record at an epoch other than the collection’s is served only if its origin remained when that epoch ended (the peer keeps one beyond the end as void): any other would be refused, so it is never sent and the peer’s vector never waits on it. - vector
- What this machine holds: the highest sequence of each origin.