我只是使用org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ServerConfig)
方法启动了zookeeper服务器(3.4.6),然后尝试将其关闭。在关机期间,我得到了这个:
11:43:11,176 WARN {main} [org.apache.zookeeper.jmx.MBeanRegistry] Failed to unregister MBean InMemoryDataTree
11:43:11,176 WARN {main} [org.apache.zookeeper.jmx.MBeanRegistry] Error during unregister
javax.management.InstanceNotFoundException: org.apache.ZooKeeperService:name0=StandaloneServer_port-1,name1=InMemoryDataTree
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.exclusiveUnregisterMBean(DefaultMBeanServerInterceptor.java:427)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.unregisterMBean(DefaultMBeanServerInterceptor.java:415)
at com.sun.jmx.mbeanserver.JmxMBeanServer.unregisterMBean(JmxMBeanServer.java:546)
at org.apache.zookeeper.jmx.MBeanRegistry.unregister(MBeanRegistry.java:115)
at org.apache.zookeeper.jmx.MBeanRegistry.unregister(MBeanRegistry.java:132)
at org.apache.zookeeper.server.ZooKeeperServer.unregisterJMX(ZooKeeperServer.java:465)
at org.apache.zookeeper.server.ZooKeeperServer.shutdown(ZooKeeperServer.java:458)
at org.apache.zookeeper.server.NIOServerCnxnFactory.shutdown(NIOServerCnxnFactory.java:271)
at org.apache.zookeeper.server.ZooKeeperServerMain.shutdown(ZooKeeperServerMain.java:132)
...
遗憾的是,我不知道取消注册MBean InMemoryDataTree 的错误是什么意思。除了某些项目构建的日志之外,我没有找到任何搜索引擎。我可以阅读代码,但显然需要很多时间来理解它。
我是否必须在启动过程中更改某些内容以摆脱这种情况,或者这是否完全正常?
答案 0 :(得分:1)
日志表明它是一个警告,通过查看源和注释,可以在很大程度上被忽略。根据我的经验,我不记得看到那些特定的消息,但一直遇到运行时异常/错误,使后续的单元测试无法运行,导致我的gradle构建退出测试任务而不生成报告。
我不知道你是怎么试图关闭ZookeeperServerMain的,但我的工作是扩展ZookeeperServerMain以便我可以访问它的受保护的关闭方法。
public class MyZookeeperServerMain extends ZookeeperServerMain{
...
public void openZoo() {
/**/
Properties startupProperties = createProperties(DEFAULT_LOG_DIR, 2181);
QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
try {
quorumConfiguration.parseProperties(startupProperties);
} catch (Exception e) {
throw new RuntimeException(e);
}
zooKeeperServer = new MyZookeeperServerMain();
final ServerConfig configuration = new ServerConfig();
configuration.readFrom(quorumConfiguration);
zooEntrance = new Thread() {
public void run() {
try {
zooKeeperServer.runFromConfig(configuration);
}
catch (IOException e) {
LOG.error("ZooKeeper Failed", e);
}
catch(Exception ie)
{
LOG.debug("shutting down zookeeper", ie);
}
catch(Error e)
{
System.out.println("error stopping zooKeeper: " + e);
}
}
};
zooEntrance.start();
}
public void closeZoo() {
zooKeeperServer.shutdown();
}
}