KeeperException$NoNodeException: KeeperErrorCode =
java连接zookeeper创建节点报错:Exceptioninthread"main"org.apache.zookeeper.KeeperException$NoNodeException:KeeperErrorCode=NoNodefor/node1/child1_1atorg.apache.zookeeper.KeeperException.create(KeeperException.
·
java连接zookeeper创建节点报错:
Exception in thread "main" org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode
for /node1/child1_1
at org.apache.zookeeper.KeeperException.create(KeeperException.java:111)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:783)
at ZookeeperUtils.createChildNode(ZookeeperUtils.java:55)
at ZookeeperUtils.main(ZookeeperUtils.java:18)
原因是要创建的节点为child1_1,但是此时其父节点/node1还不存在,因此会报错。使用java通过官方提供的zookeeper-3.4.8.jar来连接zookeeper时,要创建节点首先要确保其父节点已经被创建。
/**
* 在已有节点上创建子节点,如果父节点没有那么就不能创建
*/
public void createChildNode() throws Exception{
ZooKeeper zk=getInstance();
zk.create("/node1/child1_1","child1_1_data".getBytes(),
ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
zk.close();
}
更多推荐
已为社区贡献1条内容
所有评论(0)