RaftEx. Domain. Invariant
(raft_ex v0.6.0)
View Source
Explicit persistence/recovery index invariants for RaftEx.
The five indices involved are:
:snapshot_index- highest index captured in the latest snapshot:wal_persisted_index- highest index durably written to the WAL:log_last_index- highest index present in the in-memory log:commit_index- highest index known to be committed:last_applied- highest index applied to the state machine
Invariants (all must hold):
snapshot_index <= wal_persisted_indexwal_persisted_index <= log_last_indexcommit_index <= log_last_indexlast_applied <= commit_indexsnapshot_index <= last_applied(when a snapshot exists, i.e. snapshot_index > 0)
Checked via check/1 (returns :ok or {:error, reason}) and check!/1
(raises RaftEx.Domain.Invariant.Violation when checks are enabled). Checks
are gated by Application.get_env(:raft_ex, :invariant_checks) (:off by
default, :test/:debug to enable).
Summary
Functions
Pure check: returns :ok or {:error, reason}. Enforces all five documented invariants including WAL<=log.
Raises on violation when checks are enabled; no-op when :off. Uses check/1.
Recovery-relevant check: WAL may legitimately be ahead of the in-memory log (e.g. after truncation of a conflicting suffix before WAL truncation), so only the ordering that must hold post-recovery is enforced.
Raises on violation when checks are enabled; no-op when :off. Uses check_recovery/1.
Convenience: build an indices map from a keyword list.
Returns the current check mode.
Types
@type indices() :: %{ optional(:snapshot_index) => non_neg_integer(), optional(:wal_persisted_index) => non_neg_integer(), optional(:log_last_index) => non_neg_integer(), optional(:commit_index) => non_neg_integer(), optional(:last_applied) => non_neg_integer() }
Functions
Pure check: returns :ok or {:error, reason}. Enforces all five documented invariants including WAL<=log.
@spec check!(indices()) :: :ok
Raises on violation when checks are enabled; no-op when :off. Uses check/1.
Recovery-relevant check: WAL may legitimately be ahead of the in-memory log (e.g. after truncation of a conflicting suffix before WAL truncation), so only the ordering that must hold post-recovery is enforced.
@spec check_recovery!(indices()) :: :ok
Raises on violation when checks are enabled; no-op when :off. Uses check_recovery/1.
Convenience: build an indices map from a keyword list.
@spec mode() :: :off | :test | :debug
Returns the current check mode.