Module shards_meta

This module encapsulates the partitioned table metadata.

Description

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.

Data Types

keyslot_fun()

keyslot_fun() = fun((Key::term(), Range::pos_integer()) -> non_neg_integer())

Defines spec function to pick or compute the partition and/or node. The function returns a value for Key within the range 0..Range-1.

meta_map()

meta_map() = #{tab_pid => pid(), keypos => pos_integer(), partitions => pos_integer(), keyslot_fun => keyslot_fun(), parallel => boolean(), parallel_timeout => timeout(), ets_opts => [term()]}

Defines the map representation for the metadata data type.

partition_pids()

partition_pids() = [{non_neg_integer(), pid()}]

Defines a tuple-list with the partition number and the partition owner PID.

partition_tids()

partition_tids() = [{non_neg_integer(), ets:tid()}]

Defines a tuple-list with the partition number and the ETS TID.

t()

t() = #meta{}

Defines shards metadata.

Function Index

ets_opts/1
from_map/1 Builds a new meta from the given Map.
get/1 Returns the metadata.
get_partition_pids/1 Returns a list with the partition PIDs.
get_partition_tids/1 Returns a list with the partition TIDs.
init/2 Initializes the metadata ETS table.
is_metadata/1 Returns true if Meta is a metadata data type, otherwise, false is returned.
keypos/1
keyslot_fun/1
lookup/2 Returns the value associated to the key Key in the metadata table Tab.
new/0 Returns a metadata data type with the default values.
parallel/1
parallel_timeout/1
partitions/1
put/3 Stores the value Val under the given key Key into the metadata table Tab.
rename/2 Renames the metadata ETS table.
tab_pid/1
to_map/1 Converts the given Meta into a map.

Function Details

ets_opts/1

ets_opts(Meta::t() | shards:tab()) -> [term()]

from_map/1

from_map(Map::#{atom() => term()}) -> t()

Builds a new meta from the given Map.

get/1

get(Tab::shards:tab()) -> t() | no_return()

Returns the metadata.

get_partition_pids/1

get_partition_pids(Tab::shards:tab()) -> partition_pids()

Returns a list with the partition PIDs.

get_partition_tids/1

get_partition_tids(Tab::shards:tab()) -> partition_tids()

Returns a list with the partition TIDs.

init/2

init(Name, Opts) -> Tab

Initializes the metadata ETS table.

is_metadata/1

is_metadata(Meta::term()) -> boolean()

Returns true if Meta is a metadata data type, otherwise, false is returned.

keypos/1

keypos(Meta::t() | shards:tab()) -> pos_integer()

keyslot_fun/1

keyslot_fun(Meta::t() | shards:tab()) -> keyslot_fun()

lookup/2

lookup(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.

new/0

new() -> t()

Returns a metadata data type with the default values.

parallel/1

parallel(Meta::t() | shards:tab()) -> boolean()

parallel_timeout/1

parallel_timeout(Meta::t() | shards:tab()) -> timeout()

partitions/1

partitions(Meta::t() | shards:tab()) -> pos_integer()

put/3

put(Tab, Key, Val) -> ok

Stores the value Val under the given key Key into the metadata table Tab.

rename/2

rename(Tab, Name) -> Name

Renames the metadata ETS table.

tab_pid/1

tab_pid(Meta::t() | shards:tab()) -> pid()

to_map/1

to_map(Meta::t()) -> meta_map()

Converts the given Meta into a map.


Generated by EDoc