Learning Zookeeper - Help me with example

北城余情 提交于 2019-12-25 16:49:04

问题


I'm trying to wrap my head around Zookeeper and what it does. To this point, my experience with Zookeeper has been through other libraries that require Zookeeper (Solr and Kafka) and so my basic understand is the very vague "you better use Zookeeper to keep your configuration straight".

So help me think through a simple example problem. Let's say that I build my own service that does "stuff". There are two things that I want to protect:

  1. I want to have as little downtime as possible (gotta keep doing stuff).
  2. I can not have more than one server doing stuff because bad things would happen.

So, how would I set this up in Zookeeper? Is Zookeeper responsible for starting another stuff server if one goes down? Or do I subscribe to a Zookeeper "stuff doer status" callback? If I erroneously start up two stuff servers, how does Zookeeper help me keep bad things from happening?


回答1:


Zookeeper is a distributed lock manager. These systems provide features like coordinator election (aka "master election" or "leader election") for a distributed system, as well as provide a consistent, distributed access to small amounts of critical information which is frequently used for configuration (i.e., don't treat it like a database or a general file system).

Note that Zookeeper does not manage your service, but you can use Zookeeper to keep a hot standby (or several) such that in case of one master failing, another one will take over, so you would run N replicas of your servers, such that one of the working instances can take over immediately if the current leader goes down or becomes unavailable for any reason.

Using master election, you can choose to have two (or more) servers, but only one of them will be able to take the master lock, so only that one will be able to take action. As soon as it goes away, it will lose its claim to the lock, and your hot standby will pick up the lock and start doing work that you need it to do. Look at Zookeeper recipes for code samples. However, properly handing off work, checkpointing, and general service resilience is still up to you to design and implement.

That said, Zookeeper and similar systems provide a solid foundation to enable you to build robust distributed systems.

Other systems similar to Zookeeper include (alphabetically):

  • Chubby
  • doozerd
  • etcd

Several of these have detailed comparisons written up on their respective websites to show how they differ from the others in the list.



来源:https://stackoverflow.com/questions/23940464/learning-zookeeper-help-me-with-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!