Skip to content

Commit

Permalink
Fix interface-app mapping, recored mapping init status for each uniqu…
Browse files Browse the repository at this point in the history
…e interface key. (apache#10003)

fixes apache#9992
  • Loading branch information
chickenlj authored and AlbumenJ committed Jun 13, 2022
1 parent 3ac0c09 commit 6e7dad1
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -86,12 +88,13 @@ public void setApplicationModel(ApplicationModel applicationModel) {

@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)) {
Expand Down Expand Up @@ -223,11 +226,22 @@ protected void removeMappingLock(String key) {
}
}

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>> {
Expand Down

0 comments on commit 6e7dad1

Please sign in to comment.