View Source erlfdb_directory (erlfdb v1.2.0)

Directory Layer

Summary

Types

A directory is a named subdirectory within a root or partition. Its keys are allocated by the root's HCA allocator and stored under a content prefix derived from that allocated node name. The layer field is an arbitrary binary that applications use to tag what kind of data lives in the directory (e.g. <<"tenant">>). get_subspace/1 returns a usable subspace for reading and writing key-value data.

A partition is a directory that acts as its own independent root, with its own node-prefix space and HCA allocator. Key allocation for everything underneath a partition is managed by the partition itself rather than by any ancestor root, giving it a completely separate key namespace.

t()

A directory layer node — either a partition() (root) or a directory() (leaf).

Types

-type create_option() :: {layer, binary()} | {node_name, binary()}.
-type directory() ::
          #{id := binary(),
            name := binary(),
            root := t(),
            path := [path_item()],
            layer := binary(),
            get_id := fun((t()) -> binary()),
            get_name := fun((t()) -> binary()),
            get_root := fun((t()) -> t()),
            get_root_for_path := fun((t(), path()) -> t()),
            get_partition := fun((t()) -> t()),
            get_node_prefix := fun((t()) -> binary()),
            get_path := fun((t()) -> [path_item()]),
            get_layer := fun((t()) -> binary()),
            get_subspace := fun((t()) -> term())}.

A directory is a named subdirectory within a root or partition. Its keys are allocated by the root's HCA allocator and stored under a content prefix derived from that allocated node name. The layer field is an arbitrary binary that applications use to tag what kind of data lives in the directory (e.g. <<"tenant">>). get_subspace/1 returns a usable subspace for reading and writing key-value data.

-type open_option() :: {layer, binary()}.
-type partition() ::
          #{id := binary(),
            node_prefix := binary(),
            content_prefix := binary(),
            allocator := term(),
            allow_manual_names := boolean(),
            name => binary(),
            root => t(),
            path => [path_item()],
            is_partition => true,
            is_absolute_root => true,
            get_id := fun((t()) -> binary()),
            get_name => fun((t()) -> binary()),
            get_root := fun((t()) -> t()),
            get_root_for_path := fun((t(), path()) -> t()),
            get_partition := fun((t()) -> t()),
            get_node_prefix := fun((t()) -> binary()),
            get_path := fun((t()) -> [path_item()]),
            get_layer := fun((t()) -> binary()),
            get_subspace := fun((t()) -> term())}.

A partition is a directory that acts as its own independent root, with its own node-prefix space and HCA allocator. Key allocation for everything underneath a partition is managed by the partition itself rather than by any ancestor root, giving it a completely separate key namespace.

Because a partition is a root and not a leaf, get_subspace/1 raises an error on a partition — data is stored in ordinary directories beneath it.

The absolute root (returned by root/0) is also represented as a partition.

-type path() :: path_item() | list() | tuple().
-type path_item() :: binary() | {utf8, binary()}.
-type root_option() ::
          {node_prefix, binary()} | {content_prefix, binary()} | {allow_manual_names, boolean()}.
-type t() :: partition() | directory().

A directory layer node — either a partition() (root) or a directory() (leaf).

Functions

-spec contains(t(), binary()) -> boolean().
Link to this function

create(TxObj, Node, Path)

View Source
-spec create(erlfdb:tx_object(), t(), path()) -> t().
Link to this function

create(TxObj, Node, PathIn, Options)

View Source
-spec create(erlfdb:tx_object(), t(), path(), [create_option()]) -> t().
Link to this function

create_or_open(TxObj, Node, Path)

View Source
-spec create_or_open(erlfdb:tx_object(), t(), path()) -> t().
Link to this function

create_or_open(TxObj, Node, PathIn, Layer)

View Source
-spec create_or_open(erlfdb:tx_object(), t(), path(), binary()) -> t().
Link to this function

debug_nodes(TxObj, Node)

View Source
-spec debug_nodes(erlfdb:tx_object(), t()) -> ok | nil.
-spec exists(erlfdb:tx_object(), t()) -> boolean().
Link to this function

exists(TxObj, Node, PathIn)

View Source
-spec exists(erlfdb:tx_object(), t(), path()) -> boolean().
-spec get_id(t()) -> binary().
-spec get_layer(t()) -> binary().
-spec get_name(t()) -> binary().
-spec get_node_prefix(t()) -> binary().
-spec get_path(t()) -> [path_item()].
-spec get_root(t()) -> t().
Link to this function

get_root_for_path(Node, Path)

View Source
-spec get_root_for_path(t(), path()) -> t().
-spec get_subspace(t()) -> term().
-spec key(t()) -> binary().
-spec list(erlfdb:tx_object(), t()) -> [{path_item(), t()}].

Lists the immediate subdirectories of Node. Equivalent to list(TxObj, Node, {}).

Link to this function

list(TxObj, Node, PathIn)

View Source
-spec list(erlfdb:tx_object(), t(), path()) -> [{path_item(), t()}].

Lists the immediate subdirectories of the directory at Path under Node.

Returns [{Name, ChildNode}] where each Name is a path_item(). In practice the directory layer always stores names as {utf8, Binary} tuples, so pattern matching on the first element should use that form:

Listed = erlfdb_directory:list(Db, Root),
Names = [N || {{utf8, N}, _Node} <- Listed].

Raises {erlfdb_directory, {list_error, missing_path, Path}} if Path does not exist under Node.

Link to this function

move(TxObj, Node, OldPathIn, NewPathIn)

View Source
-spec move(erlfdb:tx_object(), t(), path(), path()) -> t().
-spec move_to(erlfdb:tx_object(), t(), path()) -> t().
-spec open(erlfdb:tx_object(), t(), path()) -> t().
Link to this function

open(TxObj, Node, PathIn, Options)

View Source
-spec open(erlfdb:tx_object(), t(), path(), [open_option()]) -> t().
-spec pack(t(), tuple()) -> binary().
-spec pack_vs(t(), tuple()) -> binary().
-spec range(t()) -> {binary(), binary()}.
-spec range(t(), tuple()) -> {binary(), binary()}.
-spec remove(erlfdb:tx_object(), t()) -> ok.
Link to this function

remove(TxObj, Node, Path)

View Source
-spec remove(erlfdb:tx_object(), t(), path()) -> ok.
Link to this function

remove_if_exists(TxObj, Node)

View Source
-spec remove_if_exists(erlfdb:tx_object(), t()) -> ok.
Link to this function

remove_if_exists(TxObj, Node, Path)

View Source
-spec remove_if_exists(erlfdb:tx_object(), t(), path()) -> ok.
-spec root() -> partition().
-spec root([root_option()]) -> partition().
-spec subspace(t(), tuple()) -> term().
-spec unpack(t(), binary()) -> tuple().