0% found this document useful (0 votes)
48 views25 pages

2.10 Election Algorithm

The document discusses election algorithms used to select a coordinator in distributed systems. It covers traditional algorithms like the Bully algorithm and ring algorithm as well as wireless election algorithms. The Bully algorithm works by having processes with higher IDs take over if they respond, while the ring algorithm circulates an election message around a logical ring. Wireless algorithms elect the node with the best capacity and find the coordinator through parent-child message passing relationships.

Uploaded by

AbcXyz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views25 pages

2.10 Election Algorithm

The document discusses election algorithms used to select a coordinator in distributed systems. It covers traditional algorithms like the Bully algorithm and ring algorithm as well as wireless election algorithms. The Bully algorithm works by having processes with higher IDs take over if they respond, while the ring algorithm circulates an election message around a logical ring. Wireless algorithms elect the node with the best capacity and find the coordinator through parent-child message passing relationships.

Uploaded by

AbcXyz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

18IT902 - DISTRIBUTED SYSTEMS

Module :2
Module Name : Processes and Synchronization
Topic : Election algorithms
Faculty : Dr.K.Sasi Kala Rani
Topics Covered
• Need for a Coordinator
• Election algorithms
• Traditional election algorithms
– Bully algorithm
– Ring algorithm
• Wireless election algorithms
Need for a Coordinator
• Many algorithms used in distributed systems require a
coordinator
– For example, see the centralized mutual exclusion algorithm.
• In general, all processes in the distributed system are equally
suitable for the role
• Election algorithms are designed to choose a coordinator.
Election Algorithms

• Any process can serve as coordinator


• Any process can “call an election” (initiate the algorithm to
choose a new coordinator).
– There is no harm (other than extra message traffic) in
having multiple concurrent elections.
• Elections may be needed when the system is initialized, or if
the coordinator crashes or retires.
Assumptions
• Every process/site has a unique ID; e.g.
– the network address
– a process number
• Every process in the system should know the values in the set
of ID numbers, although not which processors are up or down.
• The process with the highest ID number will be the new
coordinator.
Requirements
• When the election algorithm terminates a single process has
been selected and every process knows its identity.
• Formalize: every process pi has a variable ei to hold the
coordinator’s process number.
– ∀i, ei = undefined or ei = P, where P is the non-crashed
process with highest id
– All processes (that have not crashed) eventually set ei = P.
The Bully Algorithm - Overview
When any process notices that the coordinator is no longer
responding to requests, it initiates an election.
A process, P, holds an election as follows:
• P sends an ELECTION message to all processes with higher
numbers.
• If no one responds, P wins the election and becomes
coordinator.
• If one of the higher-ups answers, it takes over. P's job is done.
• When a crashed process reboots, it holds an election. If it is now
the highest-numbered live process, it will win.
1 5 1
2 2 5
election 6 OK
4 6
election 4 OK
election
0 3 0 3
7 7

• Process 4 holds an election.


• Processes 5 and 6 respond. telling 4 to stop.
• The process q now calls an election (if it has not already done so).
• Repeat until no higher-level process responds. The last process
to call an election “wins” the election.
• The winner sends a message to other processes announcing itself
as the new coordinator.
• Now 5 and 6 each hold an election.
1 5
• Process 6 tells 5 to stop. 2
• Process 6 wins and tells everyone. election
• If 7 comes back on line, it will call an 4 6
election
election election
0 3
7

1 1
2 5 5
OK 2
4 6
4 coordinator 6
0 3 0 3
7 7
1 5 1 1 5
2 2 5 2
election 6 OK election
4 6 4 6
election 4 OK election
election election
0 3 0 3 0 3
7 7 7

