Bully Algorithm
It follows all the assumptions discussed above in the Election Algorithm.
Let’s say there are 6 Processes P0, P1, P2, P3, P4, P5 written in ascending order of their Process ID (i.e.,0, 1,2,3,4,5).
The Bully Algorithm operates on the principle of higher priority.
Messages in Bully Algorithm
There can be three types of messages that processes exchange with each other in the bully algorithm:
1. Election message: Sent to announce election.
2. OK (Alive) message: Responds to the Election message.
3. Coordinator (Victory) message: Sent by winner of the election to announce the new coordinator.
Steps Involved in Bully Algorithm
Step 1: Suppose Process P2 sends a message to coordinator P5 and P5 doesn’t respond in a desired time T (possible reason could be crash, down, etc.)
Step 2: Then process P2 , sends an election message to all processes with Process ID greater than P2 (i.e. P3, P4 & P5) and awaits a response from the processes.
Step 3: If no one responds, P2 wins the election and become the coordinator.
Step 4: If any of the processes with Process ID higher than 2 responds with OK, P2’s job is done and this Process will take over.
Step 5: It then restarts and initiates an election message.
Step 6: Process P4 responds to P3 with an OK message to confirm its alive state and Process P4 figures out that process 5 has crashed, and the new process with the highest ID is process 4.
Step 7: The process that receives an election message sends a coordinator message if it is the Process with the highest ID (in this case it is P4).
Step 8: If a Process which was previously down (i.e. P5) comes back, it holds an election and if it has the highest Process Id then it will become the new coordinator and sends message to all other processes.
Bully Algorithm in Distributed System
Operating Systems play a critical role in managing and coordinating the activities of a computer system. In distributed systems, where multiple computers work together to achieve a common goal, the issue of node/process failure becomes a significant concern. To ensure the reliability and fault tolerance of a distributed system, leader election algorithms come to the rescue. In this article, we will discuss the leader election algorithm (Bully algorithm) and understand how it guarantees the election of a new coordinator when the current coordinator fails.