Bully algorithm
In distributed computing, the bully algorithm is a method for dynamically electing a coordinator or leader from a group of distributed computer processes. The process with the highest process ID number from amongst the non-failed processes is selected as the coordinator.
Assumptions
The algorithm assumes that:- the system is synchronous.
- processes may fail at any time, including during execution of the algorithm.
- a process fails by stopping and returns from failure by restarting.
- there is a failure detector which detects failed processes.
- message delivery between processes is reliable.
- each process knows its own process id and address, and that of every other process.
Algorithm
The algorithm uses the following message types:- Election Message: Sent to announce election.
- Answer Message: Responds to the Election message.
- Coordinator Message: Sent by winner of the election to announce victory.
- If has the highest process ID, it sends a Victory message to all other processes and becomes the new Coordinator. Otherwise, broadcasts an Election message to all other processes with higher process IDs than itself.
- If receives no Answer after sending an Election message, then it broadcasts a Victory message to all other processes and becomes the Coordinator.
- If receives an Answer from a process with a higher ID, it sends no further messages for this election and waits for a Victory message.
- If receives an Election message from another process with a lower ID it sends an Answer message back and if it has not already started an election, it starts the election process at the beginning, by sending an Election message to higher-numbered processes.
- If receives a Coordinator message, it treats the sender as the coordinator.
Analysis
Safety
The safety property expected of leader election protocols is that every non-faulty process either elects a process, or elects none at all. Note that all processes that elect a leader must decide on the same process as the leader. The Bully algorithm satisfies this property, and at no point in time is it possible for two processes in the group to havea conflicting view of who the leader is, except during an election. This is true because if it weren't, there are two processes and such that both sent the Coordinator message to the group. This means and must also have sent each other victory messages. But this cannot happen, since before sending the victory message, Election messages would have been exchanged between the two, and the process with a lower process ID among the two would never send out victory messages. We have a contradiction, and hence our initial assumption that there are two leaders in the system at any given time is false, and that shows that the bully algorithm is safe.