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 2021/12/09 08:27:44 UTC

[dubbo] branch 3.0-metadata-refactor updated (6416891 -> 924e0bc)

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

liujun pushed a change to branch 3.0-metadata-refactor
in repository https://gitbox.apache.org/repos/asf/dubbo.git.


    from 6416891  fix ut
     new 2b0a442  fix, dynamic configuration close & ServiceDiscoveryRegistry
     new 924e0bc  fix potential NPE

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:
 .../config/configcenter/wrapper/CompositeDynamicConfiguration.java  | 2 +-
 .../org/apache/dubbo/registry/client/AbstractServiceDiscovery.java  | 5 +++++
 .../org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java  | 6 +-----
 .../apache/dubbo/registry/client/migration/model/MigrationRule.java | 6 ++++--
 .../java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java | 4 ++++
 .../apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java  | 4 ++++
 6 files changed, 19 insertions(+), 8 deletions(-)

[dubbo] 01/02: fix, dynamic configuration close & ServiceDiscoveryRegistry

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-metadata-refactor
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 2b0a44227b93767b553886f41754b744046fc399
Author: ken.lj <ke...@gmail.com>
AuthorDate: Thu Dec 2 17:00:26 2021 +0800

    fix, dynamic configuration close & ServiceDiscoveryRegistry
---
 .../config/configcenter/wrapper/CompositeDynamicConfiguration.java  | 2 +-
 .../org/apache/dubbo/registry/client/AbstractServiceDiscovery.java  | 5 +++++
 .../org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java  | 6 +-----
 .../java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java | 4 ++++
 .../apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java  | 4 ++++
 5 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java
index a2e8dea..a345ad4 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java
@@ -97,7 +97,7 @@ public class CompositeDynamicConfiguration implements DynamicConfiguration {
             try {
                 configuration.close();
             } catch (Exception e) {
-                logger.warn("close dynamic configuration failed: " + e.getMessage(), e);
+                logger.warn("close dynamic configuration " + configuration.getClass().getName() + "failed: " + e.getMessage(), e);
             }
         }
         configurations.clear();
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
index e86a6c6..dab0e03 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
@@ -19,17 +19,20 @@ package org.apache.dubbo.registry.client;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.ConcurrentHashSet;
 import org.apache.dubbo.metadata.MetadataInfo;
 import org.apache.dubbo.metadata.report.MetadataReport;
 import org.apache.dubbo.metadata.report.MetadataReportInstance;
 import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
 import org.apache.dubbo.registry.NotifyListener;
+import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;
 import org.apache.dubbo.registry.client.metadata.MetadataUtils;
 import org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils;
 import org.apache.dubbo.registry.client.metadata.store.MetaCacheManager;
 import org.apache.dubbo.rpc.model.ApplicationModel;
 
 import java.util.List;
+import java.util.Set;
 
 import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
 import static org.apache.dubbo.metadata.RevisionResolver.EMPTY_REVISION;
@@ -52,6 +55,8 @@ public abstract class AbstractServiceDiscovery implements ServiceDiscovery {
     protected MetaCacheManager metaCacheManager;
     protected URL registryURL;
 
+    protected Set<ServiceInstancesChangedListener> instanceListeners = new ConcurrentHashSet<>();
+
     protected ApplicationModel applicationModel;
 
     public AbstractServiceDiscovery(ApplicationModel applicationModel, URL registryURL) {
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 551fd55..40b4ef8 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
@@ -286,7 +286,6 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
         String protocolServiceKey = url.getServiceKey() + GROUP_CHAR_SEPARATOR + url.getParameter(PROTOCOL_KEY, DUBBO);
 
         // register ServiceInstancesChangedListener
-        boolean serviceListenerRegistered = true;
         ServiceInstancesChangedListener serviceInstancesChangedListener;
         synchronized (this) {
             serviceInstancesChangedListener = serviceListeners.get(serviceNamesKey);
@@ -299,7 +298,6 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
                         serviceInstancesChangedListener.onEvent(new ServiceInstancesChangedEvent(serviceName, serviceInstances));
                     }
                 }
-                serviceListenerRegistered = false;
                 serviceListeners.put(serviceNamesKey, serviceInstancesChangedListener);
             }
         }
@@ -307,9 +305,7 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
         serviceInstancesChangedListener.setUrl(url);
         listener.addServiceListener(serviceInstancesChangedListener);
         serviceInstancesChangedListener.addListenerAndNotify(protocolServiceKey, listener);
-        if (!serviceListenerRegistered) {
-            serviceDiscovery.addServiceInstancesChangedListener(serviceInstancesChangedListener);
-        }
+        serviceDiscovery.addServiceInstancesChangedListener(serviceInstancesChangedListener);
     }
 
     /**
diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java
index bd020fc..1bf83cc 100644
--- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java
+++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java
@@ -110,6 +110,10 @@ public class NacosServiceDiscovery extends AbstractServiceDiscovery {
     @Override
     public void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener)
         throws NullPointerException, IllegalArgumentException {
+        // check if listener has already been added through another interface/service
+        if (!instanceListeners.add(listener)) {
+            return;
+        }
         execute(namingService, service -> listener.getServiceNames().forEach(serviceName -> {
             try {
                 service.subscribe(serviceName, Constants.DEFAULT_GROUP, e -> { // Register Nacos EventListener
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 59099e4..6d2f438 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
@@ -113,6 +113,10 @@ public class ZookeeperServiceDiscovery extends AbstractServiceDiscovery {
     @Override
     public void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener)
         throws NullPointerException, IllegalArgumentException {
+        // check if listener has already been added through another interface/service
+        if (!instanceListeners.add(listener)) {
+            return;
+        }
         listener.getServiceNames().forEach(serviceName -> registerServiceWatcher(serviceName, listener));
     }
 

[dubbo] 02/02: fix potential NPE

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-metadata-refactor
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 924e0bc1cf2467541653ab0af77707c905c2ffe6
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Nov 23 13:23:22 2021 +0800

    fix potential NPE
---
 .../apache/dubbo/registry/client/migration/model/MigrationRule.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/MigrationRule.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/MigrationRule.java
index 8dc97f7..9a4c689 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/MigrationRule.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/MigrationRule.java
@@ -164,8 +164,10 @@ public class MigrationRule {
             if (CollectionUtils.isNotEmpty(services)) {
                 for (String service : services) {
                     SubMigrationRule rule = applicationRules.get(service);
-                    if (rule.getStep() != null) {
-                        return rule.getStep();
+                    if (rule != null) {
+                        if (rule.getStep() != null) {
+                            return rule.getStep();
+                        }
                     }
                 }
             }