zrlw commented on a change in pull request #9015:
URL: https://github.com/apache/dubbo/pull/9015#discussion_r739750165



##########
File path: 
dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperTransporter.java
##########
@@ -54,25 +60,98 @@ public ZookeeperClient connect(URL url) {
         ZookeeperClient zookeeperClient;
         // address format: {[username:password@]address}
         List<String> addressList = getURLBackupAddress(url);
-        // The field define the zookeeper server , including protocol, host, 
port, username, password
-        if ((zookeeperClient = 
fetchAndUpdateZookeeperClientCache(addressList)) != null && 
zookeeperClient.isConnected()) {
-            logger.info("find valid zookeeper client from the cache for 
address: " + url);
-            return zookeeperClient;
-        }
+        String application = url.getParameter(APPLICATION_KEY, 
StringUtils.EMPTY_STRING);
         // avoid creating too many connections, so add lock
-        synchronized (zookeeperClientMap) {
-            if ((zookeeperClient = 
fetchAndUpdateZookeeperClientCache(addressList)) != null && 
zookeeperClient.isConnected()) {
+        synchronized (zookeeperApplicationMap) {
+            if ((zookeeperClient = 
fetchAndUpdateZookeeperClientCache(addressList, application)) != null &&
+                    zookeeperClient.isConnected()) {
                 logger.info("find valid zookeeper client from the cache for 
address: " + url);
                 return zookeeperClient;
             }
 
             zookeeperClient = createZookeeperClient(url);
             logger.info("No valid zookeeper client found from cache, therefore 
create a new client for url. " + url);
             writeToClientMap(addressList, zookeeperClient);
+            Set<String> appSet = new HashSet<>();
+            appSet.add(application);
+            zookeeperApplicationMap.put(zookeeperClient, appSet);
         }
         return zookeeperClient;
     }
 
+    /**
+     * close the zookeeper client if it is no longer used by any application.
+     * 
+     * @param zookeeperClient
+     * @param application the application which is going to be destroyed.
+     */
+    @Override
+    public void close(ZookeeperClient zookeeperClient, String application) {
+        synchronized (zookeeperApplicationMap) {
+            Set<String> appSet = zookeeperApplicationMap.get(zookeeperClient);
+            if (appSet == null) {
+                // zookeeperClient might be closed by other zookeeper registry 
of the same application.

Review comment:
       the comment is removed as it is outdated. now zk client only could be 
closed at application destroying or framework destroying.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to