SaltDns. Knot. ConfigServer
(Salt v1.0.0)
The single global process that owns Knot's control socket while a configuration transaction is open.
Knot allows one conf-begin ... conf-commit transaction at a time (a
second conf-begin fails with "too many transactions"), and the
transaction belongs to the thread of the control connection that opened it:
while it is open, a command from any other connection can be served by
another thread and make the next conf-set fail with "transaction thread
mismatch". So two rules, both kept here:
exclusive/3: everything that changes the configuration (ensure_zone,remove_zone,set_dnssec) runs its wholeconf-begin...conf-commitinside it, strictly one at a time;shared/3: every other use of the control socket (reads, status, zone transactions) holds a shared lock while it talks to Knot. Shared holders run in parallel with each other, never while an exclusive section runs, and an exclusive section waits for the holders to finish. Requests are served in arrival order, so neither side starves.
The shared lock is also a counting semaphore: at most :max_shared holders
at a time (default 4; config :salt_dns, SaltDns.Knot.ConfigServer, max_shared: n, or the :max_shared option of start_link/1). Knot's
control socket is a Unix socket with a small accept backlog; when it is full
a connect fails at once with EAGAIN ("temporarily out of resources"), so
unbounded parallel knotc processes break each other. I could not confirm
the backlog size in the Knot 3.6 documentation available here; a full
Unix-socket backlog is what that error reports. The adapter also retries
that one transient connect error (see SaltDns.Knot.Knotc).
Both are re-entrant: code already inside either one (the exclusive function runs in this process; a shared holder is marked in its own process) runs nested calls directly.
If the function raises, the error is returned and the server stays alive; the function is responsible for aborting its own transaction (the Knotc adapter does, in all paths). A shared holder that dies releases its lock.
Summary
Functions
Returns a specification to start this module under a supervisor.
Runs fun while holding the configuration lock and returns its result.
Concurrent callers queue in arrival order.
Runs fun (in the calling process) while holding a shared lock on the
control socket: it may run beside other shared holders, never beside an
exclusive section. Nested inside either, it just runs.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec exclusive(GenServer.server(), (-> result), timeout()) :: result | {:error, term()} when result: term()
Runs fun while holding the configuration lock and returns its result.
Concurrent callers queue in arrival order.
@spec start_link(keyword()) :: GenServer.on_start()