问题
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