-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add zookeeper service discovery support(#3557) #4119
Conversation
@klboke would you please help to review this pr? |
pom.xml
Outdated
<apache.zookeeper.version>3.4.14</apache.zookeeper.version> | ||
<zookeeper.discovery.version>3.0.4</zookeeper.discovery.version> | ||
</properties> | ||
<dependencyManagement> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this dependencyManagement section is not necessary as the zookeeper related dependencies are managed in spring-cloud-zookeeper-dependencies which is imported in spring-cloud-dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spring-cloud-zookeeper-dependencies用到了curator的依赖,这里引入curator和zookeeper的依赖是考虑到zookeeper版本的兼容性
ZooKeeper Version 3.4.x Compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification. Is there any particular reason that we should stick to the zookeeper 3.4.x version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same problem as nobodyiam about introducing zookeeper related dependencies. Also, I found that the current code running on jdk17, zk-client cannot connect to the local zk-server. the exception is as follows.
2021-12-08 17:39:56.700 WARN 61926 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn : Session 0x0 for server localhost/<unresolved>:2181, unexpected error, closing socket connection and attempting reconnect
java.lang.IllegalArgumentException: Unable to canonicalize address localhost/<unresolved>:2181 because it's not resolvable
at org.apache.zookeeper.SaslServerPrincipal.getServerPrincipal(SaslServerPrincipal.java:65)
at org.apache.zookeeper.SaslServerPrincipal.getServerPrincipal(SaslServerPrincipal.java:41)
at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1001)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1060)
When I remove the following dependencies.
<profile>
<id>zookeeper-discovery</id>
<properties>
<apache.curator.version>4.2.0</apache.curator.version>
<apache.zookeeper.version>3.4.14</apache.zookeeper.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- apache curator -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>${apache.curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${apache.curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${apache.curator.version}</version>
</dependency>
<!-- apache curator end -->
<!-- zookeeper -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${apache.zookeeper.version}</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- zookeeper end -->
</dependencies>
</dependencyManagement>
</profile>
Works well on jdk17
apollo-adminservice/src/main/resources/application-zookeeper-discovery.properties
Outdated
Show resolved
Hide resolved
apollo-adminservice/src/main/resources/application-zookeeper-discovery.properties
Outdated
Show resolved
Hide resolved
pom.xml
Outdated
<apache.zookeeper.version>3.4.14</apache.zookeeper.version> | ||
<zookeeper.discovery.version>3.0.4</zookeeper.discovery.version> | ||
</properties> | ||
<dependencyManagement> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification. Is there any particular reason that we should stick to the zookeeper 3.4.x version?
pom.xml
Outdated
<apache.zookeeper.version>3.4.14</apache.zookeeper.version> | ||
<zookeeper.discovery.version>3.0.4</zookeeper.discovery.version> | ||
</properties> | ||
<dependencyManagement> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same problem as nobodyiam about introducing zookeeper related dependencies. Also, I found that the current code running on jdk17, zk-client cannot connect to the local zk-server. the exception is as follows.
2021-12-08 17:39:56.700 WARN 61926 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn : Session 0x0 for server localhost/<unresolved>:2181, unexpected error, closing socket connection and attempting reconnect
java.lang.IllegalArgumentException: Unable to canonicalize address localhost/<unresolved>:2181 because it's not resolvable
at org.apache.zookeeper.SaslServerPrincipal.getServerPrincipal(SaslServerPrincipal.java:65)
at org.apache.zookeeper.SaslServerPrincipal.getServerPrincipal(SaslServerPrincipal.java:41)
at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1001)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1060)
When I remove the following dependencies.
<profile>
<id>zookeeper-discovery</id>
<properties>
<apache.curator.version>4.2.0</apache.curator.version>
<apache.zookeeper.version>3.4.14</apache.zookeeper.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- apache curator -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>${apache.curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${apache.curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${apache.curator.version}</version>
</dependency>
<!-- apache curator end -->
<!-- zookeeper -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${apache.zookeeper.version}</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- zookeeper end -->
</dependencies>
</dependencyManagement>
</profile>
Works well on jdk17
Codecov Report
@@ Coverage Diff @@
## master #4119 +/- ##
============================================
- Coverage 52.60% 52.59% -0.01%
+ Complexity 2615 2614 -1
============================================
Files 484 484
Lines 15190 15190
Branches 1572 1572
============================================
- Hits 7990 7989 -1
Misses 6644 6644
- Partials 556 557 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the latest code doesn't work in my environment, see the error messages below.
Java version: 1.8
ZooKeeper server version: 3.4.13
2021-12-13 08:50:46.571 WARN 46365 --- [127.0.0.1:2181)] org.apache.zookeeper.ClientCnxn : Session 0x10002b21b600002 for sever localhost/127.0.0.1:2181, Closing socket connection. Attempting reconnect except it is a SessionExpiredException.
org.apache.zookeeper.ClientCnxn$EndOfStreamException: Unable to read additional data from server sessionid 0x10002b21b600002, likely server has closed socket
at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:75)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:348)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1262)
2021-12-13 08:50:46.572 ERROR 46365 --- [nStateManager-0] o.a.c.x.d.details.ServiceDiscoveryImpl : Could not re-register instances after reconnection
org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for /services/apollo-configservice/xx.xx.xx.xx:8080
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:1836)
at org.apache.curator.framework.imps.CreateBuilderImpl$16.call(CreateBuilderImpl.java:1131)
at org.apache.curator.framework.imps.CreateBuilderImpl$16.call(CreateBuilderImpl.java:1113)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:93)
at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1110)
at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:593)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:583)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:48)
at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.internalRegisterService(ServiceDiscoveryImpl.java:237)
at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.reRegisterServices(ServiceDiscoveryImpl.java:456)
at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.access$100(ServiceDiscoveryImpl.java:59)
at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl$1.stateChanged(ServiceDiscoveryImpl.java:79)
at org.apache.curator.framework.state.ConnectionStateManager.lambda$processEvents$0(ConnectionStateManager.java:279)
at org.apache.curator.framework.listen.MappingListenerManager.lambda$forEach$0(MappingListenerManager.java:92)
at org.apache.curator.framework.listen.MappingListenerManager.forEach(MappingListenerManager.java:89)
at org.apache.curator.framework.listen.StandardListenerManager.forEach(StandardListenerManager.java:89)
at org.apache.curator.framework.state.ConnectionStateManager.processEvents(ConnectionStateManager.java:279)
at org.apache.curator.framework.state.ConnectionStateManager.access$000(ConnectionStateManager.java:43)
at org.apache.curator.framework.state.ConnectionStateManager$1.call(ConnectionStateManager.java:132)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What's the purpose of this PR
新增zookeeper服务发现支持
使用方式:
config-service
和admin-service
的maven编译命令更改为3.本地调试
修改maven
profiles
项,需要在profiles中将zookeeper-discovery
项勾选分别修改
apollo-configservice
和apollo-adminservice
服务对应的VM options
,激活zookeeper-discovery
的profile
-Dapollo_profile=github,zookeeper-discovery
替换成zookeeper服务注册效果如下:
Which issue(s) this PR fixes:
Fixes #3557
Brief changelog
XXXXX
Follow this checklist to help us incorporate your contribution quickly and easily:
mvn clean test
to make sure this pull request doesn't break anything.CHANGES
log.