HashRing

Inherits from: Object
Instance variables: nodes, positions, replicas

A consistent hash ring for distributing keys across a set of nodes. Used by Cluster for deterministic key-to-node mapping that minimizes redistribution when nodes join or leave.

Each node is placed at multiple virtual positions (replicas) on the ring for better distribution. The default is 150 virtual nodes per real node.

Test
ring := HashRing new.
ring add: 'node-a'.
ring add: 'node-b'.
ring add: 'node-c'.
ring size >>> 3
ring isEmpty >>> false
Test
ring := HashRing new: 1.
ring add: 'x'.
ring size >>> 1
(ring nodeFor: 'any-key') notNil >>> true
Test
ring := HashRing new.
ring isEmpty >>> true
ring size >>> 0

Class Methods

uncategorized

class new
class new:

Create a hash ring with the given number of virtual nodes per real node.

Instance Methods

uncategorized

add:

Add a node to the ring. The node can be any object (typically a Node or String).

hashKey:
isEmpty

Return true if the ring has no nodes.

nodeFor:

Return the node responsible for the given key.

nodes

Return all real nodes in the ring.

nodesFor:count:

Return the N nodes responsible for the given key (for replication).

primInit:
printString
remove:

Remove a node from the ring.

size

Return the number of real nodes in the ring.

sortPositions