java-CuratorTransaction KeeperErrorCode = NoNode
作者:互联网
我正在尝试使用Java的Apache Curator库中的事务将数据写入ZooKeeper.
这是我的代码:
private CuratorFramework client;
...
private void writeToZK() {
String nodePath = "/path/to/node";
client.inTransaction().create().forPath(nodePath).and().commit(); // problem
}
(我正在使用策展人v2.9.0)
这引发:
org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode
at org.apache.zookeeper.KeeperException.create(KeeperException.java:111)
at org.apache.zookeeper.ZooKeeper.multiInternal(ZooKeeper.java:949)
at org.apache.zookeeper.ZooKeeper.multi(ZooKeeper.java:915)
我进入ZooKeeper.multiInternal(),它得到了Zookeeper响应,其中包含
OpResult: err = -101, type = -1.
如果我将“ //问题”行替换为此行,它将起作用:
client.create().creatingParentsIfNeeded().forPath(nodePath); // runs with no problem
任何想法?
解决方法:
在Zookeeper中,每个节点都定义有路径.请查看文档:https://zookeeper.apache.org/doc/trunk/zookeeperOver.html
它们像标准文件系统一样组织.这意味着您不能创建>如果“ / path / to”不存在,则为“ / path / to / node”.
您提出的解决方案是正确的,因为如果节点的父级不存在,它将由zookeeper自动创建.
标签:apache-curator,apache-zookeeper,java 来源: https://codeday.me/bug/20191111/2023119.html