ViewstampedReplication.StateMachine behaviour (viewstamped_replication v0.1.0)

Copy Markdown View Source

Contract for a deterministic service replicated by VSR.

The runtime invokes apply/3 only after an operation is committed and in operation-number order. Implementations must return the same result and state for the same metadata, operation, and prior state. They must not rely on clocks, randomness, process identity, or external side effects.

Snapshots are state-machine-owned terms. Implementations should keep their encoding stable or version snapshots explicitly.

Summary

Types

operation()

@type operation() :: term()

result()

@type result() :: term()

snapshot()

@type snapshot() :: term()

state()

@type state() :: term()

Callbacks

apply(t, operation, state)

init(keyword)

@callback init(keyword()) :: state()

restore(snapshot)

@callback restore(snapshot()) :: {:ok, state()} | {:error, term()}

snapshot(state)

@callback snapshot(state()) :: {:ok, snapshot()}