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/05/07 07:37:31 UTC
[dubbo] branch 3.0 updated: Fix interface-app mapping, recored mapping init status for each unique interface key. (#10003)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 8366d310f1 Fix interface-app mapping, recored mapping init status for each unique interface key. (#10003)
8366d310f1 is described below
commit 8366d310f139747c3b70e51e105583e8eb2b2bfd
Author: ken.lj <ke...@gmail.com>
AuthorDate: Sat May 7 15:37:19 2022 +0800
Fix interface-app mapping, recored mapping init status for each unique interface key. (#10003)
fixes #9992
---
.../dubbo/metadata/AbstractServiceNameMapping.java | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 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..4871267ce0 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
@@ -26,6 +26,7 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ScopeModelAware;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -54,7 +55,8 @@ 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;
+ // TODO, check how should this be cleared once a reference or interface is destroyed to avoid key accumulation
+ private final Map<String, Boolean> mappingInitStatus = new HashMap<>();
public AbstractServiceNameMapping(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
@@ -86,12 +88,13 @@ public abstract class AbstractServiceNameMapping implements ServiceNameMapping,
@Override
public synchronized void initInterfaceAppMapping(URL subscribedURL) {
- if (initiated) {
+ String key = ServiceNameMapping.buildMappingKey(subscribedURL);
+ if (hasInitiated(key)) {
return;
}
- initiated = true;
+ mappingInitStatus.put(key, Boolean.TRUE);
+
Set<String> subscribedServices = new TreeSet<>();
- String key = ServiceNameMapping.buildMappingKey(subscribedURL);
String serviceNames = subscribedURL.getParameter(PROVIDED_BY);
if (StringUtils.isNotEmpty(serviceNames)) {
@@ -224,11 +227,22 @@ public abstract class AbstractServiceNameMapping implements ServiceNameMapping,
}
}
+ private boolean hasInitiated(String key) {
+ Lock lock = getMappingLock(key);
+ try {
+ lock.lock();
+ return mappingInitStatus.computeIfAbsent(key, _k -> Boolean.FALSE);
+ } finally {
+ lock.unlock();
+ }
+ }
+
@Override
public void $destroy() {
mappingCacheManager.destroy();
mappingListeners.clear();
mappingLocks.clear();
+ mappingInitStatus.clear();
}
private class AsyncMappingTask implements Callable<Set<String>> {