-
Notifications
You must be signed in to change notification settings - Fork 28
/
README
71 lines (42 loc) · 1.93 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
An implementation of consistent hashing ring for distributed hash tables as
a gen_server.
Here is an informal explanation of the technique:
http://www.spiteful.com/2008/03/17/programmers-toolbox-part-3-consistent-hashing/
Exports:
start_link(Peers) -> ServerRef
start_link(ServerName, Peers) -> ServerRef
Types:
Peers = [{Node, Opaque, Weight}]
Node = term()
Opaque = term()
Weight = int(), >= 1
Create a ring according to peer configuration Peers. Opaque is an opaque
data associated with the node. Greater weight makes the node own bigger
portion of the ring.
The ring creation time is N^2 where N is the sum of the nodes' weights.
add(ServerRef, Peers) -> ok | {error, already_there, [Node]}
Add Peers to the ring. If any of the nodes being added is already in the
ring (the check is done by comparing node *names*), error is returned and
the ring remains intact.
add(ServerRef, {Node, Opaque, Weight})
Equivalent to add(ServerRef, [{Node, Opaque, Weight}]).
delete(ServerRef, [Node]) -> ok | {error, unknown_nodes, [Node]}
Removes nodes from the ring by their names. If any of the names doesn't
reference an existing node in the ring, an error is returned and the ring
remains intact.
delete(ServerRef, Node)
Equivalent to delete(ServerRef, [Node]).
get_config(ServerRef) -> Peers
Returns the current configuration of the ring. The order of nodes within
the returned list is not specified.
lookup(ServerRef, Key) -> [{Node, Opaque}]
Types:
Key = term()
Look up the Ring for a list of nodes corresponding to Key. The returned
list is guaranteed to contain no duplicates.
The lookup time is log(N), where N is the sum of the nodes' weights.
nodes(ServerRef) -> [{Node, Opaque}]
Return the list of nodes in the ring. The order of nodes in the returned
list is not specified, but it is guaranteed that the list contains no
duplicates.
This operation execution time is constant.