graft v0.1.0 Graft.Machine behaviour

A behaviour module for implementing a replicated machine for the raft consensus algorithm. Look at the Graft module docs for examples on how to create such machines.

Link to this section Summary

Types

The entry request sent by the client.

The reply to be sent back to the client.

The state/data of the replicated machine (similar to the 'state' of GenServer).

Functions

Returns a specification to start this module under a supervisor.

Callbacks

Invoked when a server in the raft cluster is commiting an entry to its log. Should apply the entry to the replicated machine.

Invoked when the server starts and links to the machine.

Link to this section Types

Link to this type

entry()

entry() :: any()

The entry request sent by the client.

Link to this type

response()

response() :: any()

The reply to be sent back to the client.

Link to this type

state()

state() :: any()

The state/data of the replicated machine (similar to the 'state' of GenServer).

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this section Callbacks

Link to this callback

handle_entry(entry, state)

handle_entry(entry(), state()) :: {response(), state()}

Invoked when a server in the raft cluster is commiting an entry to its log. Should apply the entry to the replicated machine.

Should return a tuple of the response for the server along with the new state of the replicated machine.

Link to this callback

init(args)

init(args :: [any()]) :: {:ok, state()}

Invoked when the server starts and links to the machine.

args is a list accepted arguments. Look at Graft.start to see how to pass in these optional arguments.

Returning {:ok, state}, will initialise the state of the machine to state.