Skip to main content

Module lease

Module lease 

Source
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.
FenceGuard
Resource side: refuses commands that carry an older term than one already seen. Persist export so a restart keeps refusing.
LeaseAsk
A candidate asks for (or renews) a lease.
LeaseConfig
How a lease is held.
LeaseDeny
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).
LeaseFree
The holder lets go (also the answer to one).
LeaseGrant
A voter granted it.
LeaseHandle
A held lease. Valid only while is_valid; carry term in every fenced command.
LeaseLimits
Per-lease limits a Voter applies (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 with Voter::with_limits; a job’s own JobRules set them for its claim lease.
LeaseName
A lease name, scoped by the app: ymir.scheduler, ymir.jobs/<job id>. 1 to 200 of A-Z a-z 0-9 . - _ : / + #.
LeaseRecord
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§

LeaseError
Why a lease was not got or kept.
LeaseState
What an Elector sees.
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.