-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRendezvousHashing.py
37 lines (29 loc) · 1.33 KB
/
RendezvousHashing.py
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
from Resizer import Resizer
class RendezvousHashing(Resizer):
"""Implement Highest Random Weight hashing method.
Part of 'Functional Core' - methods of this class don't change
any state or objects, all they do is take values and return values.
"""
def __init__(self, nodes):
pass
def get_nodeid(self, key, nodes):
"""Find the node to use for the given key's storage."""
hashes = []
for node in nodes:
hashes.append((hash(node.name+key), node))
_, node = max(hashes)
return node.id
def add_node(self, node, nodes):
"""Nothing is done when a new node is added.
If a new site Sn+1 is added, new object placements or requests will
compute n+1 hash values, and pick the largest of these. If an object
already in the system at Sk maps to this new site Sn+1, it will be
fetched afresh and cached at Sn+1. All clients will henceforth obtain
it from this site, and the old cached copy at Sk will ultimately be
replaced by the local cache management algorithm."""
return {}
def get_storage(self, node):
"""Take all key-value pairs from this node.
If Sk is taken offline, its objects will be remapped uniformly to the
remaining n-1 sites."""
return node.hashmap