Election Algorithms: Bully Algorithm
Election Algorithms: Bully Algorithm
Election algorithms
Many distributed algorithms require the election of a special coordinator process; one that has a special role, or
initiates something, or monitors something. Often it doesn't matter who the special process is, but one and only
one must be elected, and it can't be known in advance who it will be. On a low-level you can think about the
monitor in a token ring as an example.
The assumptions of these algorithms is that every process can be uniquely identfied (by IP address, for
example), and that each process can find out the id of the other processes. What the processes don't know is
which processes are up and which are down at any given point in time.
Bully algorithm
Garcia-Molina, 1982. The process with the highest identity always becomes the coordinator.
When a process P sees that the coordinator is no longer responding to requests it initiates an election by sending
ELECTION messages to all processes whose id is higher than its own. If no one responds to the messages then P
is the new coordinator. If one of the higher-ups responds, it takes over and P doesn't have to worry anymore.
When a process receives an ELECTION message it sends a response back saying OK. It then holds it's own
election (unless it is already holding one). Eventually there is only one process that has not given up and that is
the new coordinator. It is also the one with the highest number currently running. When the election is done the
new coordinator sends a COORDINATOR message to everyone informing them of the change.
If a process which was down comes back up, it immediately holds an election. If this process had previously
been the coordinator it will take this role back from whoever is doing it currently (hence the name of the
algorithm).
Ring algorithm
Assumes that processes are logically ordered in some fashion, and that each process knows the order and who is
coordinator. No token is involved. When a process notices that the coordinator is not responding it sends an
ELECTION message with its own id to its downstream neighbor. If that neighbor doesn't respond it sends it to
its neighbor's neighbor, etc. Each station that receives the ELECTION message adds its own id to the list. When
the message circulates back to the originator it selects the highest id in the list and sends a COORDINATOR
message announcing the new coordinator. This message circulates once and is removed by the originator.
If two elections are held simultaneously (say because two different processes notice simultaneously that the
coordinator is dead) then each comes up with the same list and elects the same coordinator. Some time is wasted,
but nothing is really hurt by this.