ExAthena.Sessions.Stores.ETS (ExAthena v0.7.1)

Copy Markdown View Source

ETS-backed store implementing both ExAthena.Sessions.Store (event-log) and ExAthena.Sessions.SchemaStore (row-shaped sessions / messages / snapshots).

Tables

NameTypeKey
:ex_athena_session_rows:setsession_id
:ex_athena_message_rows:ordered_set{session_id, seq, message_id}
:ex_athena_snapshot_rows:ordered_set{session_id, message_id, snapshot_id}
:ex_athena_snapshot_index:setsnapshot_id
:ex_athena_session_events:ordered_set{session_id, monotonic_time}

:ex_athena_snapshot_index is an internal inverse index maintained by put_snapshot/1 and cleared by delete_snapshots_for_session/1. It enables O(1) lookup in get_snapshot/1 without scanning :ex_athena_snapshot_rows.

The GenServer owns table creation. All public CRUD operations work without the GenServer's pid — reads are lock-free.

Durability

ETS is in-memory; data survives process crashes (tables are public) but not BEAM restarts. Call migrate_jsonl/1 at boot to replay an existing JSONL store into the row tables.

Summary

Functions

Returns a specification to start this module under a supervisor.

Import sessions from a JSONL root directory into the ETS row tables.

Test helper: wipe all tables. Not part of the Store contract.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

migrate_jsonl(opts \\ [])

@spec migrate_jsonl(keyword()) ::
  {:ok, %{sessions: non_neg_integer(), messages: non_neg_integer()}}

Import sessions from a JSONL root directory into the ETS row tables.

Options:

  • :root — directory of <sid>.jsonl files. Defaults to Path.join(File.cwd!(), ".exathena/sessions").
  • :overwrite — when true (default), existing rows for a session are wiped before re-importing. When false, sessions already present in the store are skipped entirely.

Returns {:ok, %{sessions: n, messages: m}}.

reset()

@spec reset() :: :ok

Test helper: wipe all tables. Not part of the Store contract.