xkcoding / spring-boot-demo

🚀一个用来深入学习并实战 Spring Boot 的项目。
https://parg.co/UZM
MIT License
33.17k stars 10.89k forks source link

Zookeeper 分布式锁 启动时报错[BUG] #199

Closed StephenEvenson closed 3 years ago

StephenEvenson commented 3 years ago

描述问题

连接 ZooKeeper 集群时失败 错误日志如下:

2021-04-06 08:52:39.568 ERROR 93321 --- [ain-EventThread] o.a.c.f.imps.CuratorFrameworkImpl        : Background exception was not retry-able or retry gave up

java.lang.NullPointerException: null
    at org.apache.curator.utils.Compatibility.getHostAddress(Compatibility.java:116) ~[curator-client-5.1.0.jar:na]
    at org.apache.curator.framework.imps.EnsembleTracker.configToConnectionString(EnsembleTracker.java:185) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.EnsembleTracker.processConfigData(EnsembleTracker.java:206) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.EnsembleTracker.access$300(EnsembleTracker.java:50) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.EnsembleTracker$2.processResult(EnsembleTracker.java:150) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.CuratorFrameworkImpl.sendToBackgroundCallback(CuratorFrameworkImpl.java:892) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.CuratorFrameworkImpl.processBackgroundOperation(CuratorFrameworkImpl.java:649) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.WatcherRemovalFacade.processBackgroundOperation(WatcherRemovalFacade.java:152) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.GetConfigBuilderImpl$2.processResult(GetConfigBuilderImpl.java:222) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:630) ~[zookeeper-3.6.0.jar:3.6.0]
    at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:551) ~[zookeeper-3.6.0.jar:3.6.0]

2021-04-06 08:52:39.568  INFO 93321 --- [ain-EventThread] o.a.c.framework.imps.EnsembleTracker     : New config event received: {server.2=zoo2:2888:3888:participant;0.0.0.0:2181, server.1=0.0.0.0:2888:3888:participant;0.0.0.0:2181, server.3=zoo3:2888:3888:participant;0.0.0.0:2181, version=0}
2021-04-06 08:52:39.569 ERROR 93321 --- [ain-EventThread] o.a.c.f.imps.CuratorFrameworkImpl        : Background exception was not retry-able or retry gave up

java.lang.NullPointerException: null
    at org.apache.curator.utils.Compatibility.getHostAddress(Compatibility.java:116) ~[curator-client-5.1.0.jar:na]
    at org.apache.curator.framework.imps.EnsembleTracker.configToConnectionString(EnsembleTracker.java:185) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.EnsembleTracker.processConfigData(EnsembleTracker.java:206) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.EnsembleTracker.access$300(EnsembleTracker.java:50) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.EnsembleTracker$2.processResult(EnsembleTracker.java:150) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.CuratorFrameworkImpl.sendToBackgroundCallback(CuratorFrameworkImpl.java:892) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.CuratorFrameworkImpl.processBackgroundOperation(CuratorFrameworkImpl.java:649) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.WatcherRemovalFacade.processBackgroundOperation(WatcherRemovalFacade.java:152) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.curator.framework.imps.GetConfigBuilderImpl$2.processResult(GetConfigBuilderImpl.java:222) ~[curator-framework-5.1.0.jar:5.1.0]
    at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:630) ~[zookeeper-3.6.0.jar:3.6.0]
    at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:551) ~[zookeeper-3.6.0.jar:3.6.0]

2021-04-06 08:52:40.124  INFO 93321 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'

期待的结果

zookeeper使用3.5, curator使用

        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>5.1.0</version>
        </dependency>

可以使用, 但是启动时报错

截屏或录像

其他信息

StephenEvenson commented 3 years ago

我使用了zookeeper集群,有三个节点, 如果只有一个节点,则不会报错

xkcoding commented 3 years ago

这个配置 hosts 就解决了哦,我这边在 dev 分支已经提交了,你可以切换分支看一下~

因为最近在升级 spring boot 版本到 2.4.4 ,每个模块都还在测试,所以没有合并到 master ,后面会合过来,暂时先看下 dev 分支的 demo-zookeerper 模块

xkcoding commented 3 years ago

写了一篇文章,可以看下哦~

@StephenEvenson

https://xkcoding.com/2021/04/14/run-local-zookeeper-cluster-with-docker.html

Estom commented 9 months ago

you are handsome