Runic.Runner.Store.Mnesia (Runic v0.1.0-alpha.7)

Copy Markdown View Source

Mnesia-backed persistence adapter for the Runner.

Uses Erlang/OTP's built-in Mnesia database for workflow log storage. Provides persistence across VM restarts (via disc_copies) and distributed storage across Erlang clusters.

Usage

children = [
  {Runic.Runner.Store.Mnesia, runner_name: MyApp.Runner, disc_copies: true},
  {Runic.Runner,
   name: MyApp.Runner,
   store: Runic.Runner.Store.Mnesia,
   store_opts: [disc_copies: true]}
]

Options

  • :runner_name — (required) the Runner name, used to derive the Mnesia table name
  • :disc_copies — when true (default), persists to disk on this node. Set to false for RAM-only tables (faster, lost on VM restart).
  • :nodes — list of nodes for distributed tables. Defaults to [node()].

Mnesia Schema

If Mnesia has not been initialized with a schema directory on this node, one will be created automatically. For production use, configure the Mnesia directory via the :mnesia application env:

config :mnesia, dir: ~c"/var/data/mnesia/#{node()}"

Distributed Operation

For multi-node Mnesia clusters, ensure :mnesia.change_config(:extra_db_nodes, nodes) is called before starting the Runner, or pass :nodes in store opts.

Stream Semantics

Supports event-sourced append/3 and stream/2 via a second Mnesia table (*EventStream) with {workflow_id, sequence} compound keys for ordered event retrieval.

Design Notes

  • Write operations use :mnesia.transaction/1 for ACID guarantees.
  • Read operations use :mnesia.dirty_read/2 — no transaction overhead, eventually consistent during concurrent writes (sufficient for workflow log reads, which are dominated by the owning Worker process).
  • checkpoint/3 delegates to save/3 — Mnesia's transaction log already provides write-ahead durability.

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)