zookeeper实现分布式锁不是原子操作?

新手上路,请多包涵

为了避免羊群效应,在实现的时候后者只watch前一个节点,
那么在watch之前如果前一个节点delete了,这时候不是会一直wait吗?

阅读 2.5k
1 个回答

你说的对。

因为 ZK 锁有羊群效应问题本来就是中文互联网上自己瞎扯淡的产物,英文界你都找不着相关的讨论。

事实上 ZK 自己的官方文档上专门提到了这个问题:https://zookeeper.apache.org/...

可以看 Shared Locks 小节的 Notes 备注部分:

It might appear that this recipe creates a herd effect: when there is a large group of clients waiting for a read lock, and all getting notified more or less simultaneously when the "write-" node with the lowest sequence number is deleted. In fact. that's valid behavior: as all those waiting reader clients should be released since they have the lock. The herd effect refers to releasing a "herd" when in fact only a single or a small number of machines can proceed.

注意加粗的部分。大意就是“看起来会产生羊群效应,实际上这是合理的做法。”

说实话,我真没见过哪个 ZK 集群因为这个导致所谓的羊群效应,最后崩了的 ———— 同时有大量的锁等待,其本身造成的性能问题比这个要严重的多了;而你所谓的羊群效应,其前提就是得有大量锁等待。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进