Behaviours: ra_machine
.
Khepri private low-level API.
This module exposes the private "low-level" API to the Khepri database and
state machine. Main functions correspond to Ra commands implemented by the
state machine. All functions in khepri
are built on top of this
module.
async_ret() = ok
common_ret() = khepri:ok(khepri_adv:node_props_map()) | khepri:error()
machine_config() = #config{store_id = khepri:store_id(), member = ra:server_id(), snapshot_interval = non_neg_integer()}
Configuration record, holding read-only or rarely changing fields.
metrics() = #{applied_command_count => non_neg_integer()}
Internal state machine metrics.
projection_tree() = khepri_pattern_tree:tree(khepri_projection:projection())
A pattern tree that holds all registered projections in the machine's state.
props() = #{payload_version := khepri:payload_version(), child_list_version := khepri:child_list_version()}
Properties attached to each node in the tree structure.
abstract datatype: state()
State of this Ra state machine.
triggered() = #triggered{id = khepri:trigger_id(), event_filter = khepri_evf:event_filter(), sproc = horus:horus_fun(), props = map()}
triggers_map() = #{khepri:trigger_id() => #{sproc := khepri_path:native_path(), event_filter := khepri_evf:event_filter()}}
Internal triggers map in the machine state.
tx_ret() = khepri:ok(khepri_tx:tx_fun_result()) | khepri_tx:tx_abort() | no_return()
fold/5 | Returns all tree nodes matching the given path pattern. |
delete/3 | Deletes all tree nodes matching the path pattern. |
transaction/5 | Runs a transaction and returns the result. |
handle_tx_exception/1 | |
register_trigger/5 | Registers a trigger. |
register_projection/4 | Registers a projection. |
unregister_projection/3 | Unregisters a projection by name. |
get_last_consistent_call_atomics/1 | |
version/0 |
fold(StoreId, PathPattern, Fun, Acc, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Fun = khepri:fold_fun()
Acc = khepri:fold_acc()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:ok(NewAcc) | khepri:error()
NewAcc = Acc
StoreId
: the name of the Ra cluster.
PathPattern
: the path (or path pattern) to the nodes to get.
Options
: query options such as favor
.
returns: an {ok, NodePropsMap}
tuple with a map with zero, one or more
entries, or an {error, Reason}
tuple.
Returns all tree nodes matching the given path pattern.
delete(StoreId, PathPattern, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:command_options() | khepri:tree_options()
Ret = khepri_machine:common_ret() | khepri_machine:async_ret()
StoreId
: the name of the Ra cluster.
PathPattern
: the path (or path pattern) to the nodes to delete.
Options
: command options such as the command type.
returns: in the case of a synchronous delete, an {ok, NodePropsMap}
tuple
with a map with zero, one or more entries, or an {error, Reason}
tuple;
in the case of an asynchronous put, always ok
(the actual return value
may be sent by a message if a correlation ID was specified).
Deletes all tree nodes matching the path pattern.
transaction(StoreId, FunOrPath, Args, ReadWrite, Options) -> Ret
StoreId = khepri:store_id()
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Args = list()
ReadWrite = ro | rw | auto
Options = khepri:command_options() | khepri:query_options()
Ret = khepri_machine:tx_ret() | khepri_machine:async_ret()
StoreId
: the name of the Ra cluster.
FunOrPath
: an arbitrary anonymous function or a path pattern pointing
to a stored procedure.
Args
: a list of arguments to pass to FunOrPath
.
ReadWrite
: the read/write or read-only nature of the transaction.
Options
: command options such as the command type.
returns: in the case of a synchronous transaction, {ok, Result}
where
Result
is the return value of FunOrPath
, or {error, Reason}
if the
anonymous function was aborted; in the case of an asynchronous transaction,
always ok
(the actual return value may be sent by a message if a
correlation ID was specified).
Runs a transaction and returns the result.
handle_tx_exception(X1) -> any()
register_trigger(StoreId, TriggerId, EventFilter, StoredProcPath, Options) -> Ret
StoreId = khepri:store_id()
TriggerId = khepri:trigger_id()
EventFilter = khepri_evf:event_filter() | khepri_path:pattern()
StoredProcPath = khepri_path:path()
Options = khepri:command_options()
Ret = ok | khepri:error()
StoreId
: the name of the Ra cluster.
TriggerId
: the name of the trigger.
EventFilter
: the event filter used to associate an event with a
stored procedure.
StoredProcPath
: the path to the stored procedure to execute when the
corresponding event occurs.
returns: ok
if the trigger was registered, an {error, Reason}
tuple
otherwise.
Registers a trigger.
register_projection(StoreId, PathPattern, Projection, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Projection = khepri_projection:projection()
Options = khepri:command_options()
Ret = ok | khepri:error()
StoreId
: the name of the Ra cluster.
PathPattern
: the pattern of tree nodes which should be projected.
Projection
: the projection record created with khepri_projection:new/3
.
Options
: command options such as the command type.
returns: ok
if the projection was registered, an {error, Reason}
tuple
otherwise.
Registers a projection.
unregister_projection(StoreId, ProjectionName, Options) -> Ret
StoreId = khepri:store_id()
ProjectionName = atom()
Options = khepri:command_options()
Ret = ok | khepri:error()
StoreId
: the name of the Ra cluster.
ProjectionName
: the name of the projection to unregister.
Options
: command options such as the command type.
returns: ok
if the projection existed and was unregistered, an {error,
Reason}
tuple otherwise.
Unregisters a projection by name.
get_last_consistent_call_atomics(StoreId) -> any()
version() -> any()
Generated by EDoc