Jack
Jack

Reputation: 5880

how does zookeeper do when the master down

The title may look like silly, but I really can't understand the zookeeper failover policy when the master is down although I read a lot of docs about Zookeeper. My question as following:

  1. If I have three nodes zookeeper, then the master is down, so how do the remaining two nodes elect the new master(right now it's an even number nodes, how do they vote by majority).
  2. If one of the remaining two nodes down, then the last one will become master and continually serve the service, right please?
  3. If even number zookeeper nodes can run very well, why I have to setup odd number of Zookeeper nodes?

Upvotes: 3

Views: 1316

Answers (1)

Petter
Petter

Reputation: 1337

  1. I think you're misunderstanding what majority we're talking about here. The majority that is important is not among the remaining nodes, but among the entire cluster. So what you need to ask is: 'Can 2 nodes form a majority among 3 nodes'? And the answer is that they can, and therefore they can elect a leader. (I do not know exactly how Zookeeper solves leader voting, but the important thing is that the goals for the nodes is not to become leader but to decide on one leader. And to convince you it's possible here's a vary simple (but slow) way of solving it: The nodes vote at random, if they have formed a majority they elect that leader else they vote again.)

  2. No, this will not be the case. Since the cluster is still configured around being a 3 node cluster the one node that is left can not form a majority and can therefor not elect a leader. This is one of the reasons why a 2 node cluster can actually be worse then a 1 node one, if one of the nodes go down the cluster stops.

  3. You do not have to, it is just recommended. And a good reason to have a odd number is that if you get a net-split that divides your cluster into two parts of same size no side can elect a leader. (This is not possible if you run a odd number of nodes.) You can also see it as a buy-one-get-one-free type of deal, if you have 4 nodes only 1 can go down, but if you get 5 nodes it's okay for 2 to go down. But if you get 6 nodes it's still just 2 nodes that can go down without the cluster going down.

Upvotes: 5

Related Questions