Title: Leader in a clique in Onlogn messages
1Leader in a clique in O(nlog(n)) messages
- By Pierre A. Humblet
- and the help of Miki Asa
2Rules 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). - A node that has been captured stop capturing and
its state stopped. - Node can be captured by many other nodes but has
only one master ? the last one that captured it. - Node that captured all the nodes ? leader
3How its done
- 2 messages
- TEST(size,id)
- An attempt to capture other node.
- A TEST from a node I didnt captured ? forward to
my master. - A TEST from a node I captured ? answer it with
WINNER(id). - WINNER(id)
- The result of the fight ? id won the fight.
- Determined by who got bigger domain
- (if equal bigger id)
4A
B
State active Master A
State active Master B
5B wins
Waiting
A
B
B wins A?B TEST(size(A),id(A)) B?B
TEST(size(A),id(A)) B?B WINNER(B)
6B wins
A
B
State active Master A
State active Master B
B wins A?B TEST(size(A),id(A)) B?B
TEST(size(A),id(A)) B?B WINNER(B)
7A wins
A
B
A wins A?B TEST(size(A),id(A)) B?B
TEST(size(A),id(A)) B?B WINNER(A) B?A
WINNER(A)
8A wins
A
B
State active Master A
State stop Master A
A wins A?B TEST(size(A),id(A)) B?B
TEST(size(A),id(A)) B?B WINNER(A) B?A
WINNER(A)
9State active Master A
A
C
B
State active Master C
State stop Master A
10A wins
A
Waiting
C
B
A wins C?B TEST(size(C),id(C)) B?A
TEST(size(C),id(C)) A?B WINNER(A)
11A wins
State active Master A
A
C
B
State stop Master A
State active Master C
A wins C?B TEST(size(C),id(C)) B?A
TEST(size(C),id(C)) A?B WINNER(A)
12C wins
A
C
B
C wins C?B TEST(size(C),id(C)) B?A
TEST(size(C),id(C)) A?B WINNER(C) B?C
WINNER(C)
13C wins
State stop Master A
A
C
B
State stop Master C
State active Master C
C wins C?B TEST(size(C),id(C)) B?A
TEST(size(C),id(C)) A?B WINNER(C) B?C
WINNER(C)
14Variables
- STATE active won all the fights
- stopped lost a fight ? wont be a leader
- SIZE number of nodes I captured (send me
winner (ID)) including me - (size of my domain).
- MASTER the id of my master.
- EDGE(id) the edge leading to node id
- Dealing with messages
- PENDING_SET messages waiting to be forward to
the master - PENDING number of messages in PENDING_SET
- Initialization
- Each awaken node with ID receive winner(ID) on
edge gt 0.
15Receiving WINNER(id) on edge e
- If (id ID) // I won the fight
-
- if (e gt 0 state active) // fight that I
initiated -
- SIZE
- if SIZE N // I capture all the nodes
- stop // announce elected
- else
- send TEST(SIZE,ID) on edge SIZE //continue
-
- else // I didnt initiate the fight
- do nothing
16Receiving WINNER(id) (cont.)
- Else // id ! ID
-
- if (MASTER ! id) // my master lost
-
- MASTER id // change the master
- Send WINNER(id) on EDGE(id) // inform the
new master -
- Else // my master won
-
- do nothing
-
- PENDING - - // continue as a slave
- if PENDING gt 0
- send from PENDING_SET on EDGE(MASTER)
17Receiving TEST(size,id) on edge e
- If e lt SIZE // message from my domain
-
- if (size,id) gt (SIZE,ID) // I lost this
fight -
- STATE stopped // out of the game
- send WINNER(id) on EDGE e // inform the new
master -
- else // I won
- send WINNER(ID) on EDGE e // inform my slave
that I won -
- Else // not from my domain
-
- EDGE(id) e // update my data-base
- PENDING // send TEST to the master
- If PENDING 1
- send TEST(size,id) on EDGE (MASTER)
- else
- put TEST(size,id) on EDGE (MASTER) on
PENDING_SET
18state Size Master
active 1 2
2
active 1 3
active 1 1
1
3
6
4
active 1 4
active 1 6
5
active 1 5
19state Size Master
active 1 2
2
active 2 3
stop 1 3
1
3
6
4
active 1 4
active 1 6
5
active 1 5
20state Size Master
active 1 2
2
active 2 4
active 2 3
stop 1 4
stop 1 3
1
4
1
3
Waiting
8
6
4
active 1 4
active 1 6
5
active 1 5
21state Size Master
active 1 2
2
active 2 3
stop 1 3
1
3
Waiting
6
4
active 1 4
active 1 6
5
active 1 5
22state Size Master
active 1 2
2
active 2 3
stop 1 3
1
3
Waiting
6
4
stop 1 6
active 2 6
5
active 1 5
23state Size Master
active 1 2
2
active 2 3
stop 1 3
1
3
Waiting
Waiting
6
4
stop 1 6
active 2 6
5
active 1 5
24state Size Master
active 1 2
2
active 2 3
stop 1 3
1
3
Waiting
Waiting
6
4
stop 1 6
active 2 6
5
active 1 5
25state Size Master
active 1 2
2
stop 2 3
stop 1 6
1
3
Waiting
Waiting
6
4
stop 1 6
active 3 6
5
active 1 5
26state Size Master
active 1 2
2
stop 2 3
stop 1 6
1
3
Waiting
Waiting
6
4
stop 1 6
active 3 6
5
active 1 5
27state Size Master
active 1 2
2
stop 2 3
stop 1 6
1
3
Waiting
6
4
stop 1 6
active 3 6
5
stop 1 3
28state Size Master
active 1 2
2
stop 2 3
stop 1 6
1
3
Waiting
6
4
stop 1 6
active 3 6
5
stop 1 3
29state Size Master
active 1 2
2
stop 2 6
stop 1 6
1
3
Waiting
6
4
stop 1 6
active 4 6
5
stop 1 3
30state Size Master
active 1 2
Waiting
2
stop 2 6
stop 1 6
1
3
Waiting
6
4
stop 1 6
active 4 6
5
stop 1 3
31state Size Master
active 1 2
Waiting
2
stop 2 6
stop 1 6
1
3
Waiting
6
4
stop 1 6
active 4 6
5
stop 1 3
32state Size Master
active 1 6
Waiting
2
stop 2 6
stop 1 6
1
3
Waiting
6
4
stop 1 6
active 5 6
5
stop 1 3
33state Size Master
active 1 6
Waiting
2
stop 2 6
stop 1 6
1
3
Waiting
6
4
stop 1 6
active 5 6
5
stop 1 3
34state Size Master
active 1 6
Waiting
2
stop 2 6
stop 1 6
1
3
Waiting
6
4
stop 1 6
active 6 6
5
stop 1 6
35Termination
- Each node cant send more then N-1 TEST.
- Each TEST cause at the most 3 more messages.
36Correctness
- Lemma 1
- At the end of the algorithm there will be a node
with size N. - Proof
- Size only grows with time.
- For each TEST sent
- size or
- Node is Waiting
- Therefore
- Enough to prove there is no deadlock
37Liveness
- Suppose there is a deadlock
- Lets take the node with the biggest (size,ID) ?
its active. - Eventually it will get an answer for the last
test it initiated. Winner(ID). - Once hell get that answer ? size
- Size N ? leader
- Send TEST for the next node
38complexity
- My domain the nodes from which I received
winner(ID) while I was active myself. - Lemma 1
- SIZE size of my domain.
- If (id ID) // I won the fight
-
- if (e gt 0 state active) // fight that I
initiated -
- SIZE
- Got winner(ID) from other node state active ?
all conditions fulfill ? size - Size ? all conditions fulfill ? Got winner(ID)
from other node state active
39- Lemma 2
- If SIZE(A) at time Ta SIZE(B) at time Tb
then the domains at Ta Tb are disjoint. - Proof
- Assume domain(A) domain(B) are joint at Ta or
Tb ? - They are joint at max(Ta,Tb) ?
- There is a Tm lt max(Ta,Tb) s.t.
At Tm a node from domain(A) join
domain(B) ? - After Tm domain(A) doesnt grow ?
- At Tm Size(A) gt SIZE ? Tm gt Ta
- After Tm domain(B) gt domain(A) gt SIZE ?
- Tm gt Tb
- Contradiction
40- Lemma 3
- Rank the nodes in decreasing order by their SIZE
at termination. - S1, S2, S3, . . . , Sn-1, Sn
- Then Sk lt N/k
- Proof
- S1 Sk-1 had once the size of Sk ?
- there all disjoint (lemma 2)
- conclusion
- There is only one node with SIZEN ? one leader
41- Number of TEST sent
- If (id ID) // I won the fight
-
- if (e gt 0 state active) // fight that I
initiated -
- SIZE
- if SIZE N // I capture all the nodes
- stop // announce elected
- else
- send TEST(SIZE,ID) on EDGE(SIZE) //continue
- For each TEST sent ? SIZE
- Each TEST cause at the most 3 more messages
42- Total number of messages is no more then
- 4(N/1 N/2 N/3 . . . N/K)
- O(N log(K))
- K the number of nodes awake.
43Improvements
- The bound for the number of messages can be
tightened by noticing that the first TEST
received by a generates at the most one more
message. - The algorithm can stop as soon as SIZE N/2
(then announce elected).