You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2022/04/21 08:06:49 UTC

[dubbo] branch fix-mapping-init created (now 5f36cfe44f)

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

liujun pushed a change to branch fix-mapping-init
in repository https://gitbox.apache.org/repos/asf/dubbo.git


      at 5f36cfe44f fix

This branch includes the following new commits:

     new 5f36cfe44f fix

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[dubbo] 01/01: fix

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch fix-mapping-init
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 5f36cfe44f2581a396fc9da56ad66f4f2d59ad27
Author: chickenlj <ke...@gmail.com>
AuthorDate: Thu Apr 21 15:56:17 2022 +0800

    fix
---
 .../dubbo/metadata/AbstractServiceNameMapping.java | 31 ++++++++++++++--------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/AbstractServiceNameMapping.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/AbstractServiceNameMapping.java
index 66a77ca35d..1126af097e 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/AbstractServiceNameMapping.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/AbstractServiceNameMapping.java
@@ -25,11 +25,7 @@ import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.rpc.model.ApplicationModel;
 import org.apache.dubbo.rpc.model.ScopeModelAware;
 
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.*;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -54,7 +50,7 @@ public abstract class AbstractServiceNameMapping implements ServiceNameMapping,
     private final Map<String, Set<MappingListener>> mappingListeners = new ConcurrentHashMap<>();
     // mapping lock is shared among registries of the same application.
     private final ConcurrentMap<String, ReentrantLock> mappingLocks = new ConcurrentHashMap<>();
-    private volatile boolean initiated;
+    private final Map<String, Boolean> mappingInitiated = new HashMap<>();
 
     public AbstractServiceNameMapping(ApplicationModel applicationModel) {
         this.applicationModel = applicationModel;
@@ -86,12 +82,10 @@ public abstract class AbstractServiceNameMapping implements ServiceNameMapping,
 
     @Override
     public synchronized void initInterfaceAppMapping(URL subscribedURL) {
-        if (initiated) {
-            return;
-        }
-        initiated = true;
-        Set<String> subscribedServices = new TreeSet<>();
         String key = ServiceNameMapping.buildMappingKey(subscribedURL);
+        if (hasInitiated(key)) return;
+
+        Set<String> subscribedServices = new TreeSet<>();
         String serviceNames = subscribedURL.getParameter(PROVIDED_BY);
 
         if (StringUtils.isNotEmpty(serviceNames)) {
@@ -224,6 +218,21 @@ public abstract class AbstractServiceNameMapping implements ServiceNameMapping,
         }
     }
 
+    private boolean hasInitiated(String key) {
+        Lock lock = getMappingLock(key);
+        try {
+            lock.lock();
+            boolean initiated = mappingInitiated.computeIfAbsent(key, _k -> Boolean.FALSE);
+            if (initiated) {
+                return true;
+            }
+            mappingInitiated.put(key, Boolean.TRUE);
+        } finally {
+            lock.unlock();
+        }
+        return false;
+    }
+
     @Override
     public void $destroy() {
         mappingCacheManager.destroy();