方法论:认识问题、分析问题、解决问题。
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×tamp=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×tamp=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,杭州