0% found this document useful (0 votes)
5 views39 pages

Week-9 Election Algorithms

The document discusses election algorithms used in parallel and distributed computing to elect a leader among processes, ensuring consistency and availability. It covers various algorithms, including the Bully Algorithm, Ring Algorithm, Chang-Roberts algorithm, and Hirschberg-Sinclair algorithm, detailing their mechanisms for detecting failures and electing a new coordinator. The focus is on how these algorithms handle concurrent elections and ensure that only one leader is elected among non-faulty processes.

Uploaded by

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

Week-9 Election Algorithms

The document discusses election algorithms used in parallel and distributed computing to elect a leader among processes, ensuring consistency and availability. It covers various algorithms, including the Bully Algorithm, Ring Algorithm, Chang-Roberts algorithm, and Hirschberg-Sinclair algorithm, detailing their mechanisms for detecting failures and electing a new coordinator. The focus is on how these algorithms handle concurrent elections and ensure that only one leader is elected among non-faulty processes.

Uploaded by

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

Election Algorithms

CS 432
Parallel & Distributed Computing

Dr. Shah Khalid


A-205
SEECS Faculty Block
❖ Last Lecture:
Today…
❖ Mutual Exclusion Algorithms
❖ Today’s Session:
❖ Why we need Election Algorithms?
❖ Election Algorithms
❖ Bully Algorithm
❖ Ring Algorithm
❖ Chang-Roberts algorithm
❖ Hirschberg-Sinclair algorithm
Why Election?
❖ Example 1: Your Bank maintains multiple servers in their cloud, but for
each customer, one of the servers is responsible, i.e., is the leader
❖ What if there are two leaders per customer?
❖ Inconsistency

❖ What if servers disagree about who the leader is?


❖ Inconsistency

❖ What if the leader crashes?


❖ Unavailability
Why Election?
❖ In a group of processes, elect a Leader to undertake special tasks.
❖ What happens when a leader fails (crashes)
❖ Some (at least one) process detects this (how?)
❖ Then what?
❖ Focus of this lecture: Election algorithm
1. Elect one leader only among the non-faulty processes
2. All non-faulty processes agree on who is the leader
System Model/Assumptions
❖ Any process can call for an election.
❖ A process can call for at most one election at a time.
❖ Multiple processes can call an election simultaneously.
❖All of them together must yield a single leader only
❖ The result of an election should not depend on which process calls for it.
❖ Messages are eventually delivered.
What Do Election Algorithms Do?
➢ Detect if the current coordinator has failed.
➢ Initiate a procedure to select a new coordinator.
➢ Ensure only one coordinator is elected.
➢ Handle concurrent elections safely.
Election Algorithms
❖ Many algorithms require one process to act as coordinator, initiator or
otherwise perform a special role.
❖ There are different algorithms for coordinator selection
❖ The Bully Algorithm
❖ A Ring Algorithm
❖ Chang-Roberts algorithm
❖ Hirschberg-Sinclair algorithm

7
The Bully Algorithm
❖ Process notices that coordinator is no longer responding to
requests.
❖ It initiate an election as follows
I. P send an ELECTION message to all processes with higher
number
II. If no one responds, P wins the election and becomes coordinator
III. If one of the higher-ups answers, it takes over. P’s job is done

The biggest guy in town always win – bully


algorithm

8
The Bully Algo.

9
The Bully Algo.

10
Cont…
Example: Bully Election
answer=OK

P1 P1 P1

P0 Election P2 P0 P2 P0 P2
answer
Election Election answer Election
P5 P3 P5 P3 P5 P3
Election
Election
P4 P4 P4

1. P2 initiates election 2. P2 receives answers 3. P3 & P4 initiate election

P1 P1 P1

P0 P2 P0 P2 P0 P2

P5 P5 coordina
P5 P3 P3 P3
answer tor

P4 P4 P4

4. P3 receives reply 5. P4 receives no reply 5. P4 announces itself


