raft_kv v0.2.5 RaftKV.ValuePerKey behaviour View Source
Behaviour module to define interface functions to manipulate stored value for each key.
The implementations of command/4 and query/4 must be pure (i.e., they must consist of only deterministic computations).
To introduce side effects for your key-value operations see RaftKV.LeaderHook.
See also RaftedValue.Data.
Link to this section Summary
Callbacks
Generic read/write operation on the stored value.
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()
key()
View Source
key() :: any()
key() :: any()
load()
View Source
load() :: non_neg_integer()
load() :: non_neg_integer()
query_arg()
View Source
query_arg() :: any()
query_arg() :: any()
query_ret()
View Source
query_ret() :: any()
query_ret() :: any()
size()
View Source
size() :: non_neg_integer()
size() :: non_neg_integer()
value()
View Source
value() :: any()
value() :: any()
Link to this section Callbacks
command(arg1, size, key, command_arg)
View Source
command(nil | value(), size(), key(), command_arg()) ::
{command_ret(), load(), nil | value(), size()}
command(nil | value(), size(), key(), command_arg()) :: {command_ret(), load(), nil | value(), size()}
Generic read/write operation on the stored value.
This callback function is invoked by RaftKV.command/4 or RaftKV.command_on_all_keys_in_shard/3.
Commands are replicated across members of the consensus group and executed in all members
in order to reproduce the same value in all nodes.
The callback function must return a 4-tuple.
- 0th element : Return value for the caller of
RaftKV.command/4. - 1st element : Approximate load (in an arbitrary unit) required by execution of the command.
- 2nd element : The next version of the value after the command. If you return
nilthe key is removed. - 3rd element : Size of the next version of the value (in an arbitrary unit). Neglected if you specify
nilfor the 3rd element.
query(value, size, key, query_arg) View Source
Read-only operation on the stored value.
This callback function is invoked by RaftKV.query/4.
This function must return a 2-tuple.
- 0th element : Return value for the caller of
RaftKV.query/4. - 1st element : Approximate load (in an arbitrary unit) required by execution of the query.
Note that (most of the time) read-only queries can bypass the Raft log replication (which is necessary in the case of commands),
thanks to leader leases in the Raft protocol.
Load values to return in
command/4andquery/4should reflect this difference.