1 1
2 5 5
OK 2
4 6
4 coordinator 6
0 3 0 3
7 7
Analysis
• Works best if communication in the system has bounded
latency so processes can determine that a process has failed
by knowing the upper bound (UB) on message transmission
time (T) and message processing time (M).
– UB = 2 * T + M
• However, if a process calls an election when the coordinator
is still active, the coordinator will win the election.
A Ring Algorithm - Overview
• The ring algorithm assumes that the processes are arranged in
a logical ring and each process is knows the order of the ring of
processes.
• Processes are able to “skip” faulty systems: instead of sending
to process j, send to j + 1.
• Faulty systems are those that don’t respond in a fixed amount
of time.
A Ring Algorithm
• P thinks the coordinator has crashed; builds an ELECTION
message which contains its own ID number.
• Sends to first live successor
• Each process adds its own number and forwards to next.
• OK to have two elections at once.
Example
• 2 and 5, discover simultaneously that the previous coordinator,
process 7, has crashed.
• Each of these builds an ELECTION message and each of them
starts circulating its message, independent of the other one.
• Eventually, both messages will go all the way around, and both 2
and 5 will convert them into COORDINATOR messages, with
exactly the same members and in the same order.
• When both have gone around again, both will be removed.
• It does no harm to have extra messages circulating; at worst it
consumes a little bandwidth, but this not considered wasteful.
Ring Algorithm - Details
• When the message returns to p, it sees its own process ID in
the list and knows that the circuit is complete.
• P circulates a COORDINATOR message with the new high
number.
• Here, both 2 and 5 elect 6:
[5,6,0,1,2,3,4]
[2,3,4,5,6,0,1]
Elections in Wireless Environments
• Traditional algorithms aren’t appropriate.
– Can’t assume reliable message passing or stable network
configuration
• This discussion focuses on ad hoc wireless networks but
ignores node mobility.
– Nodes connect directly, no common access point,
connection is short term
– Often used in multiplayer gaming, on-the-fly file transfers,
etc.
Assumptions
• Wireless algorithms try to find the best node to be coordinator;
traditional algorithms are satisfied with any node.
• Any node (the source) can initiate an election by sending an
ELECTION message to its neighbors – nodes within range.
• When a node receives its first ELECTION message the sender
becomes its parent node.
Example

• Initial network - Nodes have been labeled a to j, along with their


capacity. Fig. (a).
• Node a initiates an election by broadcasting an ELECTION
message to nodes b and j, Fig. (b).
• The build-tree phase - Fig. (b) to Fig. (e)
• After that step, ELECTION messages are propagated to all nodes,
ending with the situation shown in Fig. e, where we have omitted
the last broadcast by nodes f and i:
• From there on, each node reports to its parent the node with the
best capacity, as shown in Fig.(f).
Figure 6-22.

• Node a is the source.


Messages have a unique ID to manage possible concurrent
elections
When a node R receives its first election message, it designates
the source Q as its parent, and forwards the message to all
neighbors except Q.
When R receives an election message from a non-parent, it just
acknowledges the message
• Figure 6-22. (e) The build-tree phase.
(f) Reporting of best node to source.

If R’s neighbors have parents, R is a leaf; otherwise it waits for its


children to forward the message to their neighbors.
When R has collected acks from all its neighbors, it acknowledges
the message from Q.
Acknowledgements flow back up the tree to the original source.
Example
• For example, when node g receives the acknowledgments from its
children e and h, it will notice that h is the best node, propagating
[h, 8] to its own parent, node b.
• In the end, the source will note that h is the best leader and will
broadcast this information to all other nodes.
• At each stage the “most eligible” or “best” node will be passed
along from child to parent.
• Once the source node has received all the replies, it is in a
position to choose the new coordinator.
• When the selection is made, it is broadcast to all nodes in the
network.
Wireless Elections
• If more than one election is called (multiple source nodes), a node
should participate in only one.
• Election messages are tagged with a process id.
• If a node has chosen a parent but gets an election message from
a higher numbered node, it drops out of the current election and
adopts the high numbered node as its parent. This ensures only
one election makes a choice.
Summary
• Election algorithms are designed to choose a coordinator
• Elections may be needed when the system is initialized, or if the
coordinator crashes or retires.
• High-numbered processes “bully” low-numbered processes out
of the election, until only one process remains.
• The ring algorithm assumes that the processes are arranged in
a logical ring and each process is knows the order of the ring of
processes.
Video and Assessment Links

Lecture Video 1 Lecture Video 2

You might also like