In ZooKeeper, is there a way to write a hierarchy atomically without implementing distributed locks yourself?

元气小坏坏 提交于 2020-01-14 12:19:50

问题


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?


回答1:


You can use the new multi() API

It completes all the operations or aborts them all.




回答2:


You can coordinate different clients by either electing a leader or maintaining locks You can read a nice description on Zookeeper's recipes on the Netflix curator docs (which is also a nice library to use if you want to do anything with zookeeper)



来源:https://stackoverflow.com/questions/9628545/in-zookeeper-is-there-a-way-to-write-a-hierarchy-atomically-without-implementin

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