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 2020/11/18 06:37:09 UTC
[dubbo] branch 3.0 updated (bcc9513 -> 18fef9b)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a change to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git.
from bcc9513 performance tuning, fix cache registry url creation bug (#6914)
new 712a127 put consumer url into URL attribute
new 18fef9b optimize registry and ServiceDiscovery address notification
The 2 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.
Summary of changes:
.../org/apache/dubbo/rpc/cluster/Constants.java | 2 ++
.../rpc/cluster/directory/AbstractDirectory.java | 8 +++--
.../src/main/java/org/apache/dubbo/common/URL.java | 4 +--
.../manager/DefaultExecutorRepository.java | 10 ++++++-
.../threadpool/manager/ExecutorRepository.java | 4 ++-
.../apache/dubbo/config/context/ConfigManager.java | 32 ++++++++++++++++----
.../apache/dubbo/rpc/model/ApplicationModel.java | 5 ++++
.../org/apache/dubbo/config/ReferenceConfig.java | 4 +--
.../java/org/apache/dubbo/registry/Registry.java | 2 +-
.../apache/dubbo/registry/RegistryNotifier.java | 24 ++++++++++-----
.../dubbo/registry/client/InstanceAddressURL.java | 34 ++++++++++++++++++++--
.../dubbo/registry/client/ServiceDiscovery.java | 5 ++++
.../registry/client/ServiceDiscoveryRegistry.java | 6 ++--
.../listener/ServiceInstancesChangedListener.java | 3 +-
.../registry/integration/RegistryProtocol.java | 5 +++-
.../dubbo/registry/support/AbstractRegistry.java | 12 +++++---
.../apache/dubbo/registry/nacos/NacosRegistry.java | 2 +-
.../registry/zookeeper/ZookeeperRegistry.java | 4 +--
.../zookeeper/ZookeeperServiceDiscovery.java | 3 --
.../ZookeeperServiceDiscoveryChangeWatcher.java | 12 +++++++-
20 files changed, 140 insertions(+), 41 deletions(-)
[dubbo] 01/02: put consumer url into URL attribute
Posted by li...@apache.org.
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
commit 712a127549d4ae25d80dac9f3d5880968be6e382
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Nov 17 13:45:25 2020 +0800
put consumer url into URL attribute
---
.../org/apache/dubbo/rpc/cluster/Constants.java | 2 ++
.../rpc/cluster/directory/AbstractDirectory.java | 8 ++++--
.../apache/dubbo/config/context/ConfigManager.java | 32 ++++++++++++++++++----
.../org/apache/dubbo/config/ReferenceConfig.java | 4 +--
.../registry/integration/RegistryProtocol.java | 5 +++-
.../dubbo/registry/support/AbstractRegistry.java | 12 +++++---
6 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java
index 19861ef..c1c755e 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java
@@ -99,4 +99,6 @@ public interface Constants {
* The key name for export URL in register center
*/
String EXPORT_KEY = "export";
+
+ String CONSUMER_URL_KEY = "CONSUMER_URL";
}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
index 6e7da3b..7473466 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
@@ -37,6 +37,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
+import static org.apache.dubbo.rpc.cluster.Constants.CONSUMER_URL_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
/**
@@ -72,10 +73,13 @@ public abstract class AbstractDirectory<T> implements Directory<T> {
Object referParams = url.getAttribute(REFER_KEY);
if (referParams != null) {
this.queryMap = (Map<String, String>) referParams;
- this.consumerUrl = turnRegistryUrlToConsumerUrl(url, queryMap);
+ this.consumerUrl = (URL)url.getAttribute(CONSUMER_URL_KEY);
} else {
this.queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(REFER_KEY));
- this.consumerUrl = url.addParameters(queryMap);
+ }
+
+ if (consumerUrl == null && queryMap != null) {
+ this.consumerUrl = turnRegistryUrlToConsumerUrl(url, queryMap);
}
setRouterChain(routerChain);
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java b/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
index 218fef0..54e3c04 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.config.context;
+import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.context.FrameworkExt;
import org.apache.dubbo.common.context.LifecycleAdapter;
import org.apache.dubbo.common.logger.Logger;
@@ -45,6 +46,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -71,7 +73,18 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
final Map<String, Map<String, AbstractConfig>> configsCache = newMap();
+ private static volatile boolean configWarnLogEnabled = false;
+ private static Map<String, Boolean> warnLogStatus = new ConcurrentHashMap<>();
+
public ConfigManager() {
+ try {
+ String rawWarn = ConfigurationUtils.getProperty("dubbo.application.config.warn", null);
+ if (rawWarn != null) {
+ configWarnLogEnabled = Boolean.parseBoolean(rawWarn);
+ }
+ } catch (Exception e) {
+ logger.warn("Illegal 'dubbo.application.config.warn'config, only boolean value is accepted.", e);
+ }
}
// ApplicationConfig correlative methods
@@ -430,7 +443,10 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
// throw new IllegalStateException("No such " + configType.getName() + " is found");
return null;
} else if (size > 1) {
- logger.warn("Expected single matching of " + configType + ", but found " + size + " instances, will randomly pick the first one.");
+ if (configWarnLogEnabled && warnLogStatus.get(configType) == null) {
+ logger.warn("Expected single matching of " + configType + ", but found " + size + " instances, will randomly pick the first one.");
+ warnLogStatus.put(configType, true);
+ }
}
return configsMap.values().iterator().next();
@@ -477,7 +493,9 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
private static void checkDuplicate(AbstractConfig oldOne, AbstractConfig newOne) throws IllegalStateException {
if (oldOne != null && !oldOne.equals(newOne)) {
String configName = oldOne.getClass().getSimpleName();
- logger.warn("Duplicate Config found for " + configName + ", you should use only one unique " + configName + " for one application.");
+ if (configWarnLogEnabled) {
+ logger.warn("Duplicate Config found for " + configName + ", only one unique " + configName + " is allowed for one application.");
+ }
}
}
@@ -503,10 +521,12 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
C existedConfig = configsMap.get(key);
if (existedConfig != null && !config.equals(existedConfig)) {
- if (logger.isWarnEnabled()) {
- String type = config.getClass().getSimpleName();
- logger.warn(String.format("Duplicate %s found, there already has one default %s or more than two %ss have the same id, " +
- "you can try to give each %s a different id : %s", type, type, type, type, config));
+ if (configWarnLogEnabled) {
+ if (logger.isWarnEnabled()) {
+ String type = config.getClass().getSimpleName();
+ logger.warn(String.format("Duplicate %s found, there already has one default %s or more than two %ss have the same id, " +
+ "you can try to give each %s a different id : %s", type, type, type, type, config));
+ }
}
} else {
configsMap.put(key, config);
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
index 874944a..ec73b47 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
@@ -389,10 +389,10 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
}
if (logger.isInfoEnabled()) {
- logger.info("Refer dubbo service " + interfaceClass.getName() + " from url " + invoker.getUrl());
+ logger.info("Referred dubbo service " + interfaceClass.getName());
}
- URL consumerURL = new URL(CONSUMER_PROTOCOL, map.remove(REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map);
+ URL consumerURL = new URL(CONSUMER_PROTOCOL, map.get(REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map);
MetadataUtils.publishServiceDefinition(consumerURL);
// create service proxy
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
index 8b4a769..95448c0 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
@@ -109,6 +109,7 @@ import static org.apache.dubbo.rpc.Constants.DEPRECATED_KEY;
import static org.apache.dubbo.rpc.Constants.INTERFACES;
import static org.apache.dubbo.rpc.Constants.MOCK_KEY;
import static org.apache.dubbo.rpc.Constants.TOKEN_KEY;
+import static org.apache.dubbo.rpc.cluster.Constants.CONSUMER_URL_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.EXPORT_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.WARMUP_KEY;
@@ -449,7 +450,8 @@ public class RegistryProtocol implements Protocol {
}
protected <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url, Map<String, String> parameters) {
- URL consumerUrl = new URL(parameters.get(PROTOCOL_KEY) == null ? DUBBO : parameters.get(PROTOCOL_KEY), parameters.remove(REGISTER_IP_KEY), 0, type.getName(), parameters);
+ URL consumerUrl = new URL(parameters.get(PROTOCOL_KEY) == null ? DUBBO : parameters.get(PROTOCOL_KEY), parameters.get(REGISTER_IP_KEY), 0, type.getName(), parameters);
+ url = url.putAttribute(CONSUMER_URL_KEY, consumerUrl);
ClusterInvoker<T> migrationInvoker = getMigrationInvoker(this, cluster, registry, type, url, consumerUrl);
return interceptInvoker(migrationInvoker, url, consumerUrl);
}
@@ -487,6 +489,7 @@ public class RegistryProtocol implements Protocol {
// all attributes of REFER_KEY
Map<String, String> parameters = new HashMap<String, String>(directory.getConsumerUrl().getParameters());
URL urlToRegistry = new URL(parameters.get(PROTOCOL_KEY) == null ? DUBBO : parameters.get(PROTOCOL_KEY), parameters.remove(REGISTER_IP_KEY), 0, type.getName(), parameters);
+ URL consumerURL = directory.getConsumerUrl();
if (directory.isShouldRegister()) {
directory.setRegisteredConsumerUrl(urlToRegistry);
registry.register(directory.getRegisteredConsumerUrl());
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
index a73b75f..f408266 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
@@ -284,8 +284,10 @@ public abstract class AbstractRegistry implements Registry {
if (url == null) {
throw new IllegalArgumentException("register url == null");
}
- if (logger.isInfoEnabled()) {
- logger.info("Register: " + url);
+ if (url.getPort() != 0) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Register: " + url);
+ }
}
registered.add(url);
}
@@ -295,8 +297,10 @@ public abstract class AbstractRegistry implements Registry {
if (url == null) {
throw new IllegalArgumentException("unregister url == null");
}
- if (logger.isInfoEnabled()) {
- logger.info("Unregister: " + url);
+ if (url.getPort() != 0) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Unregister: " + url);
+ }
}
registered.remove(url);
}
[dubbo] 02/02: optimize registry and ServiceDiscovery address
notification
Posted by li...@apache.org.
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
commit 18fef9b4c0bbd85e6e5ab937de939849b5673ce7
Author: ken.lj <ke...@gmail.com>
AuthorDate: Wed Nov 18 14:25:40 2020 +0800
optimize registry and ServiceDiscovery address notification
---
.../src/main/java/org/apache/dubbo/common/URL.java | 4 +--
.../manager/DefaultExecutorRepository.java | 10 ++++++-
.../threadpool/manager/ExecutorRepository.java | 4 ++-
.../apache/dubbo/rpc/model/ApplicationModel.java | 5 ++++
.../java/org/apache/dubbo/registry/Registry.java | 2 +-
.../apache/dubbo/registry/RegistryNotifier.java | 24 ++++++++++-----
.../dubbo/registry/client/InstanceAddressURL.java | 34 ++++++++++++++++++++--
.../dubbo/registry/client/ServiceDiscovery.java | 5 ++++
.../registry/client/ServiceDiscoveryRegistry.java | 6 ++--
.../listener/ServiceInstancesChangedListener.java | 3 +-
.../apache/dubbo/registry/nacos/NacosRegistry.java | 2 +-
.../registry/zookeeper/ZookeeperRegistry.java | 4 +--
.../zookeeper/ZookeeperServiceDiscovery.java | 3 --
.../ZookeeperServiceDiscoveryChangeWatcher.java | 12 +++++++-
14 files changed, 92 insertions(+), 26 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
index 1be2800..460b8ed 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
@@ -936,9 +936,9 @@ class URL implements Serializable {
public String getAnyMethodParameter(String key) {
String suffix = "." + key;
- for (String fullKey : getUrlParam().getParameters().keySet()) {
+ for (String fullKey : getParameters().keySet()) {
if (fullKey.endsWith(suffix)) {
- return getUrlParam().getParameters().get(fullKey);
+ return getParameter(fullKey);
}
}
return null;
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/manager/DefaultExecutorRepository.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/manager/DefaultExecutorRepository.java
index 66eafca..398f350 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/manager/DefaultExecutorRepository.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/manager/DefaultExecutorRepository.java
@@ -55,6 +55,8 @@ public class DefaultExecutorRepository implements ExecutorRepository {
private ScheduledExecutorService serviceDiscveryAddressNotificationExecutor;
+ private ScheduledExecutorService metadataRetryExecutor;
+
private ConcurrentMap<String, ConcurrentMap<Integer, ExecutorService>> data = new ConcurrentHashMap<>();
public DefaultExecutorRepository() {
@@ -67,6 +69,7 @@ public class DefaultExecutorRepository implements ExecutorRepository {
serviceExporterExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Dubbo-exporter-scheduler"));
serviceDiscveryAddressNotificationExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Dubbo-SD-address-refresh"));
registryNotificationExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Dubbo-registry-notification"));
+ metadataRetryExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Dubbo-metadata-retry"));
}
/**
@@ -164,11 +167,16 @@ public class DefaultExecutorRepository implements ExecutorRepository {
return registryNotificationExecutor;
}
- public ScheduledExecutorService getServiceDiscveryAddressNotificationExecutor() {
+ public ScheduledExecutorService getServiceDiscoveryAddressNotificationExecutor() {
return serviceDiscveryAddressNotificationExecutor;
}
@Override
+ public ScheduledExecutorService getMetadataRetryExecutor() {
+ return null;
+ }
+
+ @Override
public ExecutorService getSharedExecutor() {
return SHARED_EXECUTOR;
}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/manager/ExecutorRepository.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/manager/ExecutorRepository.java
index 5c08fe3..d00a7bb 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/manager/ExecutorRepository.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/manager/ExecutorRepository.java
@@ -57,7 +57,9 @@ public interface ExecutorRepository {
ScheduledExecutorService getServiceExporterExecutor();
- ScheduledExecutorService getServiceDiscveryAddressNotificationExecutor();
+ ScheduledExecutorService getServiceDiscoveryAddressNotificationExecutor();
+
+ ScheduledExecutorService getMetadataRetryExecutor();
/**
* Scheduled executor handle registry notification.
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java
index 6238b80..7400857 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java
@@ -21,6 +21,7 @@ import org.apache.dubbo.common.context.FrameworkExt;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.threadpool.manager.ExecutorRepository;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.context.ConfigManager;
@@ -96,6 +97,10 @@ public class ApplicationModel {
return (ServiceRepository) LOADER.getExtension(ServiceRepository.NAME);
}
+ public static ExecutorRepository getExecutorRepository() {
+ return ExtensionLoader.getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
+ }
+
public static ApplicationConfig getApplicationConfig() {
return getConfigManager().getApplicationOrElseThrow();
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Registry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Registry.java
index 084deff..e5f5cba 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Registry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Registry.java
@@ -29,7 +29,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_DELAY_N
*/
public interface Registry extends Node, RegistryService {
default int getDelay() {
- return getUrl().getParameter(REGISTRY_DELAY_NOTIFICATION_KEY, -1);
+ return getUrl().getParameter(REGISTRY_DELAY_NOTIFICATION_KEY, 5000);
}
default void reExportRegister(URL url) {
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java
index babf5ce..4ab5c48 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java
@@ -28,17 +28,22 @@ public abstract class RegistryNotifier {
private volatile long lastEventTime;
private Object rawAddresses;
- private Registry registry;
+ private long delayTime;
- private ScheduledExecutorService scheduler = ExtensionLoader.getExtensionLoader(ExecutorRepository.class)
- .getDefaultExtension().getRegistryNotificationExecutor();
+ private ScheduledExecutorService scheduler;
- public Registry getRegistry() {
- return registry;
+ public RegistryNotifier(long delayTime) {
+ this(delayTime, null);
}
- public RegistryNotifier(Registry registry) {
- this.registry = registry;
+ public RegistryNotifier(long delayTime, ScheduledExecutorService scheduler) {
+ this.delayTime = delayTime;
+ if (scheduler == null) {
+ this.scheduler = ExtensionLoader.getExtensionLoader(ExecutorRepository.class)
+ .getDefaultExtension().getRegistryNotificationExecutor();
+ } else {
+ this.scheduler = scheduler;
+ }
}
public synchronized void notify(Object rawAddresses) {
@@ -46,7 +51,6 @@ public abstract class RegistryNotifier {
long notifyTime = System.currentTimeMillis();
this.lastEventTime = notifyTime;
- int delayTime = getRegistry().getDelay();
long delta = (System.currentTimeMillis() - lastExecuteTime) - delayTime;
if (delta >= 0) {
scheduler.submit(new NotificationTask(this, notifyTime));
@@ -55,6 +59,10 @@ public abstract class RegistryNotifier {
}
}
+ public long getDelayTime() {
+ return delayTime;
+ }
+
protected abstract void doNotify(Object rawAddresses);
public static class NotificationTask implements Runnable {
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/InstanceAddressURL.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/InstanceAddressURL.java
index d2ee657..624f93f 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/InstanceAddressURL.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/InstanceAddressURL.java
@@ -17,6 +17,8 @@
package org.apache.dubbo.registry.client;
import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.url.component.URLAddress;
+import org.apache.dubbo.common.url.component.URLParam;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metadata.MetadataInfo;
import org.apache.dubbo.rpc.RpcContext;
@@ -38,8 +40,7 @@ public class InstanceAddressURL extends URL {
private volatile transient Map<String, Number> numbers;
private volatile transient Map<String, Map<String, Number>> methodNumbers;
- public InstanceAddressURL() {
- }
+ public InstanceAddressURL() {}
public InstanceAddressURL(
ServiceInstance instance,
@@ -300,6 +301,35 @@ public class InstanceAddressURL extends URL {
}
@Override
+ public String getAnyMethodParameter(String key) {
+ String suffix = "." + key;
+ for (String fullKey : instance.getMetadata().keySet()) {
+ if (fullKey.endsWith(suffix)) {
+ return getParameter(fullKey);
+ }
+ }
+ String protocolServiceKey = getProtocolServiceKey();
+ if (StringUtils.isNotEmpty(protocolServiceKey)) {
+ for (String fullKey : metadataInfo.getParameters(protocolServiceKey).keySet()) {
+ if (fullKey.endsWith(suffix)) {
+ return getParameter(fullKey);
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public URLParam getUrlParam() {
+ throw new UnsupportedOperationException("URLParam is replaced with MetadataInfo in instance url");
+ }
+
+ @Override
+ public URLAddress getUrlAddress() {
+ throw new UnsupportedOperationException("URLAddress is replaced with ServiceInstance in instance url");
+ }
+
+ @Override
protected Map<String, Number> getServiceNumbers(String protocolServiceKey) {
return getServiceInfo(protocolServiceKey).getNumbers();
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscovery.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscovery.java
index 3b6c4e5..90ba196 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscovery.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscovery.java
@@ -36,6 +36,7 @@ import java.util.stream.Stream;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
+import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_DELAY_NOTIFICATION_KEY;
import static org.apache.dubbo.event.EventDispatcher.getDefaultExtension;
/**
@@ -278,6 +279,10 @@ public interface ServiceDiscovery extends Prioritized {
ServiceInstance getLocalInstance();
+ default long getDelay() {
+ return getUrl().getParameter(REGISTRY_DELAY_NOTIFICATION_KEY, 5000);
+ }
+
/**
* A human-readable description of the implementation
*
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
index a6c7dd9..d7caa18 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
@@ -378,10 +378,10 @@ public class ServiceDiscoveryRegistry implements Registry {
if (isEmpty(subscribedServices)) {
Set<String> mappedServices = findMappedServices(subscribedURL, new DefaultMappingListener(subscribedURL, subscribedServices, listener));
- logger.info(subscribedURL.getServiceInterface() + " mapping to " + serviceNames + " instructed by remote metadata center.");
+ logger.info(subscribedURL.getServiceInterface() + " mapping to " + mappedServices + " instructed by remote metadata center.");
subscribedServices.addAll(mappedServices);
if (isEmpty(subscribedServices)) {
- logger.info(subscribedURL.getServiceInterface() + " mapping to " + serviceNames + " by default.");
+ logger.info(subscribedURL.getServiceInterface() + " mapping to " + getSubscribedServices() + " by default.");
subscribedServices.addAll(getSubscribedServices());
}
}
@@ -499,6 +499,7 @@ public class ServiceDiscoveryRegistry implements Registry {
}
private class DefaultMappingListener implements MappingListener {
+ private final Logger logger = LoggerFactory.getLogger(DefaultMappingListener.class);
private URL url;
private Set<String> oldApps;
private NotifyListener listener;
@@ -511,6 +512,7 @@ public class ServiceDiscoveryRegistry implements Registry {
@Override
public void onEvent(MappingChangedEvent event) {
+ logger.info("Received mapping notification from meta server, " + event);
Set<String> newApps = event.getApps();
Set<String> tempOldApps = oldApps;
oldApps = newApps;
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
index 540deaf..f0fcd33 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
@@ -93,8 +93,7 @@ public class ServiceInstancesChangedListener implements ConditionalEventListener
this.serviceUrls = new HashMap<>();
this.revisionToMetadata = new HashMap<>();
retryPermission = new Semaphore(1);
- this.scheduler = ExtensionLoader.getExtensionLoader(ExecutorRepository.class).getDefaultExtension()
- .getServiceDiscveryAddressNotificationExecutor();
+ this.scheduler = ExtensionLoader.getExtensionLoader(ExecutorRepository.class).getDefaultExtension().getMetadataRetryExecutor();
}
/**
diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
index 923401f..c472793 100644
--- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
+++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
@@ -618,7 +618,7 @@ public class NacosRegistry extends FailbackRegistry {
private RegistryNotifier notifier;
public RegistryChildListenerImpl(String serviceName, URL consumerUrl, NotifyListener listener) {
- notifier = new RegistryNotifier(NacosRegistry.this) {
+ notifier = new RegistryNotifier(NacosRegistry.this.getDelay()) {
@Override
protected void doNotify(Object rawAddresses) {
List<Instance> instances = (List<Instance>) rawAddresses;
diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java
index ae22530..663e25d 100644
--- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java
+++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java
@@ -293,10 +293,10 @@ public class ZookeeperRegistry extends CacheableFailbackRegistry {
public RegistryChildListenerImpl(URL consumerUrl, String path, NotifyListener listener, CountDownLatch latch) {
this.latch = latch;
- notifier = new RegistryNotifier(ZookeeperRegistry.this) {
+ notifier = new RegistryNotifier(ZookeeperRegistry.this.getDelay()) {
@Override
public void notify(Object rawAddresses) {
- int delayTime = getRegistry().getDelay();
+ long delayTime = getDelayTime();
if (delayTime <= 0) {
this.doNotify(rawAddresses);
} else {
diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java
index 80b7d2a..6e47bb0 100644
--- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java
+++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java
@@ -23,7 +23,6 @@ import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.DefaultPage;
import org.apache.dubbo.common.utils.Page;
-import org.apache.dubbo.event.EventDispatcher;
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;
@@ -57,8 +56,6 @@ public class ZookeeperServiceDiscovery implements ServiceDiscovery {
private URL registryURL;
- private EventDispatcher dispatcher;
-
private CuratorFramework curatorFramework;
private String rootPath;
diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryChangeWatcher.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryChangeWatcher.java
index fa982d8..fef3fef 100644
--- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryChangeWatcher.java
+++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryChangeWatcher.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.registry.zookeeper;
+import org.apache.dubbo.registry.RegistryNotifier;
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent;
import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;
@@ -24,6 +25,7 @@ import org.apache.curator.framework.api.CuratorWatcher;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
+import static org.apache.dubbo.rpc.model.ApplicationModel.getExecutorRepository;
import static org.apache.zookeeper.Watcher.Event.EventType.NodeChildrenChanged;
import static org.apache.zookeeper.Watcher.Event.EventType.NodeDataChanged;
@@ -39,6 +41,8 @@ public class ZookeeperServiceDiscoveryChangeWatcher implements CuratorWatcher {
private final ZookeeperServiceDiscovery zookeeperServiceDiscovery;
+ private final RegistryNotifier notifier;
+
private boolean keepWatching;
private final String serviceName;
@@ -49,6 +53,12 @@ public class ZookeeperServiceDiscoveryChangeWatcher implements CuratorWatcher {
this.zookeeperServiceDiscovery = zookeeperServiceDiscovery;
this.serviceName = serviceName;
this.listener = listener;
+ this.notifier = new RegistryNotifier(zookeeperServiceDiscovery.getDelay(), getExecutorRepository().getServiceDiscoveryAddressNotificationExecutor()) {
+ @Override
+ protected void doNotify(Object rawAddresses) {
+ listener.onEvent((ServiceInstancesChangedEvent)rawAddresses);
+ }
+ };
}
@Override
@@ -58,7 +68,7 @@ public class ZookeeperServiceDiscoveryChangeWatcher implements CuratorWatcher {
if (NodeChildrenChanged.equals(eventType) || NodeDataChanged.equals(eventType)) {
if (shouldKeepWatching()) {
- listener.onEvent(new ServiceInstancesChangedEvent(serviceName, zookeeperServiceDiscovery.getInstances(serviceName)));
+ notifier.notify(new ServiceInstancesChangedEvent(serviceName, zookeeperServiceDiscovery.getInstances(serviceName)));
zookeeperServiceDiscovery.registerServiceWatcher(serviceName, listener);
zookeeperServiceDiscovery.dispatchServiceInstancesChangedEvent(serviceName);
}