在 ZooKeeper 中,有没有办法在不自己实现分布式锁的情况下原子地编写层次结构? [英] In ZooKeeper, is there a way to write a hierarchy atomically without implementing distributed locks yourself?
本文介绍了在 ZooKeeper 中,有没有办法在不自己实现分布式锁的情况下原子地编写层次结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我想把这棵树写给动物园管理员
<预><代码>.一种./\.乙丙./\.德在我创建节点 b 之后,但在我能够编写节点d"或e"之前,其他一些客户端可能会出现并删除它.
有没有办法可以原子地编写这个层次结构,或者可能锁定某个路径?
解决方案
您可以使用新的 multi() API
它完成所有操作或中止所有操作.
let's say I want to write out this tree to zookeeper
. a
. / \
. b c
. / \
. d e
some other client could come along and delete node b right after I create it but before I'm able to write node 'd' or 'e'.
Is there a way I can write this hierarchy atomically, or possibly lock a certain path?
解决方案
You can use the new multi() API
It completes all the operations or aborts them all.
这篇关于在 ZooKeeper 中,有没有办法在不自己实现分布式锁的情况下原子地编写层次结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文