SaltDns. Knot. ZoneWriter
(Salt v1.0.0)
The single writer of one zone on the Knot primary.
All changes to a zone go through its writer, so Knot never sees overlapping transactions for it.
Ordering
Every mutation of a zone in Postgres takes the zone's next version under
the row lock (SaltDns.Zones), and the change list it causes is pushed with
that version. The writer applies lists strictly in version order. Lists that
arrive early wait in a buffer; a list that arrives twice or after it was
superseded is dropped. Mutators that commit in one order but push in the
other therefore cannot reorder what Knot sees.
The writer starts knowing nothing (applied: nil). Its first piece of work
is a full reconcile of the zone from Postgres, which also sets applied to
the zone's version, read before its rrsets. If the next version does not
arrive within gap_ms, the writer does a full reconcile as well. A reconcile
is also the answer to every failure.
Fast path
Consecutive lists are coalesced into one apply_changes call (one short
zone transaction, order kept, cut at about batch_size changes).
Full reconcile (SaltDns.Knot.Reconcile) happens when:
- the writer has not synced the zone yet (startup, or after a crash);
- a version is missing for
gap_ms; - the zone is
disabled, or a reconcile was asked for; - a delta fails for any reason.
A failed reconcile leaves the writer dirty; it retries with backoff
(retry_ms, doubling up to max_retry_ms). The writer is :temporary: a
crash restarts nothing, the next call starts a fresh writer (which
reconciles), and the periodic reconcile repairs the rest.
Busy
The writer of a zone that exists never stops, idle or not, so the number of writers
alive is the number of zones that have been written to. What "has work not yet in Knot"
means is the writer's busy state: it is dirty (a reconcile is owed or failing),
or it holds buffered change lists, or a removal is not finished. The writer keeps that
state as the value of its own entry in SaltDns.Knot.WriterRegistry, updated whenever
it changes, so busy_count/0 (the metric salt_dns_knot_writers_busy) is one ETS scan
with no message to any writer: a writer stuck in a long Knot call cannot block it.
Summary
Functions
How many writers are alive (one per zone written to, idle or not); 0 without a registry.
How many writers have work not yet in Knot: dirty, buffered lists, or a removal not finished. Reads the registry only; 0 when it is not running.
Returns a specification to start this module under a supervisor.
Functions
@spec alive_count() :: non_neg_integer()
How many writers are alive (one per zone written to, idle or not); 0 without a registry.
@spec busy_count() :: non_neg_integer()
How many writers have work not yet in Knot: dirty, buffered lists, or a removal not finished. Reads the registry only; 0 when it is not running.
Returns a specification to start this module under a supervisor.
See Supervisor.