RaftEx.Snapshot behaviour (raft_ex v0.1.0)

View Source

Summary

Callbacks

accept_chunk(chunk, accept_state)

@callback accept_chunk(chunk :: term(), accept_state :: term()) ::
  {:ok, term()} | {:error, term()}

begin_accept(snap_dir, meta)

@callback begin_accept(snap_dir :: String.t(), meta :: map()) ::
  {:ok, accept_state :: term()} | {:error, term()}

begin_read(location, context)

@callback begin_read(location :: String.t(), context :: map()) ::
  {:ok, meta :: map(), read_state :: term()} | {:error, term()}

complete_accept(chunk, accept_state)

@callback complete_accept(chunk :: term(), accept_state :: term()) ::
  :ok | {:ok, non_neg_integer()} | {:error, term()}

context()

(optional)
@callback context() :: map()

get_size(location)

(optional)
@callback get_size(location :: String.t()) :: {:ok, non_neg_integer()} | {:error, term()}

prepare(index, state)

@callback prepare(index :: non_neg_integer(), state :: term()) :: ref :: term()

read_chunk(read_state, chunk_bytes, location)

@callback read_chunk(
  read_state :: term(),
  chunk_bytes :: non_neg_integer(),
  location :: String.t()
) :: {:ok, chunk :: term(), {:next, term()} | :last} | {:error, term()}

read_meta(location)

@callback read_meta(location :: String.t()) :: {:ok, map()} | {:error, term()}

recover(location)

@callback recover(location :: String.t()) :: {:ok, map(), term()} | {:error, term()}

sync(location)

@callback sync(location :: String.t()) :: :ok | {:error, term()}

validate(location)

@callback validate(location :: String.t()) :: :ok | {:error, term()}

write(location, meta, ref, sync)

@callback write(location :: String.t(), meta :: map(), ref :: term(), sync :: boolean()) ::
  :ok | {:ok, bytes :: non_neg_integer()} | {:error, term()}