Module shards_state

State Handler - This module encapsulates the shards state.

Description

State Handler - This module encapsulates the shards state.

There are different properties that have to be stored somewhere so shards can work properly. Remember, shards performs a logic on top of ETS, for example, compute the shard and/or node based on the Key where the action will be applied. To do so, it needs the number of shards or partitions, the function to pick the shard and/or node (in case of global scope), the table type and of course, the module to use depending on the scope; shards_local or shards_dist.

Because of that, when a new table is created using shards, a new supervision tree is created as well to represent that table. The supervisor is shards_owner_sup and it has a control ETS table to save the state so it can be fetched later at any time.

Data Types

key()

key() = term()

Defines key type.

n_shards()

n_shards() = pos_integer()

Defines number of shards.

op()

op() = r | w | d

Defines operation type.

  • r: Read operations.
  • w: Write operation.
  • d: Delete operations.
  • pick_fun()

    pick_fun() = 'fun'(fun((key(), range(), op()) -> non_neg_integer()) | any)

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

    range()

    range() = pos_integer()

    Defines the range or set – range > 0.

    scope()

    scope() = l | g

    Defines the scope, if it is local l or global g.

    state()

    state() = #state{}

    Defines shards state.

    state_map()

    state_map() = #{module => module(), sup_name => atom(), n_shards => pos_integer(), keypos => pos_integer(), pick_shard_fun => pick_fun(), pick_node_fun => pick_fun()}

    Defines the map representation of the shards state:

    Function Index

    eval_pick_shard/2Equivalent to eval_pick_shard(Key, w, State).
    eval_pick_shard/3
    from_map/1 Builds a new state from the given Map.
    get/1 Returns the state for the given table Tab.
    is_state/1 Returns true in the given argument is a valid state, otherwise false is returned.
    keypos/1
    keypos/2
    module/1
    module/2
    n_shards/1
    n_shards/2
    new/0
    new/1
    new/2
    new/3
    pick_node_fun/1
    pick_node_fun/2
    pick_shard_fun/1
    pick_shard_fun/2
    scope/1
    sup_name/1
    sup_name/2
    to_map/1 Converts the given state into a map.

    Function Details

    eval_pick_shard/2

    eval_pick_shard(Key, State) -> any()

    Equivalent to eval_pick_shard(Key, w, State).

    eval_pick_shard/3

    eval_pick_shard(Key::key(), Op::op(), State::state()) -> non_neg_integer() | any

    from_map/1

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

    Builds a new state from the given Map.

    get/1

    get(Tab::atom()) -> state()

    Returns the state for the given table Tab.

    is_state/1

    is_state(State::any()) -> boolean()

    Returns true in the given argument is a valid state, otherwise false is returned.

    keypos/1

    keypos(State::state() | atom()) -> pos_integer()

    keypos/2

    keypos(State::state(), Keypos::pos_integer()) -> state()

    module/1

    module(State::state() | atom()) -> module()

    module/2

    module(State::state(), Module::module()) -> state()

    n_shards/1

    n_shards(State::state() | atom()) -> pos_integer()

    n_shards/2

    n_shards(State::state(), Shards::pos_integer()) -> state()

    new/0

    new() -> state()

    new/1

    new(Shards::pos_integer()) -> state()

    new/2

    new(Shards::pos_integer(), Module::module()) -> state()

    new/3

    new(Shards::pos_integer(), Module::module(), SupName::atom()) -> state()

    pick_node_fun/1

    pick_node_fun(State::state() | atom()) -> pick_fun()

    pick_node_fun/2

    pick_node_fun(State::state(), Fun::pick_fun()) -> state()

    pick_shard_fun/1

    pick_shard_fun(State::state() | atom()) -> pick_fun()

    pick_shard_fun/2

    pick_shard_fun(State::state(), Fun::pick_fun()) -> state()

    scope/1

    scope(State::state() | atom()) -> scope()

    sup_name/1

    sup_name(State::state() | atom()) -> atom()

    sup_name/2

    sup_name(State::state(), SupName::atom()) -> state()

    to_map/1

    to_map(State::state()) -> state_map()

    Converts the given state into a map.


    Generated by EDoc