Rheo.Backend.Capabilities (rheo v1.0.0)

Copy Markdown View Source

Typed backend capability declaration (ADR 023).

A backend declares two kinds of facts:

  • guarantees — semantic promises Rheo makes through this backend. The conformance suite gates correctness tests on them.
  • mechanisms — how the backend implements or optimizes delivery. They select optional conformance cases and runtime optimizations, never correctness.

at_least_once and lease_fencing are Rheo product invariants: they default to true and may not be declared false.

Guarantees

KeyMeaning
:durableEvents and delivery state survive a backend process restart
:distributedSeveral BEAM nodes may fetch from the same group concurrently
:at_least_onceAlways true
:lease_fencingAlways true
:partitionsMulti-partition streams with per-partition sequences
:contiguous_frontierRheo.lag/3 reports a contiguous ACK frontier
:replayRheo.replay/3 and Rheo.reset_group/3 are supported

See the building your own backend guide for a per-backend comparison (Redis / Postgres yes; ETS / SQLite / Mnesia v0.11 no).

Mechanisms

KeyMeaning
:atomic_compare_and_setClaims use a native atomic compare-and-set
:ordered_range_scanSequence ranges are read with an ordered scan
:secondary_indexesPayload / metadata filters use secondary indexes
:batch_writesappend_batch is a single backend write
:notificationsThe backend can signal new events (for example NOTIFY)
:change_feedThe backend exposes a change feed
:native_consumer_groupsThe backend owns consumer-group state (Redis Streams)
:native_pending_listPending deliveries are backend-native (XPENDING)
:native_reclaimExpired claims are reclaimed natively (XAUTOCLAIM)
:blocking_readsFetch can block until work arrives (XREADGROUP BLOCK)
:native_group_lagLag comes from the backend (XINFO GROUPS)

Examples

iex> caps = Rheo.Backend.Capabilities.new(durable: true, partitions: true, batch_writes: true)
iex> {caps.guarantees.durable, caps.guarantees.at_least_once, caps.mechanisms.batch_writes}
{true, true, true}

iex> Rheo.Backend.Capabilities.guarantee?(Rheo.Backend.Capabilities.new([]), :durable)
false

iex> Rheo.Backend.Capabilities.new(durable: "yes")
** (ArgumentError) capability :durable must be a boolean, got: "yes"

iex> Rheo.Backend.Capabilities.new(lease_fencing: false)
** (ArgumentError) capability :lease_fencing is a Rheo invariant and cannot be false

Summary

Types

Raw boolean map passed to new/1 before defaults are filled.

t()

Declared guarantees and mechanisms; every known key is present.

Functions

Whether the backend declares guarantee key.

Known guarantee keys.

Whether the backend declares mechanism key.

Known mechanism keys.

Builds a validated declaration.

Types

flags()

@type flags() :: %{required(atom()) => boolean()}

Raw boolean map passed to new/1 before defaults are filled.

t()

@type t() :: %Rheo.Backend.Capabilities{guarantees: flags(), mechanisms: flags()}

Declared guarantees and mechanisms; every known key is present.

Functions

guarantee?(capabilities, key)

@spec guarantee?(t(), atom()) :: boolean()

Whether the backend declares guarantee key.

guarantee_keys()

@spec guarantee_keys() :: [atom()]

Known guarantee keys.

mechanism?(capabilities, key)

@spec mechanism?(t(), atom()) :: boolean()

Whether the backend declares mechanism key.

mechanism_keys()

@spec mechanism_keys() :: [atom()]

Known mechanism keys.

new(flags)

@spec new(keyword() | map()) :: t()

Builds a validated declaration.

Arguments

  • flags — keyword list or map of known keys to booleans. Omitted keys are false, except the invariants, which are true.

Errors

Raises ArgumentError on an unknown key, a non-boolean value, or an invariant declared false.