raft_kv v0.2.0 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

Link to this section Callbacks

Link to this callback command(arg0, size, key, command_arg) View Source
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 nil the key is removed.
  • 3rd element : Size of the next version of the value (in an arbitrary unit). Neglected if you specify nil for the 3rd element.
Link to this callback query(value, size, key, query_arg) View Source
query(value(), size(), key(), query_arg()) :: {query_ret(), load()}

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/4 and query/4 should reflect this difference.