FIX.Session.Store.ETS (fix_session v0.1.2)

Copy Markdown View Source

Default session store: an ETS table held by a supervised owner process.

The table is owned by this process rather than by a session, so sequence state survives a session-process crash and reconnect, and a replacement session resumes where the dead one stopped instead of restarting at sequence 1. It is not crash durable: the table dies with its owner and with the VM.

Store operations take the table itself as the store_ref and run in the calling session's process; the owner is only consulted for table/1 and dump/2.

Options

  • :name — the table name, FIX.Session.Store.ETS by default, which also serves as the store_ref. Pass nil for an unnamed table (isolated, so safe for async: true tests) and use table/1 as the store_ref.

  • :file — snapshot path. When set, a snapshot is restored at start-up if the file exists and dumped on graceful shutdown. This is best-effort only: after a hard crash the snapshot on disk is stale, and restoring it would resume at sequence numbers already sent. A file that exists but cannot be verified fails start-up rather than silently resetting sequences to 1.

Error semantics

load/2, save_inbound/3, and commit_outbound/5 report a missing table as {:error, :store_unavailable}. get_outbound/3 instead raises when the table is gone: its :error return must mean "never stored" and nothing else, because the resend path answers it with a SequenceReset-GapFill.

Summary

Functions

Returns a specification to start this module under a supervisor.

Writes a snapshot of the current table contents to path.

Returns the owner's table, for use as a session's store_ref.

Types

store_ref()

@type store_ref() :: :ets.table()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

dump(owner, path)

@spec dump(GenServer.server(), Path.t()) :: :ok | {:error, term()}

Writes a snapshot of the current table contents to path.

start_link(options \\ [])

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

table(owner)

@spec table(GenServer.server()) :: store_ref()

Returns the owner's table, for use as a session's store_ref.