The Bully Algorithm with Failures
election

election
C
election
The coordinator p4 fails and p1 detects this Stage 1
p answer p p p
1 2 3 4
answer
election

election election C
Stage 2
answer
p1 timeout p p p
2 3 4

p3 fails
Stage 3
p p p p
1 2 3 4

Eventually.....
coordinator
C
Stage 4
p p p p
1 2 3 4
A Token Ring Algorithm

14
A Ring Alog.
❖ The processes are logically arranged in a ring.
❖ When any process notices that the coordinator is nor responding, it builds an
ELECTION message containing its own process number and sends it to its successor
❖ At each step, the sender adds its own number to the list in the message thus making
itself be a candidate.
❖ the message reaches the process that started it all. Then it looks through the
message and decides which process has the highest number and that becomes the
coordinator
❖ Then the message type is changed to COORDINATOR and the message circulates
once again so everyone knows the new coordinator and the new ring
configuration

15
A Ring Alog.
➢ 2, and 5 detect that the coordinator has crashed
➢ Both initiate election

16
Cont.….
Cont.….
Chang-Roberts algorithm
✓ Ring-based coordinator election algorithm, employed in distributed
computing
Algorithms
✓ Every process sends an election message with its id to the left if it has not
seen a message with a higher id
✓ Forward any message with an id greater than own id to the left
✓ If a process receives its own election message it is the leader
✓ It is uniform: number of processes does not need to be known to the
algorithm
Chang-Roberts algorithm
1
8 8
Each node sends 1
a message with 5
2
its id
to the left 2
5
neighbor

6
3
6
3
4
7 7
20 4
If: message received id  current node id
Then: forward message
5
8
1
2

5 8

6
7

3
4
7
21 6
If: message received id  current node id
Then: forward message

8
1
7 2

3 8
4
7
22
If: message received id  current node id
Then: forward message

7
8
1
2

3
4
7
23 8
If: message received id  current node id
Then: forward message

8
1
2

3
4
8 7
24
If: a node receives its own message

Then: it elects itself a leader


8
8
1
2

3
4
7
25
If: a node receives its own message

Then: it elects itself a leader

8
1
leader
2

3
4
7
26
Hirschberg-Sinclair algorithm
• Assume ring is bidirectional
• Carry out elections on increasingly larger sets
• Pi is a leader in phase r=0,1,2,… iff it has the largest id of
all nodes that are at a distance 2r or less from it; to
establish that, it sends probing messages on both sides
Phase 0: send(id,step counter)
to 1-neighborhood

1
8 8
1 8
5
2 2
1
2
5
6

3 5 6
4
6
3 3
7
4
7 7
4
29
If: received id  current id
Then: send a reply(OK)

8
1
2

3
4
7
30
If: a node receives both replies
Then: it becomes a temporal leader
and proceed to next phase

8
1
2

3
4
7
31
Phase 1: send(id,1,1) to left and right
adjacent in the 2-neighborhood

8
8
1
8 2
5
5 6

5 6
6
3 7
4
7
7
32
If: received id 
current id
Then: forward(id,1,2)

8 6
1
8 5
2

5 8

7 6

3 7
6
4
5 7
33
At second step: since step counter=2, I’m on
the boundary of the 2-neighborood

If: received id > current id


Then: send a reply(id)
8
1
2

3
4
7
34
If: a node receives a reply with another id
Then: forward it
If: a node receives both replies
Then: it becomes a temporal leader

8
1
2

3
4
7 35
Phase 2: send id to 2 -neighborhood
2

8
1
8 2

5
8
7
7
6

3
4
7
36
If: received id current id
Then: send a reply

8
1
2

3
4
7
37
If: a node receives both replies
Then: it becomes the leader

8
1
2

3
4
7
38
Phase 3: send id to 8-neighborhood
 The node with id 8 will receive its own probe message, and
then becomes leader!

8
1
leader
2

3
4
7 39

You might also like