我可以在Zookeeper中递归创建路径吗? [英] Can I recursively create a path in Zookeeper?

查看:85
本文介绍了我可以在Zookeeper中递归创建路径吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 ZooKeeper 放入一个项目中进行并发管理,对我来说,我尝试的第一件事很明显(使用zkpython绑定):

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])

我为自己的麻烦找回了 NoNodeException .

And I got back a NoNodeException for my trouble.

对此进行了反思并查看了文档(例如文档)之后,我一直无法找到一种方法来等效于 mkdir -p ,其中ZooKeeper将创建缺少的父级对我来说很重要.

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.

我错过了什么吗?还是不管我是否喜欢,我只是坚持为路径的每个部分发出单独的create()?

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?

推荐答案

您将不得不为路径的每个元素分别发出create().Zookeeper仅内置原子操作.以递归方式创建路径不再是原子操作.如果操作在创建一半路径元素后挂起,Zookeeper不知道您要做什么.我不知道,是否在python中已经有了Zookeeper帮助器库.Java(zkClient)中有一个可以让您通过多次调用create()来创建递归路径.

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.

这篇关于我可以在Zookeeper中递归创建路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