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

查看:37
本文介绍了我可以在 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天全站免登陆