Karta.Cluster (Karta v1.0.0)

How replicas find each other: through the database they already share (libcluster_postgres, our fork: a heartbeat over Postgres LISTEN/NOTIFY that reconnects, validates what it hears and takes a URL).

Clustering is for speed and for the admin pages' live updates across replicas; nothing depends on it for correctness. Every claim, limit and schedule is in the database, so a replica that has not joined, a network split or a rollout of every replica loses nothing (see the Running several replicas guide). Discovery fails soft: a problem is logged once and Karta runs unclustered.

Settings:

  • KARTA_CLUSTER=true switches it on (off by default);
  • KARTA_CLUSTER_DATABASE_URL is the connection discovery listens on. LISTEN needs a direct connection to Postgres, which a transaction pooler (KARTA_DATABASE_POOLER) does not give: with a pooler and no such URL, clustering stays off; without a pooler the main DATABASE_URL is used.

Discovery only says who exists. Replicas must run in distributed mode with a node name their peers can resolve (the release's bin/server sets RELEASE_DISTRIBUTION=name and RELEASE_NODE=karta@<pod address> when KARTA_CLUSTER=true), share the cookie (RELEASE_COOKIE), and reach each other on TCP 4369 (epmd) and the distribution port (KARTA_DIST_PORT, 9100 by default) - between the replicas only.

Summary

Functions

The number of connected replicas, this one included.

The libcluster topologies for the environment env (a map of variables) and the notes to log: {[], []} when clustering is off, {[], [note]} when it was asked for and cannot run (never raises).

Functions

size()

@spec size() :: pos_integer()

The number of connected replicas, this one included.

topologies(env, node \\ node(), strategy \\ LibclusterPostgres.Strategy)

@spec topologies(%{optional(String.t()) => String.t()}, atom(), module()) ::
  {keyword(), [String.t()]}

The libcluster topologies for the environment env (a map of variables) and the notes to log: {[], []} when clustering is off, {[], [note]} when it was asked for and cannot run (never raises).