Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZooKeeper - adding peers dynamically?

I'm new to ZooKeeper. This is what I need.

I've a network of peers.

  1. At t=t_1 -> [peer-1 (Leader), peer-2] peer-1 is the master and all clients connect to this node.

  2. At t=t_2 -> [peer-1 (Leader), peer-2, peer-3] At some later time peer-3 joins the group. Is it possible to add peer-3 to the list of zookeeper servers "dynamically" ( i.e., without restarting ZooKeeper on peer-1 ) ?

  3. At t=t_3 -> [peer-3 (Leader), peer-4] After a while both peer-1 and peer-2 leave the group (e.g., die or are switched off.) Assuming that there is a way to dynamically add peer-3 and peer-4 to the group peer-3 becomes the leader and all client requests are send to peer-3.

Are there any other options that I can use apart from using ZooKeeper to do something like this.

thanks.

like image 264
Soumya Simanta Avatar asked Jul 07 '12 12:07

Soumya Simanta


People also ask

How does a ZooKeeper quorum work?

By default, ZooKeeper uses majority quorums, which means that every voting that happens in one of these protocols requires a majority to vote on. One example is acknowledging a leader proposal: the leader can only commit once it receives an acknowledgement from a quorum of servers.

How do I set up a quorum on ZooKeeper?

Create a file named as myid under the Zookeeper data directory in each Zookeeper server. This file should contain the server number X as an entry in it. server_name is the hostname of the node where the Zookeeper service is started. port1 , ZooKeeper server uses this port to connect followers to the leader.

What is MYID file in ZooKeeper?

Each ZooKeeper server has a unique id. This id is used in two places: the myid file and the configuration file. The myid file identifies the server that corresponds to the given data directory. The configuration file lists the contact information for each server identified by its server id.


1 Answers

At the moment, you can't dynamically change the configuration of a zookeeper cluster without restarting. There is an open issue to fix this, ZOOKEEPER-107. The paper describing the cluster membership algorithm is quite interesting, and can be found here.

You can change the configuration of the cluster by restarting server nodes 1 at a time. For example, if you cluster has servers A,B,C, and you want to replace server C with D, then you can do something like,

  • Bring down C
  • Bring up D, it's peer list is A,B,D
  • Take down B
  • Change B's peer list to A,B,D
  • Bring up B
  • Take down A Change A's peer list to A,B,D
  • Bring up A
  • Change the client configuration of all clients to point to A,B,D

At t=t_1, you have a cluster with 2 zookeeper nodes. This is quite brittle, as if either node goes down, you will not be able to establish quorum (floor(N / 2) + 1), and the cluster will be unavailable. Generally zookeeper clusters are odd numbers.

I'm not sure what you are trying to do when you say,

peer-3 becomes the leader and all client requests are send to peer-3.

You can't specify which node in a zookeeper cluster is the leader, the nodes themselves will elect their leader, and leadership will change as nodes go up and down. As well, clients typically don't always connect to the leader, but clients are given list of machines in the cluster, and connect randomly to one, reconnecting if the server they are connected to goes down. You can set the leaderServes option to specify that the leader does NOT server client connections.

like image 191
sbridges Avatar answered Sep 28 '22 00:09

sbridges