Skip to content
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

Merged
merged 9 commits into from
Dec 21, 2021

Conversation

CalebZYC
Copy link
Contributor

@CalebZYC CalebZYC commented Nov 27, 2021

What's the purpose of this PR

新增zookeeper服务发现支持

使用方式:

  1. 修改build.sh/build.bat,将config-serviceadmin-service的maven编译命令更改为
mvn clean package -Pgithub,zookeeper-discovery -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github,zookeeper-discovery -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password
  1. 分别修改apollo-configservice和apollo-adminservice安装包中config目录下的application-github.properties,配置zookeeper服务器地址
spring.cloud.zookeeper.discovery.instance-host=127.0.0.1
spring.cloud.zookeeper.discovery.instance-port=2181

3.本地调试

  • 修改mavenprofiles项,需要在profiles中将zookeeper-discovery项勾选

  • 分别修改apollo-configserviceapollo-adminservice服务对应的VM options,激活zookeeper-discoveryprofile
    image

-Dapollo_profile=github,zookeeper-discovery

替换成zookeeper服务注册效果如下:
image

Which issue(s) this PR fixes:

Fixes #3557

Brief changelog

XXXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

@nobodyiam
Copy link
Member

@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>
Copy link
Member

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.

Copy link
Contributor Author

@CalebZYC CalebZYC Dec 6, 2021

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

Copy link
Member

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?

Copy link
Contributor

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

pom.xml Outdated
<apache.zookeeper.version>3.4.14</apache.zookeeper.version>
<zookeeper.discovery.version>3.0.4</zookeeper.discovery.version>
</properties>
<dependencyManagement>
Copy link
Member

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>
Copy link
Contributor

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/pom.xml Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 11, 2021

Codecov Report

Merging #4119 (d963c1e) into master (b2c101a) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
...llo/metaservice/controller/HomePageController.java 100.00% <ø> (ø)
...o/metaservice/service/DefaultDiscoveryService.java 100.00% <ø> (ø)
...vice/service/SpringCloudInnerDiscoveryService.java 100.00% <100.00%> (ø)
...ework/apollo/internals/RemoteConfigRepository.java 87.73% <0.00%> (-0.62%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2c101a...d963c1e. Read the comment docs.

Copy link
Member

@nobodyiam nobodyiam left a 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)

docs/zh/deployment/distributed-deployment-guide.md Outdated Show resolved Hide resolved
Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nobodyiam nobodyiam merged commit a62881d into apolloconfig:master Dec 21, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2021
@CalebZYC CalebZYC deleted the zookeeper-discovery branch December 21, 2021 12:02
@nobodyiam nobodyiam added this to the 2.0.0 milestone Jan 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support register to Zookeeper
4 participants