Helios v0.1.0 Helios.Registry.Distribution.Strategy behaviour View Source

This module implements the interface for custom distribution strategies. The default strategy used by Helios.Registry 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.

Strategy can be set in configuration, like so:

Config example

config :my_app, MyApp.Endpoint,
  registry:[
    distribution_strategy: {Helios.Registry.Distribution.RingStrategy, :init, []}
  ]

where distibution_strategy is requres {m, f, a} triplet that will be called using Kernel.apply/3 during registry startup

Link to this section Summary

Callbacks

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 section Callbacks

Link to this callback add_node(strategy, node) View Source
add_node(strategy(), node()) :: strategy() | {:error, reason()}

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

Link to this callback add_node(strategy, node, weight) View Source
add_node(strategy(), node(), weight()) :: strategy() | {:error, reason()}

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

Link to this callback add_nodes(strategy, nodelist) View Source
add_nodes(strategy(), nodelist()) :: strategy() | {:error, reason()}

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 callback key_to_node(strategy, key) View Source
key_to_node(strategy(), key()) :: node() | :undefined

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

Link to this callback remove_node(strategy, node) View Source
remove_node(strategy(), node()) :: strategy() | {:error, reason()}

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