Upload
nitza
View
27
Download
0
Embed Size (px)
DESCRIPTION
Leader in a clique in O(nlog(n)) messages. By Pierre A. Humblet and the help of Miki Asa. Rules of the game. Initialization : Each node has {1 . . N-1} edges + edge (–1) to itself. master(id) = id, state = active. Node attempt to capture other nodes (increase the size of their domain). - PowerPoint PPT Presentation
Citation preview
Leader in a clique in Leader in a clique in O(nlog(n)) messages O(nlog(n)) messages
By Pierre A. HumbletBy Pierre A. Humblet
and the help of Miki Asaand the help of Miki Asa
Rules of the gameRules of the game Initialization : Initialization :
Each node has {1 . . N-1} edges + edge (–1) to Each node has {1 . . N-1} edges + edge (–1) to itself.itself.
master(id) = id, state = active.master(id) = id, state = active. Node attempt to capture other nodes Node attempt to capture other nodes
(increase the (increase the sizesize of their domain). of their domain). A node that has been captured stop capturing A node that has been captured stop capturing
and it’s state = stopped.and it’s state = stopped. Node can be captured by many other nodes Node can be captured by many other nodes
but has only one but has only one mastermaster the last one that the last one that captured it.captured it.
Node that captured all the nodes Node that captured all the nodes leaderleader
How it’s doneHow it’s done2 messages2 messages TEST(size,id)TEST(size,id)
An attempt to capture other node.An attempt to capture other node. A TEST from a node I didn’t captured A TEST from a node I didn’t captured
forward to my master.forward to my master. A TEST from a node I captured A TEST from a node I captured
answer it with WINNER(id).answer it with WINNER(id). WINNER(id)WINNER(id)
The result of the fight The result of the fight id won the id won the fight.fight.
Determined by who got bigger domain Determined by who got bigger domain (if equal bigger id)(if equal bigger id)
A B
State = activeMaster = A
State = activeMaster = B
A B
B winsAB : TEST(size(A),id(A))BB : TEST(size(A),id(A))BB : WINNER(B)
B winsB winsWaiting
B winsAB : TEST(size(A),id(A))BB : TEST(size(A),id(A))BB : WINNER(B)
A B
State = activeMaster = A
State = activeMaster = B
B wins
A B
A winsAB : TEST(size(A),id(A))BB : TEST(size(A),id(A))BB : WINNER(A)BA : WINNER(A)
A winsA wins
A winsAB : TEST(size(A),id(A))BB : TEST(size(A),id(A))BB : WINNER(A)BA : WINNER(A)
A B
State = activeMaster = A
State = stopMaster = A
A wins
C B
A
State = activeMaster = C
State = stopMaster = A
State = activeMaster = A
C B
A
A winsCB : TEST(size(C),id(C))BA : TEST(size(C),id(C))AB : WINNER(A)
A wins
Waiting
C B
A
A winsCB : TEST(size(C),id(C))BA : TEST(size(C),id(C))AB : WINNER(A)
State = activeMaster = C
State = stopMaster = A
State = activeMaster = A
A wins
C B
A
C winsCB : TEST(size(C),id(C))BA : TEST(size(C),id(C))AB : WINNER(C)BC : WINNER(C)
C wins
C B
A
C winsCB : TEST(size(C),id(C))BA : TEST(size(C),id(C))AB : WINNER(C)BC : WINNER(C)
State = activeMaster = C
State = stopMaster = C
State = stopMaster = A
C wins
VariablesVariablesSTATE :STATE : active – won all the fights active – won all the fights
stopped – lost a fight stopped – lost a fight won’t be a leader won’t be a leader
SIZE :SIZE : number of nodes I captured (send me winner (ID)) number of nodes I captured (send me winner (ID)) including me including me
(size of my domain).(size of my domain).
MASTER : the id of my master.MASTER : the id of my master.
EDGE(id) : the edge leading to node idEDGE(id) : the edge leading to node id
Dealing with messagesDealing with messages
PENDING_SET : messages waiting to be forward to the masterPENDING_SET : messages waiting to be forward to the master
PENDING : number of messages in PENDING_SETPENDING : number of messages in PENDING_SET
InitializationInitialization
Each awaken node with ID receive winner(ID) on edge > 0.Each awaken node with ID receive winner(ID) on edge > 0.
Receiving WINNER(id) on edge eReceiving WINNER(id) on edge e
If (id = ID) If (id = ID) // I won the fight// I won the fight{{
if (e > 0 & state = active)if (e > 0 & state = active) // fight that I initiated// fight that I initiated{{SIZE ++SIZE ++if SIZE = N if SIZE = N // I capture all the nodes// I capture all the nodes
stopstop // announce elected// announce electedelse else
send TEST(SIZE,ID) on edge SIZE //continue send TEST(SIZE,ID) on edge SIZE //continue }}
elseelse // I didn’t initiate the // I didn’t initiate the fightfight
do nothingdo nothing}}
Receiving WINNER(id) (cont.)Receiving WINNER(id) (cont.)
ElseElse // id != ID// id != ID{{
if (MASTER != id)if (MASTER != id) // my master lost // my master lost {{
MASTER = idMASTER = id // change the master// change the masterSend WINNER(id) on EDGE(id) // inform the Send WINNER(id) on EDGE(id) // inform the
new masternew master}}Else Else // my master won// my master won{{
do nothingdo nothing}}
PENDING - -PENDING - - // continue as a slave// continue as a slaveif PENDING > 0if PENDING > 0
send from PENDING_SET on EDGE(MASTER)send from PENDING_SET on EDGE(MASTER)
}}
Receiving TEST(size,id) on edge eReceiving TEST(size,id) on edge eIf e < SIZEIf e < SIZE // message from my domain// message from my domain
{{
if (size,id) > (SIZE,ID) if (size,id) > (SIZE,ID) // I lost this fight // I lost this fight
{{
STATE = stoppedSTATE = stopped // out of the game // out of the game
send WINNER(id) on EDGE esend WINNER(id) on EDGE e // inform the new master// inform the new master
}}
else else // I won // I won
send WINNER(ID) on EDGE esend WINNER(ID) on EDGE e // inform my slave that I // inform my slave that I wonwon
}}
Else Else // not from my domain // not from my domain
{{
EDGE(id) = eEDGE(id) = e // update my data-base // update my data-base
PENDING ++PENDING ++ // send TEST to the master // send TEST to the master
If PENDING = 1If PENDING = 1
send TEST(size,id) on EDGE (MASTER)send TEST(size,id) on EDGE (MASTER)
elseelse
put TEST(size,id) on EDGE (MASTER) on PENDING_SETput TEST(size,id) on EDGE (MASTER) on PENDING_SET
}}
1
6
5
4
3
2
stateSize
Master
active13
active12
active11
active16 active
15
active14
1 3
stateSize
Master
stop13
6
5
4
2active
23
active12
active16 active
15
active14
1
8
4
stateSize
Master
active24stop
14 1 3
stop13
6
5
4
2active
23
active12
active16 active
15
active14
Waiting
stateSize
Master
1 3
stop13
6
5
4
2active
23
active12
active16
active14
Waiting
active15
stateSize
Master
1 3
stop13
6
5
4
2active
23
active12
active26
stop16
Waiting
active15
stateSize
Master
1 3
stop13
6
5
4
2active
23
active12
active26
stop16
Waiting
active15
Waiting
stateSize
Master
1 3
stop13
6
5
4
2active
23
active12
active26
stop16
Waiting
active15
Waiting
stateSize
Master
1 3
stop16
6
5
4
2stop
23
active12
active36
stop16
Waiting
active15
Waiting
stateSize
Master
1 3
stop16
6
5
4
2stop
23
active12
active36
stop16
Waiting
active15
Waiting
stateSize
Master
1 3
stop16
6
5
4
2stop
23
active12
active36
stop16
Waiting
stop13
stateSize
Master
1 3
stop16
6
5
4
2stop
23
active12
active36
stop16
Waiting
stop13
stateSize
Master
1 3
stop16
6
5
4
2stop
26
active12
active46
stop16
Waiting
stop13
stateSize
Master
1 3
stop16
6
5
4
2stop
26
active12
active46
stop16
Waiting
stop13
Waiting
stateSize
Master
1 3
stop16
6
5
4
2stop
26
active12
active46
stop16
Waiting
stop13
Waiting
stateSize
Master
1 3
stop16
6
5
4
2stop
26
active16
active56
stop16
Waiting
stop13
Waiting
stateSize
Master
1 3
stop16
6
5
4
2stop
26
active16
active56
stop16
Waiting
stop13
Waiting
stateSize
Master
1 3
stop16
6
5
4
2stop
26
active16
active66
stop16
Waiting
stop16
Waiting
TerminationTermination
Each node can’t send more then N-1 Each node can’t send more then N-1 TEST.TEST.
Each TEST cause at the most 3 more Each TEST cause at the most 3 more messages.messages.
CorrectnessCorrectness
Lemma 1Lemma 1
At the end of the algorithm there will be a At the end of the algorithm there will be a node with size = N.node with size = N.
ProofProof Size only grows with time.Size only grows with time. For each TEST sentFor each TEST sent
size++ orsize++ or Node is “Waiting”Node is “Waiting”
Therefore Therefore
Enough to prove there is no deadlockEnough to prove there is no deadlock
LivenessLiveness Suppose there is a deadlockSuppose there is a deadlock Lets take the node with the biggest Lets take the node with the biggest
(size,ID) (size,ID) it’s active. it’s active. Eventually it will get an answer for Eventually it will get an answer for
the last test it initiated. Winner(ID).the last test it initiated. Winner(ID). Once he’ll get that answer Once he’ll get that answer size++ size++
Size = N Size = N leader leader Send TEST for the next nodeSend TEST for the next node
complexitycomplexityMy domain:My domain: the nodes from which I the nodes from which I
received winner(ID) while I was active + received winner(ID) while I was active + myself.myself.
Lemma 1Lemma 1SIZE = size of my domain.SIZE = size of my domain.
If (id = ID) If (id = ID) // I won the fight// I won the fight{{
if (e > 0 & state = active)if (e > 0 & state = active) // fight that I // fight that I initiatedinitiated
{{SIZE ++SIZE ++
Got winner(ID) from other node & state = Got winner(ID) from other node & state = active active all conditions fulfill all conditions fulfill size++ size++
Size++ Size++ all conditions fulfill all conditions fulfill Got winner(ID) Got winner(ID) from other node & state = activefrom other node & state = active
Lemma 2Lemma 2If SIZE(A) at time Ta = SIZE(B) at time Tb If SIZE(A) at time Ta = SIZE(B) at time Tb
then the domains at Ta & Tb are disjoint.then the domains at Ta & Tb are disjoint.Proof:Proof: Assume domain(A) & domain(B) are joint at Ta or Assume domain(A) & domain(B) are joint at Ta or
Tb Tb They are joint at max(Ta,Tb) They are joint at max(Ta,Tb) There is a Tm < max(Ta,Tb) s.t. There is a Tm < max(Ta,Tb) s.t.
At Tm a node from domain(A) join domain(B) At Tm a node from domain(A) join domain(B) After Tm domain(A) doesn’t grow After Tm domain(A) doesn’t grow At Tm Size(A) >= SIZE At Tm Size(A) >= SIZE Tm > Ta Tm > TaAfter Tm domain(B) > domain(A) >= SIZE After Tm domain(B) > domain(A) >= SIZE Tm > TbTm > TbContradictionContradiction
Lemma 3Lemma 3
Rank the nodes in decreasing order by Rank the nodes in decreasing order by their SIZE at termination.their SIZE at termination.
SS11, S, S22, S, S33, . . . , S, . . . , Snn-1-1, S, Snn
Then SThen Skk <= <= N/N/kk
ProofProof
SS11 – S – Skk-1-1 had once the size of S had once the size of Skk
there all disjoint (lemma 2)there all disjoint (lemma 2)
conclusionconclusion
There is only one node with SIZE=N There is only one node with SIZE=N one leaderone leader
Number of TEST sentNumber of TEST sent
If (id = ID) If (id = ID) // I won the fight// I won the fight{{
if (e > 0 & state = active)if (e > 0 & state = active) // fight that I // fight that I initiatedinitiated
{{SIZE ++SIZE ++if SIZE = N if SIZE = N // I capture all the nodes// I capture all the nodes
stopstop // announce elected// announce electedelse else
send TEST(SIZE,ID) on EDGE(SIZE) //continue send TEST(SIZE,ID) on EDGE(SIZE) //continue }}
For each TEST sent For each TEST sent SIZE++ SIZE++Each TEST cause at the most 3 more Each TEST cause at the most 3 more
messages messages
Total number of messages is no Total number of messages is no more thenmore then
4*(N/1 + N/2 + N/3 + . . . + N/K)4*(N/1 + N/2 + N/3 + . . . + N/K)
= O(N log(K))= O(N log(K))
K = the number of nodes awake.K = the number of nodes awake.
ImprovementsImprovements The bound for the number of The bound for the number of
messages can be tightened by messages can be tightened by noticing that the first TEST received noticing that the first TEST received by a generates at the most one more by a generates at the most one more message.message.
The algorithm can stop as soon as The algorithm can stop as soon as SIZE = N/2 (then announce elected).SIZE = N/2 (then announce elected).