当前位置:   article > 正文

zookeeper调试报KeeperErrorCode = Unimplemented异常

keepererrorcode = unimplemented

最近搭建zookeeper环境跑demo时候遇到一个小问题,记录如下

 源码如下

  1. public static void main(String[] args) throws Exception {
  2. // CuratorFramework curatorFramework= CuratorFrameworkFactory.newClient("")
  3. CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().
  4. connectString(ZookeeperConf.CONNECTION_STRS).sessionTimeoutMs(5000).
  5. retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
  6. //ExponentialBackoffRetry
  7. //RetryOneTime 仅仅只重试一次
  8. //RetryUntilElapsed
  9. //RetryNTimes
  10. curatorFramework.start(); //启动
  11. createData(curatorFramework);
  12. // updateData(curatorFramework);
  13. // deleteData(curatorFramework);
  14. //CRUD
  15. curatorFramework.create();
  16. // curatorFramework.setData(); //修改
  17. // curatorFramework.delete() ;// 删除
  18. // curatorFramework.getData(); //查询
  19. }
  20. private static void createData(CuratorFramework curatorFramework) throws Exception {
  21. System.out.println("开始创建节点 /data/program");
  22. curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).
  23. forPath("/data/program", "zookeeper—test".getBytes());
  24. }
  25. private static void updateData(CuratorFramework curatorFramework) throws Exception {
  26. curatorFramework.setData().forPath("/data/program", "up".getBytes());
  27. }
  28. private static void deleteData(CuratorFramework curatorFramework) throws Exception {
  29. Stat stat = new Stat();
  30. String value = new String(curatorFramework.getData().storingStatIn(stat).forPath("/data/program"));
  31. curatorFramework.delete().withVersion(stat.getVersion()).forPath("/data/program");
  32. }

执行后报错如下

Exception in thread "main" org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for /data/program
    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:1525)
    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:47)
    at com.iris.springboot_all.zookeeper.base.CuratorDemo.createData(CuratorDemo.java:38)
    at com.iris.springboot_all.zookeeper.base.CuratorDemo.main(CuratorDemo.java:25) 

 

通常这是zookeeper客户端和服务端版本不一致造成的,因zookeeper环境是之前大数据环境已经存在的直接共用。

所以首先检查pom文件及客户端版本

  1.     <!--zookeeper-->
  2.       <dependency>
  3.           <groupId>org.apache.curator</groupId>
  4.           <artifactId>curator-framework</artifactId>
  5.           <version>4.0.0</version>
  6.       </dependency>
  7.       <dependency>
  8.           <groupId>org.apache.curator</groupId>
  9.           <artifactId>curator-recipes</artifactId>
  10.           <version>4.0.0</version>
  11.       </dependency>

设备上版本为:3.4.10

自身pom.xml中的版本为 4.0.0 

 

方法一:修改pom.xml文件兼容3.4版本

Curator官网:curator4.0与zookeeper3.4.X有依赖冲突,需要exclude其zookeeper附属依赖,并重新引入zookeeper版本

修改后pom.xml为

  1. <!--zookeeper-->
  2. <dependency>
  3. <groupId>org.apache.curator</groupId>
  4. <artifactId>curator-framework</artifactId>
  5. <version>${curator-version}</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.apache.curator</groupId>
  9. <artifactId>curator-recipes</artifactId>
  10. <version>${curator-version}</version>
  11. <exclusions>
  12. <exclusion>
  13. <groupId>org.apache.zookeeper</groupId>
  14. <artifactId>zookeeper</artifactId>
  15. </exclusion>
  16. </exclusions>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.apache.zookeeper</groupId>
  20. <artifactId>zookeeper</artifactId>
  21. <version>3.4.10</version>
  22. </dependency>

再次执行后成功

     最新版本的curator有些特性在3.4.X版本中是不支持的,为了确保代码的正确,最好加入版本模式的判断,使用isZk34CompatibilityMode()方法进行判断即可。

方法二:按照官网说明把客户端的版本升级到3.5

     升级zookeeper集群即可,如果不太方便升级则采用方法一。

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

闽ICP备14008679号