Module khepri_machine

Khepri private low-level API.

Behaviours: ra_machine.

Description

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.

This module is private. The documentation is still visible because it may help understand some implementation details. However, this module should never be called directly outside of Khepri.

Data Types

keep_while_conds_map()

keep_while_conds_map() = #{khepri_path:native_path() => khepri_condition:native_keep_while()}

Per-node keep_while conditions.

keep_while_conds_revidx()

keep_while_conds_revidx() = #{khepri_path:native_path() => #{khepri_path:native_path() => ok}}

Internal reverse index of the keep_while conditions. If node A depends on a condition on node B, then this reverse index will have a "node B => node A" entry.

machine_config()

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.

stat()

stat() = #{payload_version := khepri:payload_version(), child_list_version := khepri:child_list_version()}

Stats attached to each node in the tree structure.

state()

state() = #khepri_machine{config = khepri_machine:machine_config(), root = khepri_machine:tree_node(), keep_while_conds = khepri_machine:keep_while_conds_map(), keep_while_conds_revidx = khepri_machine:keep_while_conds_revidx(), triggers = #{khepri:trigger_id() => #{sproc := khepri_path:native_path(), event_filter := khepri_evf:event_filter()}}, emitted_triggers = [khepri_machine:triggered()], metrics = #{applied_command_count => non_neg_integer()}}

State of this Ra state machine.

tree_node()

tree_node() = #node{stat = khepri_machine:stat(), payload = khepri_payload:payload(), child_nodes = #{khepri_path:component() := #node{stat = khepri_machine:stat(), payload = khepri_payload:payload(), child_nodes = #{khepri_path:component() := #node{}}}}}

A node in the tree structure.

triggered()

triggered() = #triggered{id = khepri:trigger_id(), event_filter = khepri_evf:event_filter(), sproc = khepri_fun:standalone_fun(), props = map()}

Function Index

get/3Returns all tree nodes matching the path pattern.
count/3Counts all tree nodes matching the path pattern.
delete/3Deletes all tree nodes matching the path pattern.
transaction/4Runs a transaction and returns the result.
run_sproc/4Executes a stored procedure.
register_trigger/5Registers a trigger.

Function Details

get/3

get(StoreId, PathPattern, Options) -> Result

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, Result} tuple with a map with zero, one or more entries, or an {error, Reason} tuple.

Returns all tree nodes matching the path pattern.

count/3

count(StoreId, PathPattern, Options) -> Result

StoreId: the name of the Ra cluster.
PathPattern: the path (or path pattern) to the nodes to count.
Options: query options such as favor.

returns: an {ok, Count} tuple with the number of matching tree nodes, or an {error, Reason} tuple.

Counts all tree nodes matching the path pattern.

delete/3

delete(StoreId, PathPattern, Options) -> Result

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, Result} 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/4

transaction(StoreId, Fun, ReadWrite, Options) -> Ret

StoreId: the name of the Ra cluster.
Fun: an arbitrary anonymous function.
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, {atomic, Result} where Result is the return value of Fun, or {aborted, 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.

run_sproc/4

run_sproc(StoreId, PathPattern, Args, Options) -> Ret

StoreId: the name of the Ra cluster.
PathPattern: the path to the stored procedure.
Args: the list of args to pass to the stored procedure; its length must be equal to the stored procedure arity.
Options: options to tune the tree traversal or the returned structure content.

returns: the result of the stored procedure execution, or throws an exception if the node does not exist, does not hold a stored procedure or if there was an error.

Executes a stored procedure.

The stored procedure is executed in the context of the caller of run_sproc/3.

register_trigger/5

register_trigger(StoreId, TriggerId, EventFilter, StoredProcPath, Options) -> Ret

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.


Generated by EDoc