AuroraMeter. Cluster
(Aurora Meter v0.3.1)
View Source
Keeps every node's counters converging on the same totals.
Each node meters into its own ETS table. Two things make the cluster agree:
- Delta gossip. Every broadcaster tick this node publishes the deltas
it accumulated (
pending_gossip) on the"aurora_meter:cluster"topic; other nodes add them to their own view (AuroraMeter.Counter.apply_remote/2). Convergence is one:broadcast_interval(1 s by default). - Total announcements. Every flush writes deltas to Postgres and gets
the authoritative totals back; this node re-bases on them at once and
publishes them so the others re-base too
(
AuroraMeter.Counter.rebase/2). Anything gossip missed heals within one:flush_interval(5 s by default). Announced totals are applied only upward (a late announcement never drags a fresher view back); this node's own flush re-bases unconditionally.
Messages from this node are ignored (its own bumps are already in its view).
With config :aurora_meter, cluster_sync: false nothing is published or
applied and tenant broadcasts fan out cluster-wide as before. A
non-distributed Phoenix.PubSub is fine: every message is then local and
dropped, so a single node behaves exactly as it did.
Summary
Functions
Applies a batch as if it had arrived from origin, synchronously. Used by
AuroraMeter.Test.simulate_node/3 and simulate_flush/2.
Returns a specification to start this module under a supervisor.
Whether cross-node sync is on (:cluster_sync, default true).
Publishes this node's deltas ([{key, delta}]) to the other nodes.
Publishes authoritative totals ([{key, total}]) from a flush to the other nodes.
The PubSub topic nodes exchange deltas and totals on.
Functions
@spec apply(:deltas | :totals, node(), [{AuroraMeter.Counter.key(), integer()}]) :: :ok
Applies a batch as if it had arrived from origin, synchronously. Used by
AuroraMeter.Test.simulate_node/3 and simulate_flush/2.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec enabled?() :: boolean()
Whether cross-node sync is on (:cluster_sync, default true).
@spec publish_deltas([{AuroraMeter.Counter.key(), integer()}]) :: :ok
Publishes this node's deltas ([{key, delta}]) to the other nodes.
@spec publish_totals([{AuroraMeter.Counter.key(), integer()}]) :: :ok
Publishes authoritative totals ([{key, total}]) from a flush to the other nodes.
@spec topic() :: String.t()
The PubSub topic nodes exchange deltas and totals on.