khepri_machine (khepri v0.6.0)

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.

Link to this section Summary

Types

Per-node keep_while conditions.
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.
Configuration record, holding read-only or rarely changing fields.
Internal mapping between khepri_projection:projection() records and the native path patterns which trigger updates to each projection.
Properties attached to each node in the tree structure.
State of this Ra state machine.
A node in the tree structure.

Link to this section Types

-type async_ret() :: ok.
Link to this type

common_ret/0

-type common_ret() :: khepri:ok(khepri_adv:node_props_map()) | khepri:error().
Link to this type

keep_while_conds_map/0

-type keep_while_conds_map() :: #{khepri_path:native_path() => khepri_condition:native_keep_while()}.
Per-node keep_while conditions.
Link to this type

keep_while_conds_revidx/0

-type 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.
Link to this type

machine_config/0

-type machine_config() :: #config{}.
Configuration record, holding read-only or rarely changing fields.
Link to this type

projections_map/0

-type projections_map() :: #{khepri_projection:projection() => khepri_path:native_pattern()}.
Internal mapping between khepri_projection:projection() records and the native path patterns which trigger updates to each projection.
-type props() ::
    #{payload_version := khepri:payload_version(),
      child_list_version := khepri:child_list_version()}.
Properties attached to each node in the tree structure.
-type state() :: #khepri_machine{}.
State of this Ra state machine.
-type tree_node() :: #node{}.
A node in the tree structure.
-type triggered() :: #triggered{}.
-type tx_ret() :: khepri:ok(khepri_tx:tx_fun_result()) | khepri_tx:tx_abort() | no_return().

Link to this section Functions

Link to this function

delete(StoreId, PathPattern, Options)

-spec delete(StoreId, PathPattern, Options) -> Ret
          when
              StoreId :: khepri:store_id(),
              PathPattern :: khepri_path:pattern(),
              Options :: khepri:command_options() | khepri:tree_options(),
              Ret :: khepri_machine:common_ret() | khepri_machine:async_ret().
Deletes all tree nodes matching the path pattern.
Link to this function

fold(StoreId, PathPattern, Fun, Acc, Options)

-spec fold(StoreId, PathPattern, Fun, Acc, Options) -> Ret
        when
            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.
Returns all tree nodes matching the given path pattern.
Link to this function

handle_tx_exception(_)

Link to this function

register_projection(StoreId, PathPattern, Projection, Options)

-spec register_projection(StoreId, PathPattern, Projection, Options) -> Ret
                       when
                           StoreId :: khepri:store_id(),
                           PathPattern :: khepri_path:pattern(),
                           Projection :: khepri_projection:projection(),
                           Options :: khepri:command_options(),
                           Ret :: ok | khepri:error().
Registers a projection.
Link to this function

register_trigger(StoreId, TriggerId, EventFilter, StoredProcPath, Options)

-spec register_trigger(StoreId, TriggerId, EventFilter, StoredProcPath, Options) -> Ret
                    when
                        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().
Registers a trigger.
Link to this function

transaction(StoreId, FunOrPath, Args, ReadWrite, Options)

-spec transaction(StoreId, FunOrPath, Args, ReadWrite, Options) -> Ret
               when
                   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().
Runs a transaction and returns the result.