Fact.EventLedger (Fact v0.2.1)

View Source

This 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.

Starts the event ledger process.

Types

commit_option()

(since 0.1.0)
@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

option()

(since 0.1.0)
@type option() :: {:database_id, Fact.database_id()}

Defines the options for starting a Fact.EventLedger.

Functions

child_spec(init_arg)

(since 0.1.0)

Returns a specification to start this module under a supervisor.

See Supervisor.

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

(since 0.2.0)
@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.

start_link(opts)

(since 0.1.0)
@spec start_link([option()]) :: {:ok, pid()} | {:error, term()}

Starts the event ledger process.