swarm v3.4.0 Swarm.Distribution.Strategy behaviour

This module implements the interface for custom distribution strategies. The default strategy used by Swarm is a consistent hash ring implemented via the libring library.

Custom strategies are expected to return a datastructure or pid which will be passed along to any functions which need to manipulate the current distribution state. This can be either a plain datastructure (as is the case with the libring-based strategy), or a pid which your strategy module then uses to call a process in your own supervision tree.

For efficiency reasons, it is highly recommended to use plain datastructures rather than a process for storing the distribution state, because it has the potential to become a bottleneck otherwise, however this is really up to the needs of your situation, just know that you can go either way.

Link to this section Summary

Functions

Adds a node to the state of the current distribution strategy

Adds a node to the state of the current distribution strategy, and give it a specific weighting relative to other nodes

Adds a list of nodes to the state of the current distribution strategy. The node list can be composed of both node names (atoms) or tuples containing a node name and a weight for that node

Maps a key to a specific node via the current distribution strategy

Removes a node from the state of the current distribution strategy

Link to this section Types

Link to this type key()
key() :: term()
Link to this type nodelist()
nodelist() :: [node() | {node(), weight()}]
Link to this type reason()
reason() :: String.t()
Link to this type strategy()
strategy() :: term()
Link to this type weight()
weight() :: pos_integer()

Link to this section Functions

Link to this function add_node(strategy, node)

Adds a node to the state of the current distribution strategy.

Link to this function add_node(strategy, node, weight)

Adds a node to the state of the current distribution strategy, and give it a specific weighting relative to other nodes.

Link to this function add_nodes(strategy, nodes)

Adds a list of nodes to the state of the current distribution strategy. The node list can be composed of both node names (atoms) or tuples containing a node name and a weight for that node.

Link to this function key_to_node(strategy, node)

Maps a key to a specific node via the current distribution strategy.

Link to this function remove_node(strategy, node)

Removes a node from the state of the current distribution strategy.

Link to this section Callbacks

Link to this callback add_node(strategy, node)
add_node(strategy(), node()) :: strategy() | {:error, reason()}
Link to this callback add_node(strategy, node, weight)
add_node(strategy(), node(), weight()) :: strategy() | {:error, reason()}
Link to this callback add_nodes(strategy, nodelist)
add_nodes(strategy(), nodelist()) :: strategy() | {:error, reason()}
Link to this callback create()
create() :: strategy() | {:error, reason()}
Link to this callback key_to_node(strategy, key)
key_to_node(strategy(), key()) :: node() | :undefined
Link to this callback remove_node(strategy, node)
remove_node(strategy(), node()) :: strategy() | {:error, reason()}