SaltDns.Knot.Sync (Salt v1.0.0)

Keeps the Knot primary in line with Postgres: the entry point for everything that changes zone data.

Nothing has to be called by hand. attach/0 (done at application start when auto is on, the default outside tests) listens for the [:salt_dns, :zones, :committed] events that SaltDns.Zones emits after each committed mutation and forwards them: record changes to push/3 with the zone's new version, zone creation and updates to reconcile/1, and deletion to delete/2. Tests and other callers can use the functions directly.

Each zone has its own SaltDns.Knot.ZoneWriter, started on first use. Delivery is ordered by the zone's version (see SaltDns.Knot.ZoneWriter), at-least-once and idempotent; SaltDns.Knot.ReconcileWorker reconciles every zone periodically as the safety net.

The apex names (NS, SOA MNAME and RNAME) come from SaltDns.Apex. Settings, config :salt_dns, SaltDns.Knot.Sync: retry_ms, max_retry_ms, gap_ms (how long a missing version is waited for, default 3000), auto (listen for committed mutations), batch_size (changes per zone transaction, default 200), call_timeout (ms a synchronous call waits, default 120000).

Summary

Functions

SaltDns.Knot.apply_changes/2 for a zone's writer. The writer is the only legitimate owner of the zone's transaction, so if Knot reports one already open it is a leftover of a crashed predecessor: abort it and try once more.

Starts forwarding committed zone mutations to the writers. Idempotent.

Removes a deleted zone from the primary.

Waits until everything queued for the zone has been delivered.

Queues the change list of one committed mutation, with the zone version it produced, and returns at once. A mutation that changed no record still has a version: push it with [] so the writer does not wait for it.

Delivers the change list and waits. Returns :ok once Knot has it (directly, or through a reconcile when versions were missing) or {:error, reason}; the writer keeps retrying a failed zone in the background.

Asks for a full reconcile of the zone and returns at once.

Reconciles the zone now and waits for the outcome.

The apex NS names, the SOA MNAME and the hostmaster mailbox name (SaltDns.Apex).

Types

zone_id()

@type zone_id() :: integer()

Functions

apply_changes(name, changes)

@spec apply_changes(String.t(), [SaltDns.Zones.Change.t()]) :: :ok | {:error, term()}

SaltDns.Knot.apply_changes/2 for a zone's writer. The writer is the only legitimate owner of the zone's transaction, so if Knot reports one already open it is a leftover of a crashed predecessor: abort it and try once more.

attach()

@spec attach() :: :ok

Starts forwarding committed zone mutations to the writers. Idempotent.

delete(zone_id, zone_name)

@spec delete(zone_id(), String.t()) :: :ok

Removes a deleted zone from the primary.

flush(zone_id)

@spec flush(zone_id()) :: :ok | {:error, term()}

Waits until everything queued for the zone has been delivered.

push(zone_id, version, changes)

@spec push(zone_id(), version :: non_neg_integer(), [SaltDns.Zones.Change.t()]) :: :ok

Queues the change list of one committed mutation, with the zone version it produced, and returns at once. A mutation that changed no record still has a version: push it with [] so the writer does not wait for it.

push_sync(zone_id, version, changes)

@spec push_sync(zone_id(), non_neg_integer(), [SaltDns.Zones.Change.t()]) ::
  :ok | {:error, term()}

Delivers the change list and waits. Returns :ok once Knot has it (directly, or through a reconcile when versions were missing) or {:error, reason}; the writer keeps retrying a failed zone in the background.

reconcile(zone_id)

@spec reconcile(zone_id()) :: :ok

Asks for a full reconcile of the zone and returns at once.

reconcile_sync(zone_id)

@spec reconcile_sync(zone_id()) :: :ok | {:error, term()}

Reconciles the zone now and waits for the outcome.

settings()

@spec settings() :: SaltDns.Knot.Desired.settings()

The apex NS names, the SOA MNAME and the hostmaster mailbox name (SaltDns.Apex).