swarm v1.0.2 Swarm.Ring
This module defines an API for creating/manipulating a hash ring. The internal datastructure for the hash ring is actually a gb_tree, which provides fast lookups for a given key on the ring.
- The ring is a continuum of 2^32 “points”, or integer values
- Nodes are sharded into 128 points, and distributed across the ring
- Each shard owns the keyspace below it
- Keys are hashed and assigned a point on the ring, the node for a given ring is determined by finding the next highest point on the ring for a shard, the node that shard belongs to is then the node which owns that key.
- If a key’s hash does not have any shards above it, it belongs to the first shard, this mechanism is what creates the ring-like topology.
- A node is only added to the ring if it is running Swarm
- When nodes are added/removed from the ring, only a small subset of keys must be reassigned
Summary
Functions
Adds a node to the hash ring, with an optional weight provided which determines the number of virtual nodes (shards) that will be assigned to it on the ring
Determines which node owns the given key. This function assumes that the ring has been populated with at least one node
Creates a new hash ring structure, with no nodes added yet
Creates a new hash ring structure, seeded with the given node, with an optional weight provided which determines the number of virtual nodes (shards) that will be assigned to it on the ring
Removes a node from the hash ring
Types
t :: :gb_trees.tree
Functions
Specs
add_node(Swarm.Ring.t, node, pos_integer) :: Swarm.Ring.t
Adds a node to the hash ring, with an optional weight provided which determines the number of virtual nodes (shards) that will be assigned to it on the ring.
The default weight for a node is 128
Specs
key_to_node(Swarm.Ring.t, term) :: node | no_return
Determines which node owns the given key. This function assumes that the ring has been populated with at least one node.
Specs
new(node, pos_integer) :: Swarm.Ring.t
Creates a new hash ring structure, seeded with the given node, with an optional weight provided which determines the number of virtual nodes (shards) that will be assigned to it on the ring.
The default weight for a node is 128
Specs
remove_node(Swarm.Ring.t, node) :: Swarm.Ring.t
Removes a node from the hash ring.