Fact.EventLedger (Fact v0.2.1)
View SourceThis is the Judge Judy of the system, it manages the event ledger for a Fact database instance, handling all commits, enforcing optimistic concurrency control via append 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
Summary
Types
Defines the options that can be specified when committing.
Defines the options for starting a Fact.EventLedger.
Functions
Returns a specification to start this module under a supervisor.
Commits an event or set of events.
Starts the event ledger process.
Types
@type commit_option() :: {:timeout, timeout()}
Defines the options that can be specified when committing.
:timeout(default: 5000) - specifies how long the caller should wait for the commit operation to complete in milliseconds
@type option() :: {:database_id, Fact.database_id()}
Defines the options for starting a Fact.EventLedger.
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() | nil, [commit_option()] ) :: {:ok, Fact.event_position()} | {:error, term()}
Commits an event or set of events.
Each event is enriched with additional metadata, including a timestamp, and assigning a store position. Events are then written to the configured storage and a reference to the event is appended to the ledger file.
If the commit operation is successful, an {:appended, {record_id, event}} message will be published by the
Fact.EventPublisher for each event that was written.
Starts the event ledger process.