SaltDns. Leader. Lease
(Salt v1.0.0)
The lease row in Postgres that says which node drives Knot.
Plain statements, no advisory locks, so it works through PgBouncer in
transaction mode. Time is the database's clock: the nodes' clocks are not
compared. epoch grows whenever the lease changes hands (or lapses and is
taken again) and is the fencing token.
Summary
Functions
Takes the lease if it is free (expired) or already ours. Returns the epoch. A free lease taken by anyone bumps the epoch, even by the same holder after a lapse; renewing an unexpired lease of our own keeps it.
The current row, and whether it is still valid, or nil.
Gives the lease up at once (clean shutdown).
Extends our lease if we still hold it at epoch and it has not expired.
Types
@type lease() :: %{ holder: String.t(), epoch: pos_integer(), expires_at: DateTime.t(), knot_address: String.t() | nil, valid?: boolean() }
Functions
@spec acquire(String.t(), String.t(), pos_integer(), String.t() | nil) :: {:ok, pos_integer()} | :held
Takes the lease if it is free (expired) or already ours. Returns the epoch. A free lease taken by anyone bumps the epoch, even by the same holder after a lapse; renewing an unexpired lease of our own keeps it.
The current row, and whether it is still valid, or nil.
@spec release(String.t(), String.t(), pos_integer()) :: :ok
Gives the lease up at once (clean shutdown).
@spec renew(String.t(), String.t(), pos_integer(), pos_integer()) :: :ok | :lost
Extends our lease if we still hold it at epoch and it has not expired.