当前位置:   article > 正文

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

org.apache.zookeeper.keeperexception$unimplementedexception: keepererrorcode

前言今天在调用很久写的zk相关代码 创建节点突然创建异常。。。异常信息如下

org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for /test
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:106)
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:54)
    at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1637)
    at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1189)
    at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1166)
    at org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:64)
    at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:100)
    at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1163)
    at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:603)
    at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:593)
    at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:571)
    at org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:459)
    at org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:389)
    at com.google.zookeeper.lock.DistributeLock.main(DistributeLock.java:29)

简单地创建代码如下

//初始化
CuratorFramework framework =
      CuratorFrameworkFactory.builder().connectString("zk服务地址")
            .connectionTimeoutMs(5000)
            .retryPolicy(new ExponentialBackoffRetry(3000, 3))
            .build();
framework.start();
try {
   String s = framework.create().creatingParentsIfNeeded().forPath("/test");
   System.out.println("s=="+s);
} catch (Exception e) {
   e.printStackTrace();
}

看到错误就不淡定了。。。 直接度娘一发 发现是curator 和 zookeper 版本兼容问题

看下了下官方给的版本对比文档 官方文档链接 

ZooKeeper 3.5.x

  • Curator 4.0 has a hard dependency on ZooKeeper 3.5.x
  • If you are using ZooKeeper 3.5.x there's nothing additional to do - just use Curator 4.0

zookeeper3.5.x 是 curator4.0 很支持 不要任何操作 

ZooKeeper 3.4.x

Curator 4.0 supports ZooKeeper 3.4.x ensembles in a soft-compatibility mode. To use this mode you must exclude ZooKeeper when adding Curator to your dependency management tool.

curator4.0 对zk 3.4.x 属于软兼容需要配置 

<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-recipes</artifactId>
    <version>4.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </exclusion>
    </exclusions>
</dependency>

解决办法

第一次尝试先将 curator-recipes中zk依赖排除  zk版本使用3.5.5 服务器zk版本3.4.12  curator 4.0.0 不好使 

<!--zookeeper-->
<dependency>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper</artifactId>
    <version>3.5.5</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!--curator-->
<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-framework</artifactId>
    <version>4.0.0</version>
</dependency>
<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-recipes</artifactId>
    <version>4.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </exclusion>
    </exclusions>
</dependency>

第二次尝试将 curator-recipes中zk依赖排除 zk版本使用和服务器上一一致的3.4.12 服务器上zk版本3.4.12 curator 4.0.0 已经解决

<!--zookeeper-->
<dependency>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper</artifactId>
    <version>3.4.12</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!--curator-->
<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-framework</artifactId>
    <version>4.0.0</version>
</dependency>
<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-recipes</artifactId>
    <version>4.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </exclusion>
    </exclusions>
</dependency>

第三种curator-recipes中zk依赖排除 zk版本使用和服务器上一一致的3.4.12 服务器上zk版本3.4.12 curator 版本进行降级 使用2.12.0  已经解决 

<!--zookeeper-->
<dependency>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper</artifactId>
    <version>3.4.12</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!--curator-->
<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-framework</artifactId>
    <version>2.12.0</version>
</dependency>
<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-recipes</artifactId>
    <version>2.12.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </exclusion>
    </exclusions>
</dependency>

最终解决方法 1.服务器上版本3.5.X  zk也使用3.5.5  curator 4.0.0 没问题 

2.服务器上版本3.4.x  zk版本和服务器zk版本一致  curator 4.0.0 依赖中排除zk依赖 

3.服务器上版本3.4.x zk版本和服务器zk版本一致 curator使用2.x.x 也可以解决 具体需要自己尝试版本 (不推荐使用,可能导致兼容问题 如之前已经使用的4.0.0的东西 2.xx的 无法满足)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/386357
推荐阅读
相关标签
  

闽ICP备14008679号