Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup...

73
1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah ([email protected]), Jim Dowling]

Transcript of Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup...

Page 1: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

1/71

Chord: A Scalable Peer-to-peer Lookup Protocolfor Internet Applications

[Slides by Amir H. Payberah ([email protected]), Jim Dowling]

Page 2: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

2/73

Consistent Hashing

• Imagine we want to store information about books on 4 nodes (servers). Use the ISBN to identify each book. 

•We could use one of the nodes as a central directory server•But, with the hash of the ISBN, we don't need a central server:

switch (SHA-1(ISBN) mod 4) {case 0: // store on node1case 1: // store on node2case 2: // store on node3case 3: // store on node4

}

•Our store gets bigger......we need to add more 2 nodes. We now have to re­calculate where all the books are stored.

•Do the books stay on the same nodes?•The only books stored on the same node as before are those where 

SHA-1(ISBN) mod 4 == SHA-1(ISBN) mod 6

Page 3: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

3/73

Consistent Hashing

•Consistent hashing allows you to add more nodes and only a small minority of books will have to move to new nodes.

•Key property: low cost hash­table expansion. That is, a book's hash key is independent of the number of books and independent of the number of nodes.

If you add or remove nodes or books, a book's hash key remains the same.

•Mechanism: hash something constant at each node E.g., a node's MAC address

See: Karger et. Al,  "Consistent Hashing and Random Trees...”

Page 4: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

4/73

Consistent Hashing

•Each node is responsible for all books with hash keys between its own hash key and the hash key of the next node (going upwards).

• Imagine we have books with SHA­1(ISBN) in a range 0..16•For node1..node4, the nodes' hash keys are:

{node1→0, node2→6, node3→11, node4→16}

•So, a book with SHA­1(ISBN) 1 would be stored at node1.→ (node1) 0 < 1 (book) < 6 (node2)

•Now if we add new nodes positions 4 and 8, respectively: Nodes have hash keys: {0, 4, 6, 8, 11, 16}

•Fewer books need to be moved Books with hash keys (6..7) get moved from node2 to the first new node Books with hash keys (8..10) get moved from node3 to the second new node

Page 5: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

5/71

Recap

Page 6: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

6/73

Distributed Hash Tables (DHT)

•An ordinary hash­table, which is ...

Key Value

Fatemeh Stockholm

Sarunas Lausanne

Tallat Islamabad

Cosmin Bucharest

Seif Stockholm

Amir Tehran

Page 7: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

7/73

Distributed Hash Tables (DHT)

•An ordinary hash­table, which is distributed.

Key Value

Fatemeh Stockholm

Sarunas Lausanne

Tallat Islamabad

Cosmin Bucharest

Seif Stockholm

Amir Tehran

Page 8: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

8/73

Distributed Hash Tables (DHT)Decide on a common key spacefor nodes and values

12

257

2

1431

Set of nodes Key of nodes

Set of items Key of items

Connect nodes using a small, bounded number of links s.t. max hop count is minimized 

1 2 3 Define a strategy for assigning items to nodes

Page 9: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

9/71

Chord an Example of DHT

Page 10: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

10/73

How to Construct a DHT (Chord)?

• Use a logical name space, called the identifier space, consisting of identifiers {0,1,2,…, N-1}

• Identifier space is a logical ring modulo N.0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

1

Page 11: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

11/73

How to Construct a DHT (Chord)?

• Use a logical name space, called the identifier space, consisting of identifiers {0,1,2,…, N-1}

• Identifier space is a logical ring modulo N.

• Every node picks a random identifier though Hash H.

• Example: Space N=16 {0,…,15} Five nodes a, b, c, d, e H(a) = 6 H(b) = 5 H(c) = 0 H(d) = 11 H(e) = 2

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

1

Page 12: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

12/73

Successor ...

• The successor of an identifier is the first node met going in clockwise direction starting at the identifier.

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

2

Page 13: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

13/73

Successor ...

• The successor of an identifier is the first node met going in clockwise direction starting at the identifier.

• succ(x): is the first node on the ring with id greater than or equal x.

