Karta. Relay
(Karta v1.0.0)
Carries the announcements that must reach every replica through the database, so that replicas need no Erlang clustering:
Karta.Changesannouncements (the admin pages' live updates);- the route cache's "reload" (
Karta.Inbound.Directory.changed/0); - the disconnect of a signed-out or removed user's LiveViews
(
KartaWeb.UserAuth).
Each is delivered at once on this node and, over the Erlang cluster
(Karta.Cluster), on the connected replicas (Phoenix.PubSub.broadcast/3);
it is also sent through the database with Oban.Notifier (Postgres
LISTEN/NOTIFY), which every replica already listens on, for the
replicas that are not connected: one that has not joined, or is on the
other side of a network split. A replica ignores what it sent itself and
what a connected replica already sent it over the cluster.
An announcement is best effort: when the database cannot carry it, it is logged and the other replicas learn of the change by their periodic reload (the route cache every minute) or when the page next loads. Announcements carry ids at most, never content, and a list of ids is cut into several notifications so that none passes the 8,000 bytes Postgres allows.
Behind a transaction pooler (KARTA_DATABASE_POOLER=pgbouncer) the
notifier is Oban.Notifiers.PG, which needs the nodes clustered; the
relay then reaches the connected nodes only.
Summary
Functions
Announces a Karta.Changes.Change on this node and the others.
Returns a specification to start this module under a supervisor.
Disconnects the LiveViews of a session (its live_socket_id) everywhere.
Tells the replicas that something happened to a messaging connector
(Karta.Messaging): :commands (a command waits in its outbox), :replaced
(a newer session took the connector; arg is its id), :revoked,
:settings, :command_done (arg is the command's id). A replica that
holds the connector's agent connection reacts; one that does not ignores
it, and every such connection also checks the database every few seconds,
so a lost announcement only delays.
Announces that the inbound routes changed.
Functions
@spec change(Karta.Changes.Change.t()) :: :ok
Announces a Karta.Changes.Change on this node and the others.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec disconnect(String.t()) :: :ok
Disconnects the LiveViews of a session (its live_socket_id) everywhere.
@spec messaging( Ecto.UUID.t(), :commands | :replaced | :revoked | :settings | :command_done, String.t() | nil ) :: :ok
Tells the replicas that something happened to a messaging connector
(Karta.Messaging): :commands (a command waits in its outbox), :replaced
(a newer session took the connector; arg is its id), :revoked,
:settings, :command_done (arg is the command's id). A replica that
holds the connector's agent connection reacts; one that does not ignores
it, and every such connection also checks the database every few seconds,
so a lost announcement only delays.
@spec routes_changed(String.t()) :: :ok
Announces that the inbound routes changed.