Per-request ordered Mimir.Event buffer.
Two ETS tables: a seq counter and an ordered-set event store, both keyed
by a request id. Table names default to :mimir_turn_seq /
:mimir_turn_events and are configurable via :mimir, :turn_events_tables
(a {seq_table, buf_table} tuple) — set this if an embedder needs to run
more than one buffer instance side by side.
The "current" request id is held in the process dictionary; the embedder
sets it (put_current/1) at the start of a request, telemetry handlers and
the embedder append under it (append_current/1), and the embedder drains
the buffer with take/1 (or take_current/0) when it meters the request.
The buffer owns seq/ts, not the caller. append/2 accepts the
caller's %Mimir.Event{} as-given, but stamps it with the request's next
1-based insertion-order seq and the append-time monotonic ts before
storing it — whatever seq/ts the caller's constructor set is
overwritten. take/1/take_current/0 return events in that
buffer-assigned seq order, carrying the buffer-assigned seq/ts.
A TTL sweep reclaims buffers orphaned by a crashed request.
Summary
Functions
Append one event under rid. No-op for a nil id. Never raises.
Append under the process-current id.
Returns a specification to start this module under a supervisor.
The process-local current request id, or nil.
Set the process-local current request id (the buffer key).
Start the buffer's table owner. opts are unused; accepted for supervision-tree conformance.
Take (and clear) the seq-ordered event list for rid.
Take the current id's list and clear the current id.
Types
Functions
@spec append(request_id() | nil, Mimir.Event.t()) :: :ok
Append one event under rid. No-op for a nil id. Never raises.
The buffer owns seq/ts: the stored event's seq is replaced with the
request's next 1-based insertion-order counter and ts with the
append-time monotonic clock, overwriting whatever event.seq/event.ts
the caller's constructor set.
@spec append_current(Mimir.Event.t()) :: :ok
Append under the process-current id.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec current() :: request_id() | nil
The process-local current request id, or nil.
@spec put_current(request_id() | any()) :: :ok
Set the process-local current request id (the buffer key).
@spec start_link(keyword()) :: GenServer.on_start()
Start the buffer's table owner. opts are unused; accepted for supervision-tree conformance.
@spec take(request_id() | nil) :: [Mimir.Event.t()]
Take (and clear) the seq-ordered event list for rid.
@spec take_current() :: [Mimir.Event.t()]
Take the current id's list and clear the current id.