c++ - ZooKeeper 中的持久节点和临时节点

标签 c++ apache-zookeeper

我想知道如何使用 C++ 客户端在 ZooKeeper 中创建持久节点。我从documentation知道, 有一个方法zoo_acreate。文档对这种方法说:

This method will create a node in ZooKeeper. A node can only be created if it does not already exists. The Create Flags affect the creation of nodes. If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the client session goes away. If the ZOO_SEQUENCE flag is set, a unique monotonically increasing sequence number is appended to the path name.

但是,不幸的是,几乎与 C++ 库一样,这个库完全缺乏合理的小示例来演示库方法的用法。例如,在这种情况下,文档页面是关于 zoo_acreate 方法的,但是一些看起来很糟糕的示例完全是关于其他东西的(它甚至没有提到 zoo_acreate 方法)。

所以,我的问题是如何设置这些标志 ZOO_EPHEMERALZOO_SEQUENCE。很高兴在一些小例子的背景下看到这一点。谢谢!

最佳答案

谷歌搜索“zoo_acreate ZOO_EPHEMERAL”给出了第七个结果:

string path = "/nodes/";
string value = "data";
int rc = zoo_acreate(zh, path.c_str(), value.c_str(), value.length(),
    &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL | ZOO_SEQUENCE, &czoo_created, &where);

来源:https://issues.apache.org/jira/browse/ZOOKEEPER-348

关于c++ - ZooKeeper 中的持久节点和临时节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32665881/

相关文章:

java - 来自单个java应用程序的zookeeper中使用sasl的多用户身份验证

通过 "new"的 C++ 内存泄漏示例

c++ - 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?

android - 我如何找到要为 android studio 下载的 cmake

apache-kafka - 如何在 kubernetes 上为 Kafka 多代理设置指定广告监听器并对外公开集群?

hadoop - 使用密码 ssh 的防护方法

c++ - C++ 中的正则表达式抛出错误 "Invalid special open parenthesis."

c++ - 迭代器删除 C++ 的自定义实现

java - Apache Spark : reduceByKey function stops Java-application

hadoop - 无法启动hbase.sh(引发错误)