AuroraMeter.Flusher (Aurora Meter v0.3.0)

View Source

Periodically persists dirty ETS counters to the database, and once more on shutdown so a deploy never drops the last interval of usage.

Each cycle snapshots the dirty-key set and, per key, deletes the dirty mark and takes the pending delta (what this node added since its last flush). Deltas are written with value = value + Δ (AuroraMeter.Storage.add_counters/1), so several nodes flushing the same counter add up instead of overwriting one another. The database returns the resulting totals; this node re-bases its view on them and announces them to the cluster (AuroraMeter.Cluster).

Deleting the dirty mark per key (not the whole table) means a key re-marked mid-sweep survives to the next cycle. If the database write fails the taken deltas are put back and re-marked dirty, the error is logged and reported via [:aurora_meter, :flush, :error], and the process keeps running; a database outage costs latency, not usage. Period counters go to aurora_meter_counters, day buckets to aurora_meter_history.

Summary

Functions

Returns a specification to start this module under a supervisor.

Flushes dirty counters now, returning the number of keys persisted.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

flush()

@spec flush() :: {:ok, non_neg_integer()}

Flushes dirty counters now, returning the number of keys persisted.