View Source shards_meta (shards v1.1.1)
This module encapsulates the partitioned table metadata.
Different properties must be stored somewhere soshards
can work properly. Shards perform logic on top of ETS tables, for example, compute the partition based on the Key
where the action will be applied. To do so, it needs the number of partitions, the function to select the partition, and also the partition identifier to perform the ETS action.
Summary
Functions
Builds a new
meta
from the given Map
.Returns the
tab_info
within the metadata.Equivalent to get(Tab, Key, undefined).
Returns the value for the given
Key
in the metadata, or Def
if Key
is not set.Returns a list with the partition PIDs.
Returns a list with the partition TIDs.
Initializes the metadata ETS table.
Returns
true
if Meta
is a metadata data type, otherwise, false
is returned.Returns the value associated to the key
Key
in the metadata table Tab
. If Key
is not found, the error {unknown_table, Tab}
is raised.Returns a metadata data type with the default values.
Stores the value
Val
under the given key Key
into the metadata table Tab
.Renames the metadata ETS table.
Converts the given
Meta
into a map
.Types
-type keyslot_fun() :: fun((Key :: term(), Range :: pos_integer()) -> non_neg_integer()).
-type meta_map() :: #{tab_pid => pid(), keypos => pos_integer(), partitions => pos_integer(), keyslot_fun => keyslot_fun(), parallel => boolean(), parallel_timeout => timeout(), ets_opts => [term()]}.
-type partition_pids() :: [{non_neg_integer(), pid()}].
-type partition_tids() :: [{non_neg_integer(), ets:tid()}].
-type t() :: #meta{tab_pid :: pid() | undefined, keypos :: pos_integer(), partitions :: pos_integer(), keyslot_fun :: keyslot_fun(), parallel :: boolean(), parallel_timeout :: timeout(), ets_opts :: [term()]}.
Functions
-spec ets_opts(t() | shards:tab()) -> [term()].
meta
from the given Map
.
-spec get(Tab :: shards:tab()) -> t() | no_return().
tab_info
within the metadata.
Equivalent to get(Tab, Key, undefined).
-spec get(Tab, Key, Def) -> Val when Tab :: shards:tab(), Key :: term(), Def :: term(), Val :: term().
Key
in the metadata, or Def
if Key
is not set.
-spec get_partition_pids(Tab :: shards:tab()) -> partition_pids().
-spec get_partition_tids(Tab :: shards:tab()) -> partition_tids().
-spec init(Name, Opts) -> Tab when Name :: atom(), Opts :: [shards:option()], Tab :: shards:tab().
true
if Meta
is a metadata data type, otherwise, false
is returned.
-spec keypos(t() | shards:tab()) -> pos_integer().
-spec keyslot_fun(t() | shards:tab()) -> keyslot_fun().
-spec lookup(Tab, Key) -> term() when Tab :: shards:tab(), Key :: term().
Key
in the metadata table Tab
. If Key
is not found, the error {unknown_table, Tab}
is raised.
-spec new() -> t().
-spec parallel(t() | shards:tab()) -> boolean().
-spec parallel_timeout(t() | shards:tab()) -> timeout().
-spec partitions(t() | shards:tab()) -> pos_integer().
-spec put(Tab, Key, Val) -> ok when Tab :: shards:tab(), Key :: term(), Val :: term().
Val
under the given key Key
into the metadata table Tab
.
-spec rename(Tab, Name) -> Name when Tab :: shards:tab(), Name :: atom().
-spec tab_pid(t() | shards:tab()) -> pid().
Meta
into a map
.