Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I recursively create a path in Zookeeper?

I'm pulling ZooKeeper into a project for some concurrency management, and the first thing I tried was something that, to me, was quite obvious (using the zkpython binding):

zh = zookeeper.init('localhost:2181')
zookeeper.create(zh, '/path/to/a/node', '', [ZOO_OPEN_ACL_UNSAFE])

And I got back a NoNodeException for my trouble.

After reflecting on this and reviewing the docs (such as they are), I've been unable to find a way to do the equivalent of a mkdir -p where ZooKeeper will create the missing parent nodes for me.

Am I missing anything, or am I just stuck issuing separate create()s for each part of a path whether I like it or not?

like image 422
Nicholas Knight Avatar asked Dec 23 '22 00:12

Nicholas Knight


1 Answers

You're stuck to issue separate create()s for each element of the path. Zookeeper has only atomic operations build in. Creating a path recursively is not an atomic operation anymore. Zookeeper could not know, what you want it to do, if the operation hangs after creating half of the path elements. I don't know, if there's already a Zookeeper helper library in python. There is one in java (zkClient) that will let you create recursive paths by calling create() multiple times.

like image 136
Thomas Koch Avatar answered Dec 26 '22 10:12

Thomas Koch