views:

76

answers:

1

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?

+2  A: 

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.

Thomas Koch
So far the only Python interface for Zookeeper I've found is the one in the Zookeeper tree (which is just basic bindings to the core API), so I guess I'll be writing my own convenience methods. :) Thanks!
Nicholas Knight