View Source shards_meta (shards v1.1.0)

This module encapsulates the partitioned table metadata.

Different properties must be stored somewhere so shards 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.

Link to this section Summary

Functions

Builds a new meta from the given Map.
Returns the tab_info within the metadata.
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.

Link to this section 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{}.

Link to this section Functions

-spec ets_opts(t() | shards:tab()) -> [term()].
-spec from_map(Map :: #{atom() => term()}) -> t().
Builds a new meta from the given Map.
-spec get(Tab :: shards:tab()) -> t() | no_return().
Returns the 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().
Returns the value for the given Key in the metadata, or Def if Key is not set.
-spec get_partition_pids(Tab :: shards:tab()) -> partition_pids().
Returns a list with the partition PIDs.
-spec get_partition_tids(Tab :: shards:tab()) -> partition_tids().
Returns a list with the partition TIDs.
-spec init(Name, Opts) -> Tab when Name :: atom(), Opts :: [shards:option()], Tab :: shards:tab().
Initializes the metadata ETS table.
-spec is_metadata(Meta :: term()) -> boolean().
Returns 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().
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.
-spec new() -> t().
Returns a metadata data type with the default values.
-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().
Stores the value Val under the given key Key into the metadata table Tab.
-spec rename(Tab, Name) -> Name when Tab :: shards:tab(), Name :: atom().
Renames the metadata ETS table.
-spec tab_pid(t() | shards:tab()) -> pid().
-spec to_map(t()) -> meta_map().
Converts the given Meta into a map.