Raft v0.2.1 Raft.StateMachine behaviour

This module provides a behaviour that can be implemented by clients to make use of the replicated log.

Link to this section Summary

Types

The read or write command

The state for the state machine

The value to return to client after completing a read or write

Callbacks

Called when the leader has established that they still have a majority and haven’t been deposed as described in the raft paper section 8. While it is possible to change the state here it is HIGHLY discouraged. Changes during a read will NOT be persisted or replicated to other servers. Any mutations done here will be lost after a crash recovery or when starting a new server

Called whenever there has been a committed write command

Called when the state machine is initialized

Link to this section Types

Link to this type cmd()
cmd() :: any()

The read or write command.

Link to this type name()
name() :: Raft.peer()
Link to this type state()
state() :: any()

The state for the state machine.

Link to this type val()
val() :: any()

The value to return to client after completing a read or write.

Link to this section Callbacks

Link to this callback handle_read(cmd, state)
handle_read(cmd(), state()) :: val() | {val(), state()}

Called when the leader has established that they still have a majority and haven’t been deposed as described in the raft paper section 8. While it is possible to change the state here it is HIGHLY discouraged. Changes during a read will NOT be persisted or replicated to other servers. Any mutations done here will be lost after a crash recovery or when starting a new server.

Link to this callback handle_write(cmd, state)
handle_write(cmd(), state()) :: {val(), state()}

Called whenever there has been a committed write command.

Link to this callback init(name)
init(name()) :: state()

Called when the state machine is initialized.