Fact.EventLedger (Fact v0.1.0)
View SourceManages 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
Functions
Returns a specification to start this module under a supervisor.
Types
@type t() :: %Fact.EventLedger{ database_id: Fact.database_id(), position: Fact.event_position(), replacements: map(), schema: Fact.event_record_schema() }
@type write_events_error() :: {:error, {:event_write_failed, [{File.posix(), Fact.record_id()}]}}
@type write_ledger_error() :: {:error, {:ledger_write_failed, File.posix()}}
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec commit( Fact.database_id(), Fact.event() | [Fact.event()], Fact.append_condition(), keyword() ) :: {:ok, Fact.event_position()} | {:error, term()}
@spec start_link([{:database_id, Fact.database_id()}] | []) :: {:ok, pid()} | {:error, term()}