ZooKeeper Recipes and Apache Curator

I'm trying to figure out exactly what problems are being solved by Apache ZooKeeper ("ZK"), and perhaps their Recipe Page is the best place to start.

First, I make the following assumptions:

  • The ZooKeeper API (available in both Java and C) provides these 7 simple methods , which then allow you to create your own usage patterns, known as “ZK recipes”
  • Then you should use these ZK recipes to solve distributed programming problems yourself.
  • Or instead of creating your own ZK recipes, you can simply use the ones that come with Apache Curator
  • So, in any case, you use ZK recipes (again, homegrown or provided by the curator) to solve problems with distributed computing.

I believe Apache Kafka is an example of this, where Kafka uses ZK to create a distributed queue (which is one of the ZK recipes listed). Therefore, if my assumptions are correct, ZK provides these API methods, and the creators of Apache Kafka either used ZK directly, or used a curator to implement the ZK "Queue" recipe.

If any of my assumptions is wrong, start with a fix! Assuming I'm more or less on the go:

Looking at the list of ZK recipes, I see the following (non-exhaustive):

  • Barriers
  • Locks
  • Leader election

To evaluate these recipes and the solutions they offer, I must first evaluate the problem that they solve! I understand what blocking is from basic Java concurrency, but I just don’t see a use case where “distributed lock” will ever be needed. For the leading elections, all I can think of - as an option for using it in the first place - would be if you created the application that you wanted to send, with a built-in master / subordinate or primary / secondary. Perhaps in this case you would use ZK to implement your own Leadership Election recipe, or maybe just use the Leader Capture curator. As for the barriers, I do not see how they differ from Locks. Therefore, I ask:

  • Is my master / subordinate or primary / secondary problem the exact use case for the ZK Leader Election recipe?
  • What would be an example of distributed locking? What problems are solved?
  • The same goes for barriers: and what's the difference between locks and barriers?
+7
java apache-zookeeper curator
source share
1 answer
  • Yes. An example of your Zk leader selection recipe is the right one. In general, if the recipe already exists, why rewrite it?

Indication of Zookeeper documentation:

ZooKeeper is a centralized service for supporting configuration information, naming, providing distributed synchronization, and providing group services.

  • As for distributed locks, let's say you have a distributed system in which all configurations are stored in Zookeeper, and more than one entity is responsible for updating a specific configuration. In this case, you would like the configuration updates to be synchronous.

  • As for the barrier, I personally never used them - but with the lock you need to purchase a lock in order to actually do something on the node, the barrier that you wait until it is released, but you do not need to install it when it is free.

+5
source share

All Articles