Apache Curator Unimplemented Errors When Trying to Create zNodes
Asked Answered
K

6

23

I'm attempting to use Apache Curator with a dockerized zookeeper instance and no matter how I attempt to connect I always end up with a

org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for...

error. I've tried making sense of the documentation but I'm not getting anywhere. I've logged into the zookeeper CLI and ensured the port number is correct thusly:

snerd@powerglove:~$ docker ps CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS   NAMES 31f1093495ba        compose_zookeeper   "/opt/zookeeper/bin/   3 weeks ago         Up About a minute   0.0.0.0:32770->2181/tcp,
0.0.0.0:32769->2888/tcp, 0.0.0.0:32768->3888/tcp   zookeeper

here is the code I'm trying to use:

public class App {
    public static void main( String[] args ) {
        CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
        client.start();

            try {
                client.create().forPath("/larry-smells/foop", "tuna?".getBytes());
            } catch (Exception e) {
                System.out.println(e.toString());
            }

    }
}

As far as I can tell from the Curator getting started page, this should work. What am I missing?

edit1 just figured out that I'm able to pull data out of the zookeeper ensemble thusly:

System.out.println(new String(curatorFramework.getData().forPath("/larry-smells"))); 

but the create command is still blowing up.

edit2

stacktrace of the error:

org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for /larry-smells/foop at org.apache.zookeeper.KeeperException.create(KeeperException.java:103) at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1297) at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1040) at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1023) at org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:67) at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:99) at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1020) at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:501) at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:491) at org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:367) at org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:309) at com.mycompany.app.App.main(App.java:35)

Klingensmith answered 1/3, 2016 at 22:8 Comment(0)
P
46

Edit: Apparently this error can occur if you're using the wrong combination of Curator in combination with Zookeeper. From curator.apache.org :

Curator 2.x.x - compatible with both ZooKeeper 3.4.x and ZooKeeper 3.5.x

Curator 3.x.x - compatible only with ZooKeeper 3.5.x and includes support for new features such as dynamic reconfiguration, etc.


It's hard to pinpoint your problem with only that error-code and not a stack trace, but some improvements I would suggest to make your application more stable is:

public class App {
    public static void main( String[] args ) {
        CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
        client.start();

        try {
            //make sure you're connected to zookeeper.
            client.blockUntilConnected();

            //Make sure the parents are created.
            client.create().creatingParentsIfNeeded().forPath("/larry-smells/foop", "tuna?".getBytes());
        } catch (Exception e) {
            System.out.println(e.toString());
            }

    }
}
Pickerelweed answered 2/3, 2016 at 17:20 Comment(2)
made your suggested change and got same result. I also added the stack trace to the text of the question.Klingensmith
doots -- turns out I'm a dink. the issue was plainly stated in a warning at the bottom of the curator homepage regarding using only v2 with zookeeper versions < 3.5.x. Basically I failed to RTFM. If you put that in the form of an answer I'll accept it so at least you get some cred for your trouble :-)Klingensmith
A
3

I also faced a similar exception, I used the below dependencies which are compatible and helps me to resolve the exception.

    <dependency>
        <groupId>org.apache.zookeeper</groupId>
        <artifactId>zookeeper</artifactId>
        <version>3.4.6</version>
    </dependency>

    <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-framework</artifactId>
        <version>4.0.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-x-discovery</artifactId>
        <version>4.0.1</version>
    </dependency>
Attainment answered 9/10, 2018 at 10:27 Comment(0)
K
2

I had the same problem.

I tried to use inTransaction () as explained here: http://www.programcreek.com/java-api-examples/index.php?api=org.apache.curator.framework.CuratorFramework on exercise 6 and seems to work.

client.inTransaction ().create().forPath("/larry-smells/foop", "tuna?".getBytes()).and ().commit ();
Kelley answered 10/8, 2017 at 21:41 Comment(1)
Thank you, this is very useful, especially the inTransaction()Teagan
B
1

The issue is caused because of incompatibility.

To fix this, you need to change the version like it's explained here:
https://curator.apache.org/zk-compatibility.html

If this doesn't work, just look for the newest curator version which depends on a 3.4.x zookeeper version (currently '2.12.0').

Bratton answered 9/11, 2017 at 5:23 Comment(0)
R
0

@Massimo Da Ros solution works, but in new version Curator 4.0.0 inTransaction is deprecated, it's recommented use transaction method like below:

CuratorOp op = client.transactionOp().create()
            .withMode(CreateMode.PERSISTENT)
            .withACL(Ids.OPEN_ACL_UNSAFE)
            .forPath("/test", "Data".getBytes());
result = client.transaction().forOperations(op).get(0).toString();
Riffraff answered 25/1, 2018 at 3:8 Comment(0)
R
0

I faced similiar problem. I was using spring-cloud-starter-zookeeper-discovery which by itself of course has compatible zookeeper and curator versions.

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
    </dependency>

I checked the dependency tree and spring-cloud-starter-zookeeper-discovery Version 3.1.1. was using zookeeper Version 3.6.0

The problem was, in my docker-compose.yml I was using zookeeper Version 3.4!

So make sure your docker-compose.yml zookeeper version fits your maven zookeeper version.

version: "3.8"
services:
  zookeeper:
    container_name: zookeeper
    image: zookeeper:3.6  <----------------- zookeeper version
    ports:
      - "2181:2181"

Revenuer answered 9/3, 2022 at 1:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.