Kantoor.Cluster (Kantoor v1.0.0)

Several replicas of Kantoor behind a load balancer, each one a plain copy of the others: none is special, and any of them can serve any connection.

What must be exact lives in Postgres (login lockouts and rate limits, the mail index, DAV sync tokens, staged attachments). What only has to be fast is carried between the replicas by Phoenix.PubSub over Erlang distribution: a message ingested on one replica wakes the IMAP IDLE sessions and open pages on the others at once. Distribution is only a speed-up. Every waiting party also re-checks the database on a timer, so a replica that has not joined yet, a netsplit or a lost message costs seconds, never an update (Kantoor.CatchUp).

Replicas find each other through the database they already share, with the libcluster_postgres strategy: each announces its node name on a Postgres channel and dials the others it hears. The announcement needs a direct connection to Postgres (LISTEN does not survive a transaction-mode pooler), so it has its own setting.

Settings

  • KANTOOR_CLUSTER=true turns it on (default false: one replica, no distribution).
  • KANTOOR_CLUSTER_DATABASE_URL is the direct postgres:// URL used for discovery. Without it KANTOOR_DIRECT_DATABASE_URL is used, and without that DATABASE_URL, except with KANTOOR_DATABASE_POOLER on (DATABASE_URL then goes through the pooler): discovery stays off and the log says so. The replicas stay correct through the database (Kantoor.CatchUp); only the speed-up of distribution is missing.
  • RELEASE_COOKIE (required when clustering) is the shared secret of distribution; RELEASE_NODE defaults to kantoor@<pod IP> (KANTOOR_NODE_HOST overrides the address); KANTOOR_DIST_PORT (default 9100) is the one port distribution listens on. See rel/overlays/bin/server and the guide "Running several replicas".

If discovery cannot reach the database it logs and keeps retrying; Kantoor runs unclustered on the database catch-up meanwhile.

Summary

Functions

Supervisor children for the application tree.

Whether clustering is switched on.

The libcluster topologies for this node, [] when clustering is off or misconfigured.

Functions

children()

@spec children() :: [Supervisor.child_spec() | {module(), term()}]

Supervisor children for the application tree.

enabled?()

@spec enabled?() :: boolean()

Whether clustering is switched on.

topologies()

@spec topologies() :: keyword()

The libcluster topologies for this node, [] when clustering is off or misconfigured.