You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2024/05/09 06:08:12 UTC

(servicecomb-java-chassis) branch master updated: [SCB-2877]Fix zookeeper cache instances by application name problem (#4329)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new f3ad2047b [SCB-2877]Fix zookeeper cache instances by application name problem (#4329)
f3ad2047b is described below

commit f3ad2047b9cf09901f843f4c4c9f66dc9df527c5
Author: liubao68 <bi...@qq.com>
AuthorDate: Thu May 9 14:08:07 2024 +0800

    [SCB-2877]Fix zookeeper cache instances by application name problem (#4329)
---
 .../apache/servicecomb/registry/zookeeper/ZookeeperDiscovery.java    | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/service-registry/registry-zookeeper/src/main/java/org/apache/servicecomb/registry/zookeeper/ZookeeperDiscovery.java b/service-registry/registry-zookeeper/src/main/java/org/apache/servicecomb/registry/zookeeper/ZookeeperDiscovery.java
index 4d871b3a1..c421a7022 100644
--- a/service-registry/registry-zookeeper/src/main/java/org/apache/servicecomb/registry/zookeeper/ZookeeperDiscovery.java
+++ b/service-registry/registry-zookeeper/src/main/java/org/apache/servicecomb/registry/zookeeper/ZookeeperDiscovery.java
@@ -73,7 +73,7 @@ public class ZookeeperDiscovery implements Discovery<ZookeeperDiscoveryInstance>
 
   private static final Logger LOGGER = LoggerFactory.getLogger(ZookeeperDiscovery.class);
 
-  private final Map<String, ServiceCache<ZookeeperInstance>> serviceDiscoveries =
+  private final Map<String, Map<String, ServiceCache<ZookeeperInstance>>> serviceDiscoveries =
       new ConcurrentHashMapEx<>();
 
   private Environment environment;
@@ -112,7 +112,8 @@ public class ZookeeperDiscovery implements Discovery<ZookeeperDiscoveryInstance>
   @Override
   public List<ZookeeperDiscoveryInstance> findServiceInstances(String application, String serviceName) {
     try {
-      ServiceCache<ZookeeperInstance> discovery = serviceDiscoveries.computeIfAbsent(application, app -> {
+      ServiceCache<ZookeeperInstance> discovery = serviceDiscoveries.computeIfAbsent(application, app ->
+          new ConcurrentHashMapEx<>()).computeIfAbsent(serviceName, name -> {
         JsonInstanceSerializer<ZookeeperInstance> serializer =
             new JsonInstanceSerializer<>(ZookeeperInstance.class);
         ServiceDiscovery<ZookeeperInstance> dis = ServiceDiscoveryBuilder.builder(ZookeeperInstance.class)