ZooKeeper

ZooKeeper is a high-performance coordination service for distributed applications. It exposes common services - such as naming, configuration management, synchronization, and group services - in a simple interface so you don't have to write them from scratch. You can use it off-the-shelf to implement consensus, group management, leader election, and presence protocols. And you can build on it for your own, specific needs.

zookeeper 3.4 documentation

Locks 分布式锁

lock操作过程

  1. Call create( ) with a pathname of "locknode/lock-" and the sequence and ephemeral flags set.

  2. Call getChildren( ) on the lock node without setting the watch flag (this is important to avoid the herd effect).

  3. If the pathname created in step 1 has the lowest sequence number suffix, the client has the lock and the client exits the protocol.

  4. The client calls exists( ) with the watch flag set on the path in the lock directory with the next lowest sequence number.

  5. if exists( ) returns false, go to step 2. Otherwise, wait for a notification for the pathname from the previous step before going to step 2.

总结一下
客户端去创建一个根节点 如上的"locknode/lock-"节点, 如果根节点存在,则在根节点下创建自增长瞬时节点, 取出根节点下的所有节点,取出最小的序号作为锁的持有者,此时如果自己的节点id与此序号相等则获得锁,反之,watch住序号比自己靠前的一个锁的释放操作.

unlock操作过程

The unlock protocol is very simple: clients wishing to release a lock simply delete the node they created in step 1.

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,206评论 0 10
  • ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于...
    rthsfjhtrj阅读 3,627评论 0 1
  • 最近一直在学习如何阅读,不管是快速阅读,还是主题阅读,亦或是深度阅读,通过最近的学习,多少都了解了些。一直觉得自己...
    希亚阅读 1,661评论 3 0
  • 第二天一早,宁昊眼睛一睁开就开始给赵政打电话。 赵政接通电话听清楚他的意思后直接说,“珠宝玉器这一块的业务,我已经...
    可可豆子阅读 2,383评论 0 5
  • 楼亭樵客阅读 748评论 0 0

友情链接更多精彩内容