Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 825 Lecture 8. Leader Election Aim is to elect exactly one node as the leader.

Similar presentations


Presentation on theme: "CIS 825 Lecture 8. Leader Election Aim is to elect exactly one node as the leader."— Presentation transcript:

1 CIS 825 Lecture 8

2 Leader Election Aim is to elect exactly one node as the leader.

3 Bully Algorithm Assumes a complete network Uses timeouts to detect failures Node with the highest id is elected the leader

4 Bully algorithm Any process P i : - leader i = id i send elect(leader i ) to all nodes num_recd i = 0 while (num_recd i != n-1) do receive elect(y) from a process; num_recd i ++; if y > leader i then leader i = y;

5 Algorithm Process failures: On detecting failure of leader send elect(id i ) to all nodes with larger ids start timer On receiving elect(y) from P x if y < id i then send nack(id i ) to P x send elect(id i ) to all nodes with larger ids; start timer

6 if y > id i then cancel timer On receiving nack(y), cancel timer Timeout: send elected(id i ) to all processes On recovery, try to elect yourself as the leader.

7 Election in a ring Send message around the ring with your id If P i receives a message with id x and id i < x then P i forwards the messages; If you receive your own message then declare yourself the leader

8 Time complexity Time taken from the instant the first process wakes up to the time when the algorithm finishes, assuming that each message transmission takes one time unit and each local computation action takes one time unit.

9 A more efficient algorithm If phase i, send message to capture nodes up to distance 2 i. If successful in phase i, then an ack is propagated back. When the ack is received back and you have not been captured, the phase number is increased. Capturing is based on (phase, id)

10 Number of nodes at phase 0: N Number of nodes that finish phase 0: Number of nodes that finish phase 1:

11 Election in a complete network Candidate node: state i = candidate L1: select a neighbor j from unvisited set; send elect(leader i ) to j; receive msg(j) from k if msg = ack then if j > i then state = passive; leader i = j else if (unvisited != empty) go to L1 else send elected to all nodes if (msg = elect) and (j > i) then state = passive; send ack(leader i ) to j; state i = passive or sleeping receive elect(j) from j; if j > leader i then leader i = j send ack(leader i ) to j

12 Election in a complete network Candidate node: state i = candidate L1: select S = 2 phasei nodes from unvisited set select elect(phase i, i) to nodes in S; receive msg(phase, j) from k if msg = ack then if (phase, j) > (phase i, i) then state = passive; leader i = j else if (ack received from all nodes in S) then phase i ++; if phase i != logN then go to L1 else send elected to all nodes if (msg = elect) and (phase, j) > (phase i, i) then state = passive; leader i = j; phase i = j send ack(phase,leader i ) to j; state i = passive or sleeping receive elect(phase, j) from j; if (phase, j) > (phase i, leader i ) then leader i = j; phase i = j send ack(phase,leader i ) to j

13 The number of nodes that own k nodes is at most N/k -The sets of nodes captured by different alive candidates are disjoint

14 Election in a complete network Candidate node: state i = candidate L1: select S = 2 phasei nodes from unvisited set select elect(phase i, i) to nodes in S; receive msg(phase, j) from k if msg = ack then if (phase, j) > (phase i, i) then state = passive; leader i = j else if (ack received from all nodes in S) then phase i ++; if phase i != logN then go to L1 else send elected to all nodes if (msg = elect) and (phase, j) > (phase i, i) then state = passive; leader i = j; phase i = j send ack(phase,leader i ) to j; if (msg = kill-owner) and (phase, j) > (phasei, i) then state = passive; leaderi= j; phasei = j send owner-accept(phase,leaderi) to k state i = passive or sleeping - receive elect(phase, j) from j; if (phase, j) > (phase i, leader i ) then send kill-owner(phase,j) to leader if owner-accept is received, then send ack(phase,leader i ) to j; leader = j

15

16

17

18 Minimum Spanning tree construction Each node is a subtree/fragment by itself. Select the minimum outgoing edge of the fragment Send message to connect to the fragment on the other side of this edge to form a larger fragment

19 Selecting minimum outgoing edge Each fragment has a leader/root Leader send FIND message to all nodes in the fragment Each node sends test message on outgoing edges, one at a time in increasing cost order, to find an outgoing edge Each node reports outgoing edges to the leader Leader then selects the minimum one Root is changed to the node with the minimum outgoing edge

20 f 2 4 7 3 6 5 d b e c a 2 4 7 3 6 5 d b e c a 2 4 7 3 6 5 d b e c a 2 4 7 3 6 5 d b e c a 8 8

21 2 4 7 3 6 5 d b e c a

22 Worst Case Message complexity

23

24 Level Numbers Initially, fragments of size one are at level 0 When two fragments of size L merge, a new fragment of size L + 1 is created Level number is included in all messages When a node receives a message from a node with a higher level number X, it delays response until its fragment number becomes at least X.

25 Fragment absorption If node x in fragment F at level L sends message to node y in fragment G at level L’ to combine such that L < L’, then if y is still finding outgoing edge then it absorbs F into G

26

27


Download ppt "CIS 825 Lecture 8. Leader Election Aim is to elect exactly one node as the leader."

Similar presentations


Ads by Google