ViewstampedReplication.Storage behaviour (viewstamped_replication v0.1.0)

Copy Markdown View Source

Durable-state adapter contract used by a replica runtime.

Adapter state is owned by the replica process. Mutating callbacks return the updated adapter state so storage implementations do not need a process of their own.

Summary

Types

recovered_state()

@type recovered_state() :: %{
  configuration_hash: binary(),
  replica_id: term(),
  hard_state: map(),
  log: ViewstampedReplication.Log.t(),
  commit_number: non_neg_integer(),
  applied_number: non_neg_integer(),
  snapshot: term() | nil,
  client_table: map()
}

Callbacks

append(term, arg2)

@callback append(
  term(),
  ViewstampedReplication.LogEntry.t() | [ViewstampedReplication.LogEntry.t()]
) ::
  {:ok, term()} | {:error, term()}

close(term)

@callback close(term()) :: :ok | {:error, term()}

install_snapshot(term, term)

@callback install_snapshot(term(), term()) :: {:ok, term()} | {:error, term()}

install_state(term, map)

@callback install_state(term(), map()) :: {:ok, term()} | {:error, term()}

open(keyword)

@callback open(keyword()) :: {:ok, term()} | {:error, term()}

persist_hard_state(term, map)

@callback persist_hard_state(term(), map()) :: {:ok, term()} | {:error, term()}

recover(term)

@callback recover(term()) :: {:ok, recovered_state(), term()} | {:error, term()}

set_applied(term, non_neg_integer, map)

@callback set_applied(term(), non_neg_integer(), map()) ::
  {:ok, term()} | {:error, term()}

set_commit_number(term, non_neg_integer)

@callback set_commit_number(term(), non_neg_integer()) :: {:ok, term()} | {:error, term()}

truncate_suffix(term, non_neg_integer)

@callback truncate_suffix(term(), non_neg_integer()) :: {:ok, term()} | {:error, term()}

write_snapshot(term, term)

@callback write_snapshot(term(), term()) :: {:ok, term()} | {:error, term()}