Primitives of ZooKeeper

Learn to implement some example primitives of ZooKeeper using the clientAPI.

ZooKeeper helps clients to implement a set of primitives using the client API. ZooKeeper servers do not know about these powerful primitives because there isn’t any function for each of them. For the servers, these are just a set of functions from the client API sent by the client. Some of the common primitives are wait-free, which are group membership and configuration management. These primitives are either updated once or very often, and are mostly used for reading which makes it wait-free. Others, like rendezvous and locks, are based on waiting unless an event, such as a watch, are not triggered.

Configuration management

ZooKeeper allows the client to implement dynamic configuration by using the following steps:

  1. Create a znode zcz_c with 8090 as the port value.
newZnode = create("/config/port", 8090, EPHEMERAL)
  1. Each process is called with the full path of its zcz_c and gets its configuration from zcz_c, whose watch flag is set to true, using the command below.
getData("/config/port", true)
  1. The configurations are not updated too often, but when they are, using the command below, the process is notified to use the updated configuration that sets the watch flag to true.
setData("/config/port", value, version)

Watches help ensure that the process which has set the watch flag to true gets updated information. Any process that has set the watch flag to true on the zcz_c will be notified so that it can use the updated value before it tries to read zcz_c. The process will be notified only once for multiple changes in the zcz_c before the process reads zcz_c ...