Expand description
Majority-vote leases with fencing terms (since 0.8).
The op log is eventually consistent, so it can’t give mutual exclusion by itself. A lease
comes from a small quorum protocol between voters: the user’s devices that hold a role
grant (for Ymir, ymir.inference; Voters::Role). A candidate asks every voter at once
and holds the lease while a majority granted it, timed by its own monotonic clock and cut
short by the assumed clock-rate drift. Each new holder gets a higher Term, the fencing
token: resources refuse commands with a term older than one they have seen
(FenceGuard), so a paused or partitioned ex-holder can do no harm.
Asks and answers are Message variants on /weirdnet/sync/2, sealed
like every other request, so only active, admitted devices of the user take part. A
voter answers only candidates that are in the same voter set. Safety needs no wall clock
and no HLC; only rate drift within LeaseConfig::max_drift.
Voters keep the highest term per lease (persist Voter::export); after a restart a
voter refuses takeovers for one maximum lease duration, so it can’t hand out an
overlapping lease.
Structs§
- Elector
- Acquires and renews one lease in a background thread. No preemption: a live holder keeps
it; after a lapse the lowest-ranked candidate tries first. Dropping it (or
release) lets go. - Fence
Guard - Resource side: refuses commands that carry an older term than one already seen. Persist
exportso a restart keeps refusing. - Lease
Ask - A candidate asks for (or renews) a lease.
- Lease
Config - How a lease is held.
- Lease
Deny - A voter did not grant it: who it promised, for how much longer, and the highest term it has granted (ask with a higher one next time).
- Lease
Free - The holder lets go (also the answer to one).
- Lease
Grant - A voter granted it.
- Lease
Handle - A held lease. Valid only while
is_valid; carrytermin every fenced command. - Lease
Limits - Per-lease limits a
Voterapplies (since 0.8.1): the longest grant, and how long it refuses another holder after a promise lapsed (its holder stopped renewing without letting go). Set them per lease-name prefix withVoter::with_limits; a job’s ownJobRulesset them for its claim lease. - Lease
Name - A lease name, scoped by the app:
ymir.scheduler,ymir.jobs/<job id>. 1 to 200 ofA-Z a-z 0-9 . - _ : / + #. - Lease
Record - Who holds a lease, written to the op log on each new term for display. Nothing trusts it.
- Leases
- The candidate side: acquires, renews and releases leases through a sync node and its
shared state (as served by
crate::start_node). The state’s lock is never held across the network. - Stale
- A command from an older term than the guard has seen.
- Term
- Fencing token: strictly increases per lease name across holders.
- Voter
- The voter side (one per device, kept in
SyncState::voter). Not secret.
Enums§
- Lease
Error - Why a lease was not got or kept.
- Lease
State - What an
Electorsees. - Voters
- Who votes (and who may stand): devices with an active cert in the roster.
Constants§
- DEFAULT_
DURATION - Default time a grant lasts at a voter.
- DEFAULT_
MAX_ DRIFT - Default worst clock-rate drift assumed between devices.
- DEFAULT_
RENEW_ EVERY - Default renewal interval (a third of the duration).
- DEFAULT_
STAGGER - Default delay per candidate rank after a lapse.
- LEASE_
TYPE - The envelope type lease messages travel under.