Download Notes on Distributed Hashing: Chord and Replicated Hash Tables and more Slides Distributed Database Management Systems in PDF only on Docsity!
CS 347 Notes08 7
Distributed Lookup
- Have <k, v> pairs
- Given k, find matching values
1 a
1 b
7 c
4 d
1 a
3 a
4 a
lookup(4) = {a, d}
k v
CS 347 Notes08 8
Data Distributed Over Nodes
- N nodes
- Each holds some <k,v> data
CS 347 Notes08 9
Notation
- X.func(params) means RPC of
procedure func(params) at node X
- X.A means send message to X to get
value of A
- If X omitted, we refer to local procedure
or data structures
node Y
data: A, B...
node X
data: A, B...
B := X.A
A := X.f(B)
CS 347 Notes08 10
Distributed Hashing
Chord Paper:
Ion Stoica, Robert Morris, David Liben-Nowell, David R. Karger,
M. Frans Kaashoek, Frank Dabek, Hari Balakrishnan,
Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications.
IEEE/ACM Transactions on Networking
http://pdos.csail.mit.edu/chord/papers/paper-ton.pdf
CS 347 Notes08 11
Hashing Values and Nodes
- H(v) is m-bit number (v is value)
- H(X) is m-bit number (X is node id)
- Hash function is “good”
m
H(X) H(Y)
H(k)
k v stored at Y
CS 347 Notes08 12
Chord Circle
N
N
N
N
N
N
N
N
N
N
K
K
K24, K
K
m=
CS 347 Notes08 13
Rule
- Consider nodes X, Y such that Y follows X
clockwise
- Node Y is responsible for keys k such that
H(k) in ( H(X), H(Y) ]
N
N
stores K55, K56, ... K
use hashed
values...
e.g., N54 is node
whose id hashes
to 54.
CS 347 Notes08 14
Succ, pred links
N
N
N
N
N
N
N
N
N
N
N1.succ
N1.pred
m=
CS 347 Notes08 15
Search using succ links
N
N
N
N
N
N
N
N
N
N
N14.find_succ(K52)
N51.find_succ(K52)
=N
m=
CS 347 Notes08 16
Code
if k in (X, succ]
return succ
else
return succ.find_succ(k);
CS 347 Notes08 17
Notation: Use of Hashed Values
if k in (X, succ]
return succ
else
return succ.find_succ(k);
if H(k) in (H(X), H(succ)]
return succ
else
return succ.find_succ(k);
should be
CS 347 Notes08 18
Looking Up Data
Y := find_succ(k);
S := Y.lookup(k);
return S;
returns local values associated with k
CS 347 Notes08 25
Example
N
N
N
N
N
N
N
N
N
N
find_succ(K54)
CS 347 Notes08 26
Example
N
N
N
N
N
N
N
N
N
N
find_succ(K54)
K
CS 347 Notes08 27
Code
if id in (X, succ] return succ
else
Y := closest_preceed(id);
return Y.find_succ(id);
for i := m downto 1
if finger[i] in (X,id) return finger[i];
return X;
CS 347 Notes08 28
Another Example
N
N
N
N
N
N
N
N
N
N
find_succ(K7)
CS 347 Notes08 29
Example
N
N
N
N
N
N
N
N
N
N
find_succ(K7)
CS 347 Notes08 30
Example
N
N
N
N
N
N
N
N
N
N
find_succ(K7)
K
return N
CS 347 Notes08 31
Yet Another Example
N
N
N
N
N
N
N
N
N
N
find_succ(K8)
CS 347 Notes08 32
Yet Another Example
N
N
N
N
N
N
N
N
N
N
find_succ(K8)
return N
there seems to be a
bug in code of Slide 26
(which is the same as
Figure 5 of Chord
paper).
CS 347 Notes08 33
Adding Nodes to Circle
N
N
N
N
N
N
N
N
N
N
K
K
K24, K
K
N
joining node
for now,
assume nodes
never die
need to
1. update links
2. move data
CS 347 Notes08 34
New Node X Joins
- Node Y is known to be in ring
- X.join(Y)
pred := nil;
succ := Y.find_succ(X);
CS 347 Notes08 35
Periodic Stabilization
Y := succ.pred;
if Y in (X, succ) succ := Y;
succ.notify(X);
if pred = nil OR Z in (pred, X)
pred := Z;
CS 347 Notes08 36
Periodic Finger Check
next := next + 1;
if next > m
next := 1;
finger[next] := find_succ(X+
next-
)
CS 347 Notes08 43
Periodic Stabilization
if pred = nil OR Z in (pred, X)
Z.give(data in range (pred ,Z] )
pred := Z
X.remove(data in range (pred ,Z] )
Question: What data do we give when pred=nil?
Note: We are glossing over concurrency issues,
e.g., what happens to lookups while we are moving data?
CS 347 Notes08 44
Lookup May be at Wrong Node!
Np
Nx
Ns
nil
resp. for (Nx, Ns]
resp. for (Np, Nx]
lookup for k in (Np, Nx]
directed to Ns!
CS 347 Notes08 45
Looking Up Data (Revised)
ok := false
while not ok do
Y := find_succ(k)
[ok, S] := Y.lookup(k)
return S
if k in (pred, Y]
return [true, local values for k]
else return [false, {}] CS 347 Notes08 46
Inserting Data (Revised)
ok := false
while not ok do
Y := find_succ(k)
ok := Y.insert(k, v)
if k in (pred, Y]
insert [k,v] in local storage
return true
else return false
CS 347 Notes08 47
Why Does This Work?
- pred, succ links eventually correct
- data ends up at correct node
key k is at node X where k in (X.prev, X]
- finger pointers speed up searches
but do not cause problems
CS 347 Notes08 48
Results for N Node System
- With high probability, the number of
nodes that must be contacted to find a
successor is O(log N)
- Although finger table contains room for m
entries, only O(log N) need to be stored
- Experimental results show average lookup
time is (log N)/
CS 347 Notes08 49
Node Failures
Np
Nx
Ns
k8 v
k9 v
k7 v
data at Nx:
Nx dies!!
- links screwed up
- data lost
CS 347 Notes08 50
To Fix Links
if (pred has failed)
pred := nil;
- Also, keep links to r successors in ring
CS 347 Notes08 51
Failure Example
Np
Nx
Ns
Initially...
Nx dies...
backup succ link (r=2)
CS 347 Notes08 52
Failure Example
Np
Ns
After Ns.check_pred
nil
CS 347 Notes08 53
Failure Example
Np
Ns
After Np discovers Nx down...
nil
CS 347 Notes08 54
Failure Example
Np
Ns
After stabilization...
CS 347 Notes08 61
Node Joins
node N
data for
keys that
hash to 0,
node N
data for
keys that
hash to 2,
hash node 0 N 1 N 2 N 3 N
hash node 0 N 1 N 2 N 3 N
First, set up N1...
node N
hash node 0 N 1 N 2 N 3 N
CS 347 Notes08 62
Node Joins
node N
data for
keys that
hash to 0,
node N
data for
keys that
hash to 2,
hash node 0 N 1 N 2 N 3 N
hash node 0 N 1 N 2 N 3 N
Copy data to N1...
node N
data for
keys that
hash to 1
hash node 0 N 1 N 2 N 3 N
data
copy
CS 347 Notes08 63
Node Joins
node N
data for
keys that
hash to 0,
node N
data for
keys that
hash to 2,
hash node 0 N 1 N 2 N 3 N
hash node 0 N 1 N 2 N 3 N
Change control...
node N
data for
keys that
hash to 1
hash node 0 N 1 N 2 N 3 N
N1 N
Which do we update first, N0 or N1??
CS 347 Notes08 64
Node Joins
node N
data for
keys that
hash to 0
node N
data for
keys that
hash to 2,
hash node 0 N 1 N 2 N 3 N
hash node 0 N 1 N 2 N 3 N
Drop data at N0...
node N
data for
keys that
hash to 1
hash node 0 N 1 N 2 N 3 N
N1 N
CS 347 Notes08 65
Update Other Nodes
node N
data for
keys that
hash to 0,
node N
data for
keys that
hash to 2,
hash node 0 N 1 N 2 N 3 N
hash node 0 N 1 N 2 N 3 N
node N
data for
keys that
hash to 1
hash node 0 N 1 N 2 N 3 N
N1 N1^ N
How do other nodes get updated?
- Eagerly by N0?
- Lazily by future lookups?
CS 347 Notes08 66
What about inserts?
node N
data for
keys that
hash to 0,
node N
data for
keys that
hash to 2,
hash node 0 N 1 N 2 N 3 N
hash node 0 N 1 N 2 N 3 N
node N
data for
keys that
hash to 1
hash node 0 N 1 N 2 N 3 N
insert arrives at this point...
- apply at N0 and then copy?
- re-direct to N1?
data
copy
CS 347 Notes08 67
Control of Hash Table
hash node next
a N1 N
node that holds data
for bucket “a”... if N
is local node, then
local node controls
bucket “a”
when move in
progress, this field
records node data is
moving to...
CS 347 Notes08 68
Different Scenarios
hash node next
a X Y
hash node next
a X Y
Y:
X:
X:
X: Node X controls a,
lookups local, inserts local
Forward lookups and inserts to Y
Node X controls a,
lookups local, inserts to Y (& X?)
Inserts local, forward lookups to X
hash node next
a X nil (X)
hash node next
a Y nil (Y)
CS 347 Notes08 69
New Node Y Joins
[[ select HT entry [j, X] willing to give up
(note, next[j] should be nil)
next[j] := Y; ]]
copy HT making Y.next[j] := Y;
copy data for key j to Y
Y.node[j] := Y; Y.next[j] := nil;
node[j] := Y; next[j] = nil;
remove data for key j
CS 347 Notes08 70
Looking Up Data (Revised)
id := H(k)
[[ if X = X.node(id) then
return local values for k
else ]]
Y := X.node(id); tt := Y.node(id);
[[ if (tt neq Y) and (X.node(id)=Y)
X.node(id) := tt ]]
return( Y.DHTlookup(k) )
CS 347 Notes08 71
Storing Data
id := H(k)
[[ tt := node(id); nn := next(id);
if (X = tt and nn=nil) or (nn=X)
insert (k,v) locally
else ]]
if nn = nil Y := tt else Y := nn;
Y.DHTinsert(k,v)
CS 347 Notes08 72
Example
node N
data for
keys that
hash to 0,
node N
data for
keys that
hash to 2,
N0.join(N1) is executed...
hash node next 0 N 1 N 2 N 3 N
hash node next 0 N 1 N 2 N 3 N
node N
CS 347 Notes08 79
Example: Step 7
node N
data for
keys that
hash to 1
node N
data for
keys that
hash to 2,
Node N0 removes data for bucket 0...
Note: What happens to lookups & inserts at this point in time?
hash node next 0 N 1 N 2 N 3 N
node N
hash node next 0 N 1 N 2 N 3 N
data for
keys that
hash to 0
hash node next 0 N 1 N 2 N 3 N
CS 347 Notes08 80
Lookup Example
node N
data for
keys that
hash to 0,
node N
data for
keys that
hash to 2,
Updates to hash table in progress...
hash node next 0 N 1 N 2 N 3 N
node N
data for
keys that
hash to 0
hash node next 0 N1 N 1 N 2 N 3 N
hash node next 0 N 1 N 2 N 3 N
out of
date
N2.DHTlookup(id=0)
CS 347 Notes08 81
Lookup Example
node N
data for
keys that
hash to 0,
node N
data for
keys that
hash to 2,
Updates to hash table in progress...
hash node next 0 N 1 N 2 N 3 N
node N
data for
keys that
hash to 0
hash node next 0 N1 N 1 N 2 N 3 N
hash node next 0 N 1 N 2 N 3 N
out of
date
N2.DHTlookup(id=0)
updated
to N
N1.DHTlookup(id=0)
CS 347 Notes08 82
Lookup Example
node N
data for
keys that
hash to 1
node N
data for
keys that
hash to 2,
Final state...
hash node next 0 N 1 N 2 N 3 N
node N
data for
keys that
hash to 0
hash node next 0 N 1 N 2 N 3 N
hash node next 0 N 1 N 2 N 3 N
CS 347 Notes08 83
Can we prove scheme works?
- Assume only joins, no failures
- Remember: OK to miss recent inserts
- if not, need 2PC to handoff control...
CS 347 Notes08 84
Exercise
- Make HT extensible
- Start with m entries in HT, then
dynamically double size
- Make sure we don’t get confused
when HTs of different sizes exist
CS 347 Notes08 85
Chord vs Replicated HT
- Which code is simpler?
- note that Chord code does not show data migration!
- Lookups O(log N) vs O(1)
- Impact of caching
- Routing table: Log N vs N
- Anonymity?
- Bootstrapping
CS 347 Notes08 86
Neighborhood Search (Gnutella)
- Each node stores its own data
searches nearby nodes
key val 12 a 7 b 13 c 25 a
key val 47 f 12 d 51 x 9 y
key val 41 g 99 c 14 d
CS 347 Notes08 87
Storing Data
insert (k,v) locally at X
CS 347 Notes08 88
Lookup
TTL := desired value
return( X.find(k, TTL, X) )
TTL := TTL – 1
S := local data pairs with key k
if TTL > 0 then
for all Y in X.neighbors (Y neq Z) do
S:=S union Y.find(k, TTL, X)
return( S)
CS 347 Notes08 89
Example
key val 12 a 7 b 13 c 25 a
key val 47 f 12 d 25 x 9 y
key val 41 g 13 c 14 d
key val 41 g 13 x 14 d
key val 41 g 13 c 14 d
key val 41 g 13 f 14 d
key val 13 f 12 c
key val 15 f 12 c
key val 13 d 12 c
key val 44 s 05 a
node N
N1.DTlookup(13), TTL = 4
key val 13 t 01 d
CS 347 Notes08 90
Example
key val 12 a 7 b 13 c 25 a
key val 47 f 12 d 25 x 9 y
key val 41 g 13 c 14 d
key val 41 g 13 x 14 d
key val 41 g 13 c 14 d
key val 41 g 13 f 14 d
key val 13 f 12 c
key val 15 f 12 c
key val 13 d 12 c
key val 44 s 05 a
node N
N1.DTlookup(13), TTL = 4
key val 13 t 01 d
ttl=
ttl=
ttl=
answer so far = {c, f, x}
CS 347 Notes08 97
Bootstrap Server
known nodes:
S =X1, X2, x3,...
server
X
X
X
X
add to S
if no response,
remove from S
sometimes called “pong server”
CS 347 Notes08 98
Problems with Neighborhood Search
- Unnecessary messages
- High load and traffic
- Example: nodes have M new neighbors,
number of messages is M TTL
- Low capacity nodes are a bottleneck
- Do not find all answers
network area
searched
TTL
CS 347 Notes08 99
Why is Neighborhood Search Good?
- Can pose complex queries
- Simple robust algorithm
- Works well if data is highly replicated
network area
searched
TTL
sites that have latest Madonna song
CS 347 Notes08 100
Super-Nodes
- Regular nodes index their content at
super-nodes
- Super-nodes run neighborhood search
SN
SN
SN
SN
SN
SN
SN
SN
SN SN
CS 347 Notes08 101
Motivation for Super-Nodes
- Take advantage of powerful nodes
- Searching larger index better than
searching many smaller ones
SN
SN
SN
SN
SN
SN
SN
SN
SN SN
CS 347 Notes08 102
Napster (Original One)
SN
CS 347 Notes08 103
Napster (Original One)
SN
get file
query
CS 347 Notes08 104
Napster (Original One)
- Actually, had several disconnected SNs
SN
get file
query
SN
SN
napster
CS 347 Notes08 105
Performance Evaluation
- Yang, Beverly; Garcia-Molina, Hector. Designing
a Super-peer Network, IEEE International
Conference on Data Engineering, 2003.
SN
SN
SN
SN
SN
SN
SN
SN
SN SN
cluster size
topology
Metrics:
•Bandwidth
•Compute Load
number of nodes = 10,
CS 347 Notes08 106
Aggregate Bandwidth
CS 347 Notes08 107
Individual Bandwidth Load
single SP
CS 347 Notes08 108
Individual Compute Load
CS 347 Notes08 115
Open Problems
Performance
Correctness Participation
- Efficiency
- Load-balancing
- Authentic Services
- Prevention of DoS
- Incentives
•Functionality
•Applications
•Anonymity
CS 347 Notes08 116
Open Problems: “Bad Guys”
- Availability (e.g., coping with DOS attacks)
- Authenticity
- Anonimity
- Access Control (e.g., IP protection, payments,...)
CS 347 Notes08 117
Authenticity
title: origin of species
author: charles darwin
date: 1859
body: In an island far,
far away ...
CS 347 Notes08 118
Authenticity
title: origin of species
author: charles darwin
date: 1859
body: In an island far,
far away ...
CS 347 Notes08 119
More than Fetching One File
T=origin
Y=
A=darwin
T=origin
Y=
A=darwin
T=origin
Y=
A=darwin
T=origin
Y=?
A=darwin
B=?
CS 347 Notes08 120
More than Fetching One File
T=origin
Y=
A=darwin
T=origin
Y=
A=darwin
T=origin
Y=
A=darwin
T=origin
Y=?
A=darwin
B=?
T=origin
Y=
A=darwin
B=abcd
CS 347 Notes08 121
Solutions
- Authenticity Function A(doc): T or F
- at expert sites, at all sites?
- can use signature expert sig(doc) user
- Voting Based
- authentic is what majority says
- Time Based
- e.g., oldest version (available) is authentic
CS 347 Notes08 122
Added Challenge: Efficiency
- Example: Current music sharing
authenticity function
files is expensive
Track peer behavior
bad peer
good peer good peer
CS 347 Notes08 123
How to Track Peer Behavior?
, v
, v
, v
]
a b c d
- Single value between 0 and 1?
CS 347 Notes08 124
How to Track Peer Behavior?
, v
, v
, v
]
a b c d
- Single value between 0 and 1?
[ total downloads, good downloads ]?
CS 347 Notes08 125
Trust Operations
a
b c
d e
[1, .9, .5, 0, 0]
[1, 1, 0, .3, 1] [1, 0, 1, 1, .2]
update?
CS 347 Notes08 126
Issues
- Trust computations in dynamic system
- Overloading good nodes
- Bad nodes can provide good content
sometimes
- Bad nodes can build up reputation
- Bad nodes can form collectives
- ...