Succ(12) = 0 Succ(1) = 2 Succ(6) = 6

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

2

Page 14: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

14/73

Connect the Nodes

• Each node points to its successor.

The successor of a node n is succ(n+1).

0’s successor is succ(1) = 2 2’s successor is succ(3) = 5 5’s successor is succ(6) = 6 6’s successor is succ(7) = 11 11’s successor is succ(12) = 0

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

2

Page 15: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

15/73

Where to Store Data?

• Use globally known hash function, H.

• Each item <key,value> gets identifier H(key) = k.

H(''Fatemeh'') = 12 H(''Cosmin'') = 2 H(''Seif'') = 9 H(''Sarunas'') = 14 H(''Tallat'') = 4

3

Page 16: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

16/73

Where to Store Data?

• Use globally known hash function, H.

• Each item <key,value> gets identifier H(key) = k.

H(''Fatemeh'') = 12 H(''Cosmin'') = 2 H(''Seif'') = 9 H(''Sarunas'') = 14 H(''Tallat'') = 4

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Fatemeh

Sarunas

Cosmin

Tallat

Seif

3

Page 17: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

17/73

Where to Store Data?

• Use globally known hash function, H.

• Each item <key,value> gets identifier H(key) = k.

H(''Fatemeh'') = 12 H(''Cosmin'') = 2 H(''Seif'') = 9 H(''Sarunas'') = 14 H(''Tallat'') = 4

• Store each item at its successor.

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Fatemeh

Sarunas

Cosmin

Tallat

Seif

3

Page 18: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

18/73

Where to Store Data?

• Use globally known hash function, H.

• Each item <key,value> gets identifier H(key) = k.

H(''Fatemeh'') = 12 H(''Cosmin'') = 2 H(''Seif'') = 9 H(''Sarunas'') = 14 H(''Tallat'') = 4

• Store each item at its successor.

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Sarunas

Cosmin

Tallat

Seif

Fatemeh

3

Page 19: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

19/71

Lookup?

Page 20: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

20/73

Lookup?

• To lookup a key k Calculate H(k) Follow succ pointers until item k is found

get(seif)0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Sarunas

Cosmin

Tallat

Seif

Fatemeh

Page 21: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

21/73

Lookup?

• To lookup a key k Calculate H(k) Follow succ pointers until item k is found

• Example Lookup ''Seif'' at node 2 H(''Seif'')=9 Traverse nodes:

• 2, 5, 6, 11 (BINGO) Return ''Stockholm'' to initiator

Key Value

Seif Stockholm

get(seif)0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Sarunas

Cosmin

Tallat

Seif

Fatemeh

Page 22: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

22/73

Lookup?

// ask node n to find the successor of idprocedure n.findSuccessor(id) {

       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else // forward the query around the circle           return successor.findSuccessor(id)   }

• (a, b] the segment of the ring moving clockwise from but not including a until and including b.• n.foo(.) denotes an RPC of foo(.) to node n.• n.bar denotes and RPC to fetch the value of the variable bar in node n.

Page 23: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

23/73

Put and Get

procedure n.put(id, value) {   s = findSuccessor(id)   s.store(id, value)}

•PUT and GET are nothing but lookups!!

procedure n.get(id) {   s = findSuccessor(id)   return s.retrieve(id)}

Page 24: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

24/71

How can we improve this?

Page 25: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

25/73

Cost of Lookup Operations

• If only the pointer to succ(n+1) is used Worst case lookup time is O(N), for N nodes

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Sarunas

Cosmin

Tallat

Seif

Fatemeh

Page 26: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

26/73

Speeding up Lookups

• Finger/routing table: Point to succ(n+1) Point to succ(n+2) Point to succ(n+4) Point to succ(n+8) … Point to succ(n+2M­1)

• Distance always halved to the destination.

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Page 27: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

27/73

Speeding up Lookups

• Size of routing tables is logarithmic.: Routing table size: M, where N = 2^M.

• Every node n knows successor(n + 2^(i­1)) for i = 1... M

•  Routing entries = log2(N)

log2(N) hops from any node to 

