Fact.EventLedger (Fact v0.1.0)

View Source

Manages the event ledger for a Fact database instance, handling all commits, enforcing optimistic concurrency control via position expectations or query conditions.

Fact.EventLedger is a GenServer responsible for:

  • Writing event record files, and appending to the ledger.
  • Ensuring events are enriched with metadata, ids, timestamps, and store positions
  • Publishing appended events via Fact.EventPublisher
  • Tracking the current ledger position and maintaining order.

It's the Judge Judy of the system.

Summary

Types

t()

@type t() :: %Fact.EventLedger{
  database_id: Fact.database_id(),
  position: Fact.event_position(),
  replacements: map(),
  schema: Fact.event_record_schema()
}

write_events_error()

@type write_events_error() ::
  {:error, {:event_write_failed, [{File.posix(), Fact.record_id()}]}}

write_ledger_error()

@type write_ledger_error() :: {:error, {:ledger_write_failed, File.posix()}}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

commit(database_id, events, append_condition \\ nil, options \\ [])

@spec commit(
  Fact.database_id(),
  Fact.event() | [Fact.event()],
  Fact.append_condition(),
  keyword()
) :: {:ok, Fact.event_position()} | {:error, term()}

start_link(opts)

@spec start_link([{:database_id, Fact.database_id()}] | []) ::
  {:ok, pid()} | {:error, term()}