5.1 Distributed Hash Table
5.1 Distributed Hash Table
• Hashing
• Distributed Hash Table
• Chord
2
A Hash Table (hash map)
3
Hash functions
4
Hashing for partitioning usecase
• Objective
• Given document X, choose one of k servers to use
• Eg. using modulo hashing
• Number servers 1..k
• Place X on server i = (X mod k)
• Problem? Data may not be uniformly distributed
• Place X on server i = hash (X) mod k
• Problem?
• What happens if a server fails or joins (k à k±1)?
• What is different clients has different estimate of k?
• Answer: All entries get remapped to new nodes!
5
Distributed hash table (DHT)
6
DHT: basic idea
K V
K V
K V
K V
K V
K V K V
K V
K V
K V
K V
7
DHT: basic idea
K V
K V
K V
K V
K V
K V K V
K V
K V
K V
K V
K V
K V
K V
K V
K V
K V K V
K V
K V
K V
K V
K V
K V
K V
K V
K V
K V K V
K V
K V
K V
K V
insert(K1,V1)
K V
K V
K V
K V
K V
K V K V
K V
K V
K V
K V
insert(K1,V1)
(K1,V1) K V
K V
K V
K V
K V
K V K V
K V
K V
K V
K V
K V
K V
K V
K V
K V
K V K V
K V
K V
K V
K V
retrieve (K1)
• State Assignment
• What “(key, value) tables” does a node store?
• Network Topology
• How does a node select its neighbors?
• Routing Algorithm:
• Which neighbor to pick while routing to a destination?
• Various DHT algorithms make different choices
• CAN, Chord, Pastry, Tapestry, Plaxton, Viceroy, Kademlia, Skipnet,
Symphony, Koorde, Apocrypha, Land, ORDI …
14
Chord: A scalable peer-to-peer look-up
protocol for internet applications
Credit: University of California, berkely and Max planck institute
15
Outline
• What is Chord?
• Consistent Hashing
• A Simple Key Lookup Algorithm
• Scalable Key Lookup Algorithm
• Node Joins and Stabilization
• Node Failures
16
What is Chord?
17
Consistent hashing
18
Consistent hashing
19
Consistent hashing – Successor nodes
identifier
node
6
X key
1
0 successor(1) = 1
7 1
identifier
successor(6) = 0 6 6 circle 2 2 successor(2) = 3
5 3
4
2
20
Consistent hashing – Join and departure
21
Consistent hashing – Node join
keys
5
7
keys
0 1
7 1
keys
6 2
keys
5 3 2
22
Consistent hashing – Node departure
keys
7
keys
0 1
7 1
keys
6 6 2
keys
5 3 2
23
A Simple key lookup
24
A Simple key lookup
25
A Simple key lookup
26
Scalable key location
27
Scalable key location – Finger tables
28
Scalable key location – Finger tables
7 1 1+20 2 3
1+21 3 3
1+22 5 0
6 2
29
Scalable key location – Finger tables
• A finger table entry includes both the Chord identifier and the
IP address (and port number) of the relevant node.
• The first finger of n is the immediate successor of n on the
circle.
30
Scalable key location – Example query
31
Scalable key location – A characteristic
32
Node joins and stabilizations
33
Node joins and stabilizations
34
Node Joins – join()
35
Node Joins – join()
36
Node joins – stabilize()
• Each time node n runs stabilize(), it asks its successor for it’s
predecessor p, and decides whether p should be n’s successor
instead.
• stabilize() notifies node n’s successor of n’s existence, giving
the successor the chance to change its predecessor to n.
• The successor does this only if it knows of no closer
predecessor than n.
37
Node joins – stabilize()
38
Node joins – Join and stabilization
n n joins
ns n predecessor = nil
n n acquires ns as successor via some n’
pred(ns) = n
n n runs stabilize
n n notifies ns being the new predecessor
n ns acquires n as its predecessor
succ(np) = ns
n np runs stabilize
pred(ns) = np
n
n np asks ns for its predecessor (now n)
n np acquires n as its successor
succ(np) = n
n np notifies n
nil n n will acquire np as its predecessor
n all predecessor and successor pointers are now
correct
39
Node Joins – fix_fingers()
• Each node periodically calls fix fingers to make sure its finger
table entries are correct.
• It is how new nodes initialize their finger tables
• It is how existing nodes incorporate new nodes into their
finger tables.
40
Node Joins – fix_fingers()
41
Node failures
42
Chord – The math
43
Interesting simulation results
44
Applications: Time-shared storage
45
Applications: Chord-based DNS
46
What is Chord? – Addressed problems
47
Summary
48
Thanks for your attention!
49