Buffer-owned admission state for crash-recovery swap writes.
The state bounds work to one active preparation and one latest pending snapshot. Its generation advances on every admission and invalidation, so a prepared older snapshot cannot publish after newer work becomes authoritative.
Summary
Types
The active preparation worker: snapshot, worker pid, and monitor.
Monotonic swap admission generation.
An admitted buffer snapshot: generation, source path, and content.
Function that starts the debounce timer for an admitted swap.
Functions
Admits a snapshot, starting it immediately or replacing the latest pending work.
Returns the configured storage backend.
Returns backend options for a generation, including the swap directory.
Completes matching active work and returns the latest pending snapshot, if any.
Completes matching active work identified by its process monitor.
Returns true when this buffer has a configured swap directory.
Consumes the matching timer token and rejects stale timer messages.
Invalidates every admitted write and returns resources the Buffer process must revoke.
Builds swap admission state from Buffer start options.
Checks whether a worker's prepared result is still the newest admitted snapshot.
Records the current debounce timer and its stale-message token.
Clears the current timer and returns its timer reference for cancellation.
Returns the configured debounce timer starter.
Records the monitored worker that is preparing an admitted snapshot.
Types
The active preparation worker: snapshot, worker pid, and monitor.
@type generation() :: non_neg_integer()
Monotonic swap admission generation.
@type snapshot() :: {generation(), String.t(), binary()}
An admitted buffer snapshot: generation, source path, and content.
@type t() :: %Minga.Buffer.State.Swap{ active: active_work() | nil, backend: module() | nil, backend_options: keyword(), directory: String.t() | nil, generation: generation(), pending: snapshot() | nil, timer: reference() | nil, timer_start: timer_start(), timer_token: reference() | nil }
@type timer_start() :: (pid(), term(), non_neg_integer() -> reference())
Function that starts the debounce timer for an admitted swap.
Functions
Admits a snapshot, starting it immediately or replacing the latest pending work.
Returns the configured storage backend.
@spec backend_options(t(), generation()) :: keyword()
Returns backend options for a generation, including the swap directory.
Completes matching active work and returns the latest pending snapshot, if any.
@spec complete_monitor(t(), pid(), reference()) :: {:ok, generation(), snapshot() | nil, t()} | :unknown
Completes matching active work identified by its process monitor.
Returns true when this buffer has a configured swap directory.
Consumes the matching timer token and rejects stale timer messages.
@spec invalidate(t()) :: {reference() | nil, active_work() | nil, t()}
Invalidates every admitted write and returns resources the Buffer process must revoke.
Builds swap admission state from Buffer start options.
@spec publication_status(t(), pid(), generation()) :: :current | :obsolete | :unknown
Checks whether a worker's prepared result is still the newest admitted snapshot.
Records the current debounce timer and its stale-message token.
Clears the current timer and returns its timer reference for cancellation.
@spec timer_start(t()) :: timer_start()
Returns the configured debounce timer starter.
Records the monitored worker that is preparing an admitted snapshot.