rafted_value v0.11.1 RaftedValue.Data behaviour View Source
A behaviour that defines data to be replicated by RaftedValue
servers.
It is required to implement a callback module of this behaviour to run a consensus group.
Concrete implementations of all callback functions of this behaviour must be pure,
so that all members of a consensus group can reproduce the data by replicating only command_arg
.
Therefore, for example, if you want to use "current time" in your command implementation,
you must not obtain current time in command/1
implementation; you have to pass it by embedding in command_arg
.
This is a design decision made to support arbitrary data structure while keeping Raft logs compact.
Link to this section Summary
Callbacks
Generic read/write operation on the stored value.
Creates an initial value to be stored.
Read-only operation on the stored value.
Link to this section Types
command_arg()
View Source
command_arg() :: any()
command_arg() :: any()
command_ret()
View Source
command_ret() :: any()
command_ret() :: any()
data()
View Source
data() :: any()
data() :: any()
query_arg()
View Source
query_arg() :: any()
query_arg() :: any()
query_ret()
View Source
query_ret() :: any()
query_ret() :: any()
Link to this section Callbacks
command(data, command_arg)
View Source
command(data(), command_arg()) :: {command_ret(), data()}
command(data(), command_arg()) :: {command_ret(), data()}
Generic read/write operation on the stored value.
This callback function is invoked by RaftedValue.command/4
.
Commands are replicated across members of the consensus group and executed in all members
in order to reproduce the same history of stored value.
This function should return a pair of "return value to client" and "next version of stored data".
new()
View Source
new() :: data()
new() :: data()
Creates an initial value to be stored.
Whenever a new consensus group is started by RaftedValue.start_link/2
(called with :create_new_consensus_group
),
this function is called to initialize the stored value.
query(data, query_arg) View Source
Read-only operation on the stored value.
This callback function is invoked by RaftedValue.query/3
.
This function should return "return value to client".