any other node

• Example: Log2(1000000) 20≈

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Page 28: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

28/73

DHT Lookup

// ask node n to find the successor of idprocedure n.findSuccessor(id) {

       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else // forward the query around the circle           return successor.findSuccessor(id)   }

Page 29: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

29/73

DHT Lookup

// ask node n to find the successor of idprocedure n.findSuccessor(id) {

       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else // forward the query around the circle           return successor.findSuccessor(id)   }

closestPrecedingNode(id)

Page 30: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

30/73

DHT Lookup

// ask node n to find the successor of idprocedure n.findSuccessor(id) {

       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else { // forward the query around the circle           m := closestPrecedingNode(id)           return m.findSuccessor(id)       }   }

// search locally for the highest predecessor of id   procedure closestPrecedingNode(id) {      for i = m downto 1 do {         if (finger[i] ∈(n, id)) then             return finger[i]     }     return n  }

Page 31: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

31/73

Chord – Lookup (1/4)

0

9

3

6

2

5

12

8

11

13

4

1

7

10

14

15 get(15)

15

procedure n.findSuccessor(id) {       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else { // forward the query around the circle           m := closestPrecedingNode(id)           return m.findSuccessor(id)       }   }

Page 32: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

32/73

Chord – Lookup (1/4)

0

9

3

6

2

5

12

8

11

13

4

1

7

10

14

get(15)

15

15

procedure n.findSuccessor(id) {       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else { // forward the query around the circle           m := closestPrecedingNode(id)           return m.findSuccessor(id)       }   }

Page 33: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

33/73

Chord – Lookup (2/4)

0

9

3

6

2

5

12

8

11

13

4

1

7

10

14

get(15)

15

15

procedure n.findSuccessor(id) {       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else { // forward the query around the circle           m := closestPrecedingNode(id)           return m.findSuccessor(id)       }   }

Page 34: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

34/73

Chord – Lookup (2/4)

0

9

3

6

2

5

12

8

11

13

4

1

7

10

14

get(15)

15

15

procedure n.findSuccessor(id) {       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else { // forward the query around the circle           m := closestPrecedingNode(id)           return m.findSuccessor(id)       }   }

Page 35: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

35/73

Chord – Lookup (3/4)

0

9

3

6

2

5

12

8

11

13

4

1

7

10

14

get(15)

15

15

procedure n.findSuccessor(id) {       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else { // forward the query around the circle           m := closestPrecedingNode(id)           return m.findSuccessor(id)       }   }

Page 36: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

36/73

Chord – Lookup (3/4)

0

9

3

6

2

5

12

8

11

13

4

1

7

10

14

15

15

procedure n.findSuccessor(id) {       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else { // forward the query around the circle           m := closestPrecedingNode(id)           return m.findSuccessor(id)       }   }

get(15)

Page 37: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

37/73

Chord – Lookup (4/4)

0

9

3

6

2

5

12

8

11

13

4

1

7

10

14

get(15)

15

15

procedure n.findSuccessor(id) {       if (predecessor ≠ nil and id ∈ (predecessor, n]) then return n       else if (id ∈(n, successor]) then           return successor       else { // forward the query around the circle           m := closestPrecedingNode(id)           return m.findSuccessor(id)       }   }

Page 38: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

38/73

Discussion

•We are basically done.

•But …

•What about joins and failures/leaves? Nodes come and go as they wish.

•What about data? Should I lose my doc because some kid decided to shut down his machine 

and he happened to store my file?

•So actually we just started ...

Page 39: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

39/71

Handling Dynamism?Ring Maintenance?

Page 40: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

40/73

Handling Dynamism ­ Ring Maintenance

•Everything depends on successor pointers.

• In Chord, in addition to the successor pointer, every node has a predecessor pointer as well for ring maintenance.

Predecessor of node n is the first node met in anti­clockwise direction starting at n­1.

Page 41: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

41/73

Handling Dynamism ­ Ring Maintenance

• Periodic stabilization is used to make pointers eventually correct. Try pointing succ to closest alive successor. Try pointing pred to closest alive predecessor.

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Page 42: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

42/73

Handling Dynamism ­ Ring Maintenance

• Periodic stabilization is used to make pointers eventually correct. Try pointing succ to closest alive successor. Try pointing pred to closest alive predecessor.

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Page 43: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

43/73

Handling Dynamism ­ Ring Maintenance

• Periodic stabilization is used to make pointers eventually correct. Try pointing succ to closest alive successor. Try pointing pred to closest alive predecessor.

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Page 44: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

44/71

Handling Join?

Page 45: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

45/73

Chord – Handling Join (1/5)

•When n joins: Find n’s successor with lookup(n) Set succ to n’s successor Stabilization fixes the rest

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

Page 46: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

46/73

Chord – Handling Join (2/5)

•When n joins: Find n’s successor with lookup(n) Set succ to n’s successor Stabilization fixes the rest

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

13

Page 47: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

47/73

Chord – Handling Join (3/5)

•When n joins: Find n’s successor with lookup(n) Set succ to n’s successor Stabilization fixes the rest

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

13

Page 48: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

48/73

Chord – Handling Join (4/5)

•When n joins: Find n’s successor with lookup(n) Set succ to n’s successor Stabilization fixes the rest

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

13

Page 49: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

49/73

Chord – Handling Join (5/5)

•When n joins: Find n’s successor with lookup(n) Set succ to n’s successor Stabilization fixes the rest

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

13

Page 50: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

50/71

Fixing Fingers

Page 51: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

51/73

Chord – Fixing Fingers

•Periodically refresh finger table entries, and store the index of the next finger to fix.

•Local variable next initially is 0.

// When receiving notify(p) at n:procedure n.fixFingers() {   next := next+1   if (next > m) then      next := 1   finger[next] := findSuccessor(n ⊕ 2^(next ­ 1))

}

Page 52: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

52/73

Chord – Fixing Fingers (1/4)

•Current situation: succ(N48) is N60.•Succ(21⊕ 2^(6­1)) = Succ(53) = N60.

N21 N26 N32 N48 N60

N53

21⊕ 2^(6­1) = 53 N21.finger6.node

Page 53: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

53/73

Chord – Fixing Fingers (2/4)

• Succ(21⊕ 2^(6­1)) = Succ(53) = ?• New node N56 joins and stabilizes successor pointer.• Finger 6 of node N21 is wrong now.• N21 eventually try to fix finger 6 by looking up 53 which stops at N48, however 

and nothing changes.

N21 N26 N32 N48 N60

N53

21⊕ 2^(6­1) = 53 N21.finger6.node

N56

Page 54: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

54/73

Chord – Fixing Fingers (3/4)

• Succ(21⊕ 2^(6­1)) = Succ(53) = ?• N48 will eventually stabilize its successor.• This means the ring is correct now.

N21 N26 N32 N48 N60

N53

21⊕ 2^(6­1) = 53 N21.finger6.node

N56

Page 55: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

55/73

Chord – Fixing Fingers (4/4)

• Succ(21⊕ 2^(6­1)) = Succ(53) = N56• When N21 tries to fix Finger 6 again, this time the response from N48 will be 

correct and N21 corrects the finger.

N21 N26 N32 N48 N60

N53

21⊕ 2^(6­1) = 53 N21.finger6.node

N56

Page 56: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

56/71

Handling Failure?

Page 57: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

57/73

Successor List

•A node has a successors list of size r containing the immediate r successors

succ(n+1) succ(succ(n+1)+1) succ(succ(succ(n+1)+1)+1)

•How big should r be?  log(N)

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Page 58: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

58/73

Successor List ...

// Periodically at nprocedure n.stabilize() {   succ := find first alive node in successor list

       v := succ.pred      if (v ≠ nil and v ∈ (n,succ]) then

      set succ := v      send a notify(n) to succ

   updateSuccessorList(succ.successorList)   }

// join a Chord ring containing node m   procedure n.join(m) {      pred := nil     Succ := m.findSuccessor(n)    updateSuccesorList(succ.successorList)  }

Page 59: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

59/73

Dealing with Failures

•Periodic stabilization

• If successor fails Replace with closest alive successor

  • If predecessor fails

Set pred to nil

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5

Page 60: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

60/73

Chord – Handling Failure (1/5)

• When n leaves Just disappear (like failure).• When pred detected failed Set pred to nil.

• When succ detected failed Set succ to closest alive in successor list.

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

13

procedure n.checkPredecessor() {   if predecessor has failed then       predecessor := nil}

Page 61: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

61/73

Chord – Handling Failure (2/5)

• When n leaves Just disappear (like failure).• When pred detected failed Set pred to nil.

• When succ detected failed Set succ to closest alive in successor list.

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

procedure n.checkPredecessor() {   if predecessor has failed then       predecessor := nil}

Page 62: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

62/73

Chord – Handling Failure (3/5)

• When n leaves Just disappear (like failure).• When pred detected failed Set pred to nil.

• When succ detected failed Set succ to closest alive in successor list.

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

procedure n.checkPredecessor() {   if predecessor has failed then       predecessor := nil}

Page 63: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

63/73

Chord – Handling Failure (4/5)

• When n leaves Just disappear (like failure).• When pred detected failed Set pred to nil.

• When succ detected failed Set succ to closest alive in successor list.

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

procedure n.checkPredecessor() {   if predecessor has failed then       predecessor := nil}

Page 64: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

64/73

Chord – Handling Failure (5/5)

• When n leaves Just disappear (like failure).• When pred detected failed Set pred to nil.

• When succ detected failed Set succ to closest alive in successor list.

// Periodically at n:v := succ.predif (v ≠ nil and v ∈ (n,succ]) then    set succ := v

   send a notify(n) to succ

// When receiving notify(p) at n:if (pred = nil or p ∈ (pred, n]) then    set pred := p

15

11

procedure n.checkPredecessor() {   if predecessor has failed then       predecessor := nil}

Page 65: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

65/71

Variations of Chord

Page 66: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

66/73

Variations of Chord

•Chord#

•DKS

Page 67: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

67/73

Chord#

•The routing table has exponentially increasing pointers on the ring (node space) and NOT the identifier space.

Page 68: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

68/73

Chord vs. Chord#

0

9

3

2

511

151

7

10

14

13

Chord Chord#

8

4

6

12

0

9

3

2

511

151

7

10

14

13

8

4

6

12

Page 69: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

69/73

DKS

•Generalization of Chord to provide arbitrary arity

•Provide logk(n) hops per lookup k being a configurable parameter n being the number of nodes

• Instead of only log2(n)

Page 70: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

70/73

DKS – Lookup

•Achieving logk(n) lookup•Each node contains logk(N)=L 

levels, N=kL

•Each level contains k intervals, 

•Example, k=4, N=16 (42), node 0

Node 0 I0 I1 I2 I3

Level 1 0 ... 3 4 ... 7 8 ... 11 12 ... 15

0

11

2

6

5

1

3

4

13

14

15

12

7

10

89

Interval 0

Interval 1

Interval 3

Interval 2

Page 71: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

71/73

DKS – Lookup

•Achieving logk(n) lookup•Each node contains logk(N)=L 

levels, N=kL

•Each level contains k intervals, 

•Example, k=4, N=16 (42), node 0

0

11

2

6

5

1

3

4

13

14

15

12

7

10

89

Node 0 I0 I1 I2 I3

Level 1 0 ... 3 4 ... 7 8 ... 11 12 ... 15

Level 2 0 1 2 3

Page 72: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

72/71

Summary

Page 73: Chord: A Scalable Peer-to-peer Lookup Protocol for ...1/71 Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications [Slides by Amir H. Payberah (amir@sics.se), Jim

73/73

Summary

•Pointer of the nodes: Successor: first clockwise node Predecessor: first anti­clockwise node Finger list: successor(n + 2^(i­1)) 

for i = 1... M (N = 2^M).

•Handling dynamism Periodic stabilization

•Handling failure Successor list Periodic stabilization

0

11

2

6

1

3

4

7

12

9 8

10

15

13

14

5