MailglassInbound.RateLimiter.TableOwner (MailglassInbound v2.2.0)

Copy Markdown View Source

Owns the :mailglass_inbound_rate_limit ETS table and the small amount of work that must be serialized: missing-key admission, bounded contention fallback, and idle sweeping. Mailglass.RateLimiter.AtomicBucket keeps the normal path as a fixed-point compare-and-swap loop; only exhausted callers enter this package-local owner mailbox.

ETS opts (OTP 27+) — copied verbatim from core

  • :set — single-entry-per-key bucket
  • :public — cross-process read/write without owner-forwarding
  • :named_table — caller references :mailglass_inbound_rate_limit directly
  • read_concurrency: true — hot read path optimization
  • write_concurrency: :auto — OTP 27 flag for lock striping
  • decentralized_counters: true — OTP 27 flag, per-scheduler counters

Crash semantics

If this process crashes, BEAM deletes the ETS table. The supervisor restarts TableOwner and ensure_table/0 recreates the canonical table before every owner ETS operation. Counter state is intentionally ephemeral across a restart, but callers re-admit through the replacement owner rather than crashing on :badarg.

Reserved-singleton note

This module uses name: __MODULE__. It is library-internal machinery (not a user-facing singleton) and is the documented reserved-singleton exception, mirroring Mailglass.RateLimiter.TableOwner. The inbound ETS table must be a process-stable named table so the limiter hot path can reach it without a registry lookup.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the ETS table name. Public so tests can inspect state.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

table()

(since 1.2.0)

Returns the ETS table name. Public so tests can inspect state.