zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for {root.path}

weixin_33978044發表於2017-10-04

方法論:認識問題、分析問題、解決問題。

1. 問題描述

Dubbo 應用使用 ZooKeeper 作為註冊中心,啟動時發生該異常。

ZooKeeper JAR及其 Curator 客戶端版本:

zookeeper-3.5.1-alpha
curator-framework-3.3.0
curator-client-3.3.0

ZooKeeper 伺服器版本:3.4.9

$ echo stat | nc localhost 2181
Zookeeper version: 3.4.9-1757313, built on 08/23/2016 06:50 GMT

2. 異常日誌

2017-10-03 20:06:48.485  INFO 62124 --- [           main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-10-03 20:06:48.498 ERROR 62124 --- [           main] o.s.boot.SpringApplication               : Application startup failed

java.lang.IllegalStateException: Failed to register ......
    ......
Caused by: com.alibaba.dubbo.rpc.RpcException: Failed to register
dubbo://192.168.1.2:20880/spring.guides.dubbo.service.DemoService?accepts=0&anyhost=true&application=spring-boot-rpc-soa-dubbo-provider&dubbo=2.5.5&generic=false&interface=spring.guides.dubbo.service.DemoService&methods=sayHello&pid=62124&retries=1&side=provider&threadpool=cached&threads=100&timeout=1000&timestamp=1507032406454
to zookeeper zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=spring-boot-rpc-soa-dubbo-provider&check=true&client=curator&dubbo=2.5.5&file=/Users/dannong/.dubbo/registry.cache&group=dubbo_develop&interface=com.alibaba.dubbo.registry.RegistryService&pid=62124&timestamp=1507032406438, cause: KeeperErrorCode = Unimplemented for /dubbo_develop
    at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.doRegister(ZookeeperRegistry.java:112) ~[dubbo-2.5.5.jar:2.5.5]
    at com.alibaba.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:136) ~[dubbo-2.5.5.jar:2.5.5]
    ... 27 common frames omitted
Caused by: java.lang.IllegalStateException: KeeperErrorCode = Unimplemented for /dubbo_develop
    at com.alibaba.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.createPersistent(CuratorZookeeperClient.java:59) ~[dubbo-2.5.5.jar:2.5.5]
    at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:44) ~[dubbo-2.5.5.jar:2.5.5]
    at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:39) ~[dubbo-2.5.5.jar:2.5.5]
    at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:39) ~[dubbo-2.5.5.jar:2.5.5]
    at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:39) ~[dubbo-2.5.5.jar:2.5.5]
    at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.doRegister(ZookeeperRegistry.java:110) ~[dubbo-2.5.5.jar:2.5.5]
    ... 28 common frames omitted
Caused by: org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for /dubbo_develop
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:103) ~[zookeeper-3.5.1-alpha.jar:3.5.1-alpha-1693007]
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) ~[zookeeper-3.5.1-alpha.jar:3.5.1-alpha-1693007]
    at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1297) ~[zookeeper-3.5.1-alpha.jar:3.5.1-alpha-1693007]
    at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1075) ~[curator-framework-3.3.0.jar:3.3.0]
    at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1058) ~[curator-framework-3.3.0.jar:3.3.0]
    at org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:67) ~[curator-client-3.3.0.jar:na]
    at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:100) ~[curator-client-3.3.0.jar:na]
    at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1055) ~[curator-framework-3.3.0.jar:3.3.0]
    at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:524) ~[curator-framework-3.3.0.jar:3.3.0]
    at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:514) ~[curator-framework-3.3.0.jar:3.3.0]
    at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:492) ~[curator-framework-3.3.0.jar:3.3.0]
    at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:44) ~[curator-framework-3.3.0.jar:3.3.0]
    at com.alibaba.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.createPersistent(CuratorZookeeperClient.java:56) ~[dubbo-2.5.5.jar:2.5.5]
    ... 33 common frames omitted

3. 問題分析

UnimplementedException 的描述是 Operation is unimplemented,即該操作未實現異常

最後的異常呼叫棧 ZooKeeper.create(ZooKeeper.java:1297) 方法的原始碼:

    /**
     * Create a node with the given path and returns the Stat of that node. The
     * node data will be the given data and node acl will be the given acl.
     */
    public String create(final String path, byte data[], List<ACL> acl,
            CreateMode createMode, Stat stat)
            throws KeeperException, InterruptedException {
        final String clientPath = path;
        PathUtils.validatePath(clientPath, createMode.isSequential());

        final String serverPath = prependChroot(clientPath);

        RequestHeader h = new RequestHeader();
        h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create2);
        CreateRequest request = new CreateRequest();
        Create2Response response = new Create2Response();
        request.setData(data);
        request.setFlags(createMode.toFlag());
        request.setPath(serverPath);
        if (acl != null && acl.size() == 0) {
            throw new KeeperException.InvalidACLException();
        }
        request.setAcl(acl);
        ReplyHeader r = cnxn.submitRequest(h, request, response, null);
        if (r.getErr() != 0) {
            throw KeeperException.create(KeeperException.Code.get(r.getErr()),
                    clientPath);
        }
        if (stat != null) {
            DataTree.copyStat(response.getStat(), stat);
        }
        if (cnxn.chrootPath == null) {
            return response.getPath();
        } else {
            return response.getPath().substring(cnxn.chrootPath.length());
        }
    }

ZooKeeper.create(ZooKeeper.java:1297) 方法看,是ZooKeeper建立節點(Dubbo註冊中心的根目錄節點,dubbo.registry.group=dubbo_develop)時發生了異常。

結合 zookeeper學習4之curator開源的zookeeper客戶端 - 夢の殤
對該問題的解答:

使用curator的版本必須匹配伺服器上安裝zookeeper的版本,本人使用的是zookeeper的最新穩定版3.4.9(最新不穩定版是3.5.X),
所以curator不能使用最新版本,否則建立節點時就會報
org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for /curator/test01 錯誤。
官方上有這段話:

Versions
The are currently two released versions of Curator, 2.x.x and 3.x.x:

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.

Apache Curator對ZooKeeper版本相容性/ZooKeeper Version Compatibility
的最新解釋:

ZooKeeper 3.5.x
    Curator 4.0 has a hard dependency on ZooKeeper 3.5.x
ZooKeeper 3.4.x
    Curator 4.0 supports ZooKeeper 3.4.x ensembles in a soft-compatibility mode.

可以確定,問題根源Curator的3.3.0版本和ZooKeeper的3.5.1-alpha版本不匹配ZooKeeper伺服器的3.4.9版本

4. 解決方案

  • 將 ZooKeeper JAR版本降到 zookeeper-3.4.9,與伺服器版本一樣
  • 將 Curator 版本升級到最新的 curator-recipes-4.0.0,或者降到2.x.x最新的 curator-recipes-2.12.0

祝玩得開心!ˇˍˇ
雲舒,2017.10.4,杭州