Sunday 12 July 2015

Why do we need odd number of voting disks ?


The reason for the odd number of voting disks is to solve the "split-brain" problem. The split-brain problem occurs when the cluster interconnect goes down and each node cannot obtain a heartbeat from the other nodes. At this time, each node in the cluster thinks they are the only one alive and they think they should become the "master node". There can be only one master node. Each half thinks they are the brains of the operation, which we cannot allow.
So how do we resolve this? 
We set up a race. Each candidate node wants to be the master so we put it up to a vote. Whichever contestant gets the most votes wins. So node 1 contacts the first voting disk and says "I am here first so I am the master!". Simultaneously, node 2 contacts the second voting disk and says  "I am here first so I am the master!". They both can't be right. If there were an even number of voting disks, then it is possible that each candidate node could come up with exactly half the number of total votes and we would have a tie, which must be resolved. Now the real race begins. The two nodes run to the third and final voting disk. The node that gets there first now has 2 votes to 1, wins the election, and becomes the master node in the cluster.

1 comment: