SaltDns. Knot. Failover
(Salt v1.0.0)
Turns the node's Knot into a primary when the node becomes the leader, and
back into a secondary of the other node when it stops being the leader.
Only runs in a cluster (SaltDns.Leader.enabled?/0).
Promotion ({:leader_event, :promoted, epoch})
- Confirm against the database that the lease is still ours at this epoch.
- Import the DNSSEC keys from Postgres into the local key store
(
SaltDns.Dnssec.KeyImport), so the zones are signed by the same keys. - Start
SaltDns.Knot.LeaderSupervisor(writers, distribution, edge catalog). - Reconcile every zone: each zone leaves the
followertemplate for its organisation's template (nomaster); Knot keeps the zone data, signatures included, and the serial never goes back (serial-policy: unixtime). - Signing is switched on by that reconcile for the zones whose DNSSEC
lifecycle says so (
SaltDns.Zones.Dnssec.knot_mode/1); a zone whose keys could not be imported is frozen instead (SaltDns.Knot.Frozen). - Only now
ready?/0is true and changes are delivered. Changes that arrive meanwhile wait in this process's mailbox.
Demotion ({:leader_event, :demoted, _}, and at boot)
First ready?/0 becomes false and the leader processes stop, so nothing
else can write. Then SaltDns.Knot.follow/2 makes every zone a secondary of
the other node without signing, and zones that were primaries here are
retransferred (a divergent change of the old leader is replaced). If Postgres
cannot be reached the zones Knot already has are kept as they are. A node that
just booted is a follower until it wins the lease, so a restarted old leader
never signs next to the new one.
While a follower, the node's zone list follows Postgres every
follower_interval ms (default 15000) and whenever a change is announced.
Summary
Functions
The PubSub topic on which the replica that holds the lease announces
{:zone_applied, name} after it changed a zone in its Knot. A follower asks its
own Knot to check the primary for that zone at once (Knot.refresh_zones/1),
instead of waiting for its poll (at most 15 s). A speed-up only: the poll and
the follower sync make it correct when a message is lost.
How many signed zones are frozen because their keys could not be imported.
Returns a specification to start this module under a supervisor.
Runs one follower sync now and waits (for tests and the console).
What a follower does with the lease row: {:point, address} when another
replica holds a valid lease and advertises a transfer address that passes
SaltDns.Knot.PeerAddress, {:invalid, address} when it advertises one that
does not, :none otherwise (no lease, an expired one, or this replica's own).
True while this node is the leader and promotion has finished.
True without a cluster, else ready?/0.
Whether this replica may take traffic (the readiness probe in a cluster): not while it is being promoted or demoted, and then either the ready leader or a follower whose Knot has loaded every zone Postgres says it should have. A new replica's Knot is empty for a few seconds while it transfers.
The role this process believes the node has: :leader, :follower or :promoting.
Functions
@spec applied_topic() :: String.t()
The PubSub topic on which the replica that holds the lease announces
{:zone_applied, name} after it changed a zone in its Knot. A follower asks its
own Knot to check the primary for that zone at once (Knot.refresh_zones/1),
instead of waiting for its poll (at most 15 s). A speed-up only: the poll and
the follower sync make it correct when a message is lost.
@spec blocked_count() :: non_neg_integer()
How many signed zones are frozen because their keys could not be imported.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec follower_sync() :: :ok | {:error, term()}
Runs one follower sync now and waits (for tests and the console).
@spec peer_target(map() | nil, String.t() | nil) :: {:point, String.t()} | {:invalid, term()} | :none
What a follower does with the lease row: {:point, address} when another
replica holds a valid lease and advertises a transfer address that passes
SaltDns.Knot.PeerAddress, {:invalid, address} when it advertises one that
does not, :none otherwise (no lease, an expired one, or this replica's own).
@spec ready?() :: boolean()
True while this node is the leader and promotion has finished.
@spec ready_or_single?() :: boolean()
True without a cluster, else ready?/0.
@spec replica_ready?() :: boolean()
Whether this replica may take traffic (the readiness probe in a cluster): not while it is being promoted or demoted, and then either the ready leader or a follower whose Knot has loaded every zone Postgres says it should have. A new replica's Knot is empty for a few seconds while it transfers.
@spec state() :: atom()
The role this process believes the node has: :leader, :follower or :promoting.