Synchronization Tech
Synchronization Tech
Election Algorithms
Election Algorithms
◆ Many distributed algorithms require one process to
act as coordinator, initiator, or otherwise perform a
special role.
◆ It does not matter who does it but one of them has to
be a coordinator.
◆ These algorithms will assume that each active process
has a unique priority id.
◆ In general, election algorithms attempt to locate the
process with the highest process number and
designate it as the coordinator. (could use network
addresses)
⬥ For simplicity we assume one process per machine
Election Algorithms:
Election principles
▪ Any process can call for an election.
▪ A process can call for at most one election at a time.
▪ There could be concurrent calls for the same election.
▪ The result of an election does not depend on which process
calls for it.
▪ Processes involved in an election are called the “participants”
of the election.
▪ The non-failed process with the best election attribute value
(e.g., highest id or address, fastest cpu, etc.) is elected.
▪ A run of the election algorithm must always guarantee at the
end:
▪ Safety: Non-failed process selected has best attribute value
Bully Algorithm
◆ Each process has a unique numerical ID
3
0
electio
n
5
Election Algorithms: Ring Algorithm
◆ As a message is passed on, the sender adds itself to the
list. When it gets back to the initiator, everyone had a
chance to make its presence known
election: 3
0 5
5
Election Algorithms: Ring Algorithm
◆ When a node receives a “coordinator message”, he
records the ID of the new leader and changes state to
Normal, and forwards the message (unless he is the
leader).
0 Electio 3
n
0,3,4,5
5
Election Algorithms: Ring Algorithm, Example
• Even if two ELECTIONS start at once, everyone will pick the same
leader.
Election Algorithms: Ring Algorithm, Example
Election: 2,
P1 P1 3,4,0,1 P1
P0 P2 P0 P2 P0 P2
Election: 2 Coord(4): 2
El P5 P5 P5
ec P3 P3 P3
tio P4 P4
n:
2,3 Election: 2,3
,4 P4 Coord(4): 2,3
2. P2 receives “election”, 3. P2 selects 4 and
1. P2 initiates election P4 dies announces the result
Coord(4) 2, Election: 2, Coord(3): 2,
P1 3,0,1 Election: Coord(3): P1 3,0,1
P1 3,0,1
2,3,0 2,3,0
P0 P2 P0 P2 P0 P2
Election: 2 Coord(3): 2
P5 P5 P5
P3 P3 P3
P4 P4 P4
dead coordinator
Lost token,
Token ring 1 to ∞ 0 to n – 1
process crash