Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.dubbo.rpc.model.ModuleModel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -106,6 +107,11 @@ public class ServiceDiscoveryRegistryDirectory<T> extends DynamicDirectory<T> {
private final ModuleModel moduleModel;
private final ProtocolServiceKey consumerProtocolServiceKey;
private final ConcurrentMap<ProtocolServiceKey, URL> customizedConsumerUrlMap = new ConcurrentHashMap<>();
private static final String WEIGHT_KEY = "weight";

// Invocation-level parameters that trigger invoker refresh when changed by dynamic configuration
private static final Set<String> INVOCATION_KEYS = new HashSet<>(Arrays.asList(
CommonConstants.TIMEOUT_KEY, CommonConstants.RETRIES_KEY, CommonConstants.LOADBALANCE_KEY, WEIGHT_KEY));

public ServiceDiscoveryRegistryDirectory(Class<T> serviceType, URL url) {
super(serviceType, url);
Expand Down Expand Up @@ -365,7 +371,7 @@ private void refreshInvoker(List<URL> invokerUrls) {
// factor to avoid resizing.
oldUrlInvokerMap =
new LinkedHashMap<>(Math.round(1 + localUrlInvokerMap.size() / DEFAULT_HASHMAP_LOAD_FACTOR));
localUrlInvokerMap.forEach(oldUrlInvokerMap::put);
oldUrlInvokerMap.putAll(localUrlInvokerMap);
}
Map<ProtocolServiceKeyWithAddress, Invoker<T>> newUrlInvokerMap =
toInvokers(oldUrlInvokerMap, invokerUrls); // Translate url list to Invoker map
Expand Down Expand Up @@ -414,7 +420,6 @@ private void refreshInvoker(List<URL> invokerUrls) {
* the items that will be put into newUrlInvokeMap will be removed from oldUrlInvokerMap.
*
* @param oldUrlInvokerMap it might be modified during the process.
* @param urls
* @return invokers
*/
private Map<ProtocolServiceKeyWithAddress, Invoker<T>> toInvokers(
Expand Down Expand Up @@ -571,6 +576,15 @@ private boolean urlChanged(Invoker<T> invoker, InstanceAddressURL newURL, Protoc
}
}

// Check if any critical invocation parameter has changed
for (String key : INVOCATION_KEYS) {
String oldVal = oldURL.getParameter(key);
String newVal = newURL.getParameter(key);
if (!Objects.equals(oldVal, newVal)) {
return true;
}
}

MetadataInfo.ServiceInfo oldServiceInfo =
oldURL.getMetadataInfo().getValidServiceInfo(protocolServiceKey.toString());
if (null == oldServiceInfo) {
Expand Down Expand Up @@ -647,18 +661,16 @@ protected Map<String, String> getDirectoryMeta() {
* Check whether the invoker in the cache needs to be destroyed
* If set attribute of url: refer.autodestroy=false, the invokers will only increase without decreasing,there may be a refer leak
*
* @param oldUrlInvokerMap
* @param newUrlInvokerMap
*/
private void destroyUnusedInvokers(
Map<ProtocolServiceKeyWithAddress, Invoker<T>> oldUrlInvokerMap,
Map<ProtocolServiceKeyWithAddress, Invoker<T>> newUrlInvokerMap) {
if (newUrlInvokerMap == null || newUrlInvokerMap.size() == 0) {
if (newUrlInvokerMap == null || newUrlInvokerMap.isEmpty()) {
destroyAllInvokers();
return;
}

if (oldUrlInvokerMap == null || oldUrlInvokerMap.size() == 0) {
if (oldUrlInvokerMap == null || oldUrlInvokerMap.isEmpty()) {
return;
}

Expand All @@ -683,7 +695,7 @@ private void destroyUnusedInvokers(
logger.info(oldUrlInvokerMap.size() + " deprecated invokers deleted.");
}

private class ReferenceConfigurationListener extends AbstractConfiguratorListener {
private static class ReferenceConfigurationListener extends AbstractConfiguratorListener {
private final ServiceDiscoveryRegistryDirectory<?> directory;
private final URL url;

Expand Down
Loading