Ankusa.Queue.DedupeSweeper (ankusa v0.7.0)

Copy Markdown View Source

Expires ingest-dedupe keys (?u, with their ?e expiry index) once their ttl has passed, so the dedupe index stays bounded by dedupe.max_entries.

One process per instance, next to Ankusa.Queue.Writer and never inside it. The sweep itself (the scan of ?e, the key decoding, the tenant ordinals, the batching) runs here: every @interval_ms, and then back to back for as long as a full chunk of expired keys keeps coming, so it keeps pace with an ingest rate of tens of thousands of keys a second. What it hands the writer is one batch of at most @chunk keys at a time ({:expire_dedupe, entries}), because a refresh and a delete of one key must not race: the writer deletes a key only if it still holds the expiry the sweep read, and takes the key off the tenant's and the node's dedupe counter in the same batch.

Emits [:ankusa, :dedupe, :pruned] (count) for every batch that removed keys. A failed chunk is logged and retried on the next tick; sweep/1 runs the sweep to completion, for a test or an operator.

Summary

Functions

Returns a specification to start this module under a supervisor.

Sweep every key expired as of now, synchronously: {:ok, deleted}.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

sweep(instance)

@spec sweep(atom()) :: {:ok, non_neg_integer()} | {:error, term()}

Sweep every key expired as of now, synchronously: {:ok, deleted}.