Download presentation
Presentation is loading. Please wait.
Published byHortense Malone Modified over 9 years ago
1
Election Algorithms
2
Topics r Issues r Detecting Failures r Bully algorithm r Ring algorithm
3
Readings r Van Steen and Tanenbaum: 5.4 r Coulouris: 11.3
4
Election Algorithms r Remember using Lamport clocks for total order r Can you think of another way to do this? r It turns out that you can use a sequencer. m All operations go to a sequencer m The sequencer assigns numbers to each message before the message goes to each replica m What if the sequencer goes down?
5
Election Algorithms r Many distributed algorithms require a process to act as a coordinator. r The coordinator can be any process that organizes actions of other processes. r A coordinator may fail r How is a new coordinator chosen or elected?
6
Election Algorithms r Assumptions m Each process has a unique number to distinguish them. m One process per machine (which suggests that an IP address can be the unique identifier) Processes know each other ’ s process number m Processes do not know which ones are currently up and which ones are down. r General Approach m Locate the process with the process with the highest process number and designate it as the coordinator. m Election algorithms differ in how they do this.
7
Issues in Dealing with Coordinator Failure m Detecting Failure Any node might detect failure first Multiple processes might detect failure at once. m Election Must run without coordination Must deal with arbitrary process failures All nodes must agree on when election is over and who the new coordinator is.
8
Detecting Failures r Timeouts are used to detect failures T = 2T trans + T process Where T tran is maximum transmission delay and T proces s represents the maximum delay for processing a message. r If a process fails to respond to a message request within T seconds then an election is initiated.
9
Bully Algorithm r When a process, P, notices that the coordinator is no longer responding to requests, it initiates an election. m P sends an ELECTION message to all processes with higher numbers. m If no one responds, P wins the election and becomes a coordinator. If one of the higher-ups answers, it takes over. P ’ s job is done.
10
Bully Algorithm r When a process gets an ELECTION message from one of its lower-numbered colleagues: m Receiver sends an OK message back to the sender to indicate that he is alive and will take over. m Receiver holds an election, unless it is already holding one. m Eventually, all processes give up but one, and that one is the new coordinator. m The new coordinator announces its victory by sending all processes a message telling them that starting immediately it is the new coordinator.
11
Bully Algorithm r If a process that was previously down comes back: m It holds an election. If it happens to be the highest process currently running, it will win the election and take over the coordinator ’ s job. “ Biggest guy ” always wins and hence the name “ bully ” algorithm.
12
The Bully Algorithm (Example) r The bully election algorithm r Process 4 holds an election r Process 5 and 6 respond, telling 4 to stop r Now 5 and 6 each hold an election
13
The Bully Algorithm (Example) d) Process 6 tells 5 to stop e) Process 6 wins and tells everyone
14
Bully Algorithm Analysis r Best case m The node with second highest identifier detects failure m Total messages = N-2 One message for each of the other processes indicating the process with the second highest identifier is the new coordinator. r Worst case m The node with lowest identifier detects failure. This causes N-1 processes to initiate the election algorithm each sending messages to processes with higher identifiers. m Total messages = O(N 2 )
15
Bully Algorithm Discussion r How many processes are used to detect a coordinator failure? m As many as you want. You could have all other processes check out the coordinator. r It is impossible for two processes to be elected at the same time.
16
Ring Algorithm r Use a ring (processes are physically or logically ordered, so that each process knows who its successor is). r Algorithm m When a process notices that coordinator is not functioning: Builds an ELECTION message (containing its own process number) Sends the message to its successor (if successor is down, sender skips over it and goes to the next member along the ring, or the one after that, until a running process is located). At each step, sender adds its own process number to the list in the message.
17
Ring Algorithm r Algorithm (continued) m When the message gets back to the process that started it all: Process recognizes the message that contains its own process number Changes message type to COORDINATOR Circulates message once again to inform everyone else: Who the new coordinator is (list member with highest number); Who the members of the new ring are. When message has circulated once, it is removed. Even if two ELECTIONS started at once, everyone will pick same leader since node with highest identifier is picked.
18
Ring Algorithm Initiation: 1.Process 4 sends an ELECTION message to its successor (or next alive process) with its ID
19
Ring Algorithm Initiation: 2. Each process adds its own ID and forwards the ELECTION message
20
Ring Algorithm contd… Leader Election: 3. Message comes back to initiator, here the initiator is 4. 4. Initiator announces the winner by sending another message around the ring
21
Ring Algorithm Analysis At best 2(N-1 ) messages are passed One round for the ELECTION message One round for the COORDINATOR Assumes that only a single process starts an election. Multiple elections cause an increase in messages but no real harm done.
22
Summary r Synchronization between processes often requires that one process acts as a coordinator. r The coordinator is not fixed. r Election algorithms determine the coordinator.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.