Leader election
Leader election
Definition : Given a set of processes choose an unique leader (safety) in a finite time (liveness).
Applications :
• radio and wifi networks
• wired networks
• spanning tree construction
• cloud or client-server architectures
Leader election
Th. There is no deterministic algorithm for leader election in anonymous and uniform networks.
Proof idea:
1. The network is anonymous and the initial configuration is symmetric ;
2. The objectif configuration (with an elected leader) is asymmetric ;
3. There is an execution such as the system goes from a
symmetric configuration into an asymmetric
configuration and vice-versa.
Leader election
• Bypass the impossibility results :
– use of identifiers
• Chang et Roberts
• Hirshberg-Sinclair
• Diffusion
– use of randomness
• Itai et Rodeh
Chang-Roberts algorithm
Chang&Roberts algorithm
• Topology : unidirectional ring (each site «i»
has a pointeur vers to its successeur succ[i])
• Idea : each candidate sends along the ring its
candidature ; the process with the maximal
identifier wins
Algorithme Chang-Roberts
Candidature site «i»
candidat_i = true
send <CHEF,i> to succ[i] /* i sends its candidature
Reception at site «i» of message <CHEF,j> sent by site «j»
Case
j>i: send <CHEF,j> to succ[i]
j<i: if not candidat_i
candidat_i=true; send <CHEF,i> to succ[i]
j=i: diffusion <CHEF, i> /* send to all the election result
Chang-Roberts - example
0
4 3
2
0
4 3
2 0
4 3
2
0
4 3
2
Complexity Best case : O(n)
•
Identifiers ordered in an increasing order around the ring.
1
2 4
3
Complexity
Worst case : O(n 2 )
•
The identifiers are ordered in a decreasing order around the ring
•
Identifier « i » visits i before its status is
decided 4
3 1
2
Complexity
Average : O(nlog(n))
★ Identify all the possibilities to arrange identifiers around the ring : (n-1)!
★ Let X_k denote : the number of messages if the election would start at node k
★ E[ ∑X_k ] = ∑ E[X_k] for k going
from 1 to n
«Diffusion»
«Diffusion 1»
• Idea :
– each candidate sends its identity to the other nodes in the network
– a site responds to all nodes having an identifier inferior of itself
– a process that does not receive a response its the leader
• Hypotheses : reliable communication and
synchronous (upper bound on the communication
time known)
«Diffusion 2»
• Idea :
– each candidate sends its identity to the other nodes in the network and waits for the identity of the other sites
– compute max/min over the set of identities received
• Hypothesis : reliable communication and knowledge
of the number of processes in the network
Hirschberg-Sinclair algorithm
Hirschberg-Sinclair
• Topology : bidirectional ring
• the algorithm works in rounds
• only the processes which win the round
« r » play for round « r+1 »
• Algorithm: P i is the leader of round « r » if
and only if P i has the maximal identifier
in the set of nodes at distance at most 2 r
from P i
Hirschberg-Sinclair
• Initially:
– all processus sont leaders
• Round 0:
– 6 , 7 et 8 leaders
• Round 1:
– 7, 8 leaders
• Round 2:
– 8 the unique leader
– at most log(N) rounds
Itai-Rodeh algorithm
Algorithme Itai-Rodeh
• use Chang&Roberts algorithm
• each process chooses a random id in 1..n (two processes can choose the same id)
• each process candidate sends a message with to fields : – “counter” initially equal to 1
– “another” initially equal to false (as soon as the message meets a candidat with the same id, “another” sets to true)
• leaders at round “i” reexecute the algorithm
• the algorithm finishes with probability 1
Leader Election Applications
20
Spanning tree construction (diffusion)
• a single spanning tree is constructed (safety) in a finite time (liveness)
• leader-based solution
– the leader starts the construction by sending message M
to its neighbors ; on the reception of a message a process
takes as father in the tree the sender and diffuses the
message to its neighbors except its father.
Spanning tree construction (diffusion)
• Structures :
– Parent : pointer to the parent node in the tree (initially NULL)
– Children : set of children (initially empty)
– Others : neighbors which are not children (initially
empty)
Spanning tree construction (diffusion)
1 2
3
5 4
6 7
Site i initiator
if leader and parent=NULL then send M to neighbors; parent=i
Site i receive message M from site j if parent=NULL then
parent=j
send <parent> to j
send M to neighbors k, such that k≠j
else send <reject> to j
Site i receives <parent> from site j children=children U {j}
if children U others=voisins \ {parent} then
end
Site i receives <reject> from site j others=others U {j}
if children U others=voisins \ {parent} then
end
Spanning tree construction (diffusion)
Site i initiator
if leader and parent=NULL then send M to neighbors; parent=i
Site i receive message M from site j if parent=NULL then
parent=j
send <parent> to j
send M to neighbors k, such that k≠j
else send <reject> to j
Site i receives <parent> from site j children=children U {j}
if children U others=voisins \ {parent} then
end
Site i receives <reject> from site j others=others U {j}
if children U others=voisins \ {parent} then
end