When using Apache Curator, why does creating a zNode cause NoNodeException

Tags: , ,



I am trying to create a “directory” in Zookeeper like this:

curatorFramework = CuratorFrameworkFactory.newClient(
    "ip-111-11-111-1.us-west-2.compute.internal/111.11.111.1:2181",
    zkInfo.getSessionTimeoutMs(),
    zkInfo.getConnectionTimeoutMs(),
    new RetryNTimes(zkInfo.getRetryAttempts(), 
    zkInfo.getRetryIntervalMs())
);
curatorFramework.start();

byte[] byteArray = new byte[1];
byteArray[0] = (byte) 7;

curatorFramework.create()
    .withMode(CreateMode.PERSISTENT)
    .withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE)
    .forPath("/my_node", byteArray); 

Perplexingly, it is giving me a “NoNodeException” on the very node I’m trying to create.

Caused by: org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /my_node
        at org.apache.zookeeper.KeeperException.create(KeeperException.java:111) ~[stormjar.jar:?]
        at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) ~[stormjar.jar:?]
        at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:783) ~[stormjar.jar:?]
        at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1176) ~[stormjar.jar:?]
        at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1156) ~[stormjar.jar:?]
        at org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:64) ~[stormjar.jar:?]
        at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:100) ~[stormjar.jar:?]
        at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1153) ~[stormjar.jar:?]
        at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:607) ~[stormjar.jar:?]
        at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:597) ~[stormjar.jar:?]
        at org.apache.curator.framework.imps.CreateBuilderImpl$3.forPath(CreateBuilderImpl.java:362) ~[stormjar.jar:?]
        at org.apache.curator.framework.imps.CreateBuilderImpl$3.forPath(CreateBuilderImpl.java:310) ~[stormjar.jar:?]

Note that I am able to connect to Zookeeper:

Socket connection established to ip-111-11-111-1.us-west-2.compute.internal/111.11.111.1:2181, initiating session
Session establishment complete on server ip-111-11-111-1.us-west-2.compute.internal/111.11.111.1:2181, sessionid = 0x100000363b13354, negotiated timeout = 20000        

Please note that the Zookeeper server is on a remote machine and the ip (“111.11.111.1”) has been changed in this post.

Answer

Seems related to ACLs, just to be sure, you could manually create it.

Locate your local zk binaries (doesn’t need to be on the remote host) and launch the client (zkCli) pointing at your server. Once connected, create the new znode:

bin/zkCli.sh -server 111.11.111.1:2181

[zkshell:x] create /my_node
>>Created /mynode

The shell should output the last sentence in order to guarantee the node has been created. Once done, launch again the Curator process.

Take a look here for more detailed info about the zk client.



Source: stackoverflow