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 08:12:33 UTC

[dubbo] branch 3.0 updated: fix offlineApp does not work as expected, because of empty revision check stops the de-registration. (#10009)

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 435a2e23cd fix offlineApp does not work as expected, because of empty revision check stops the de-registration. (#10009)
435a2e23cd is described below

commit 435a2e23cd2cecf56946d319d407b255429ee8ab
Author: ken.lj <ke...@gmail.com>
AuthorDate: Sat May 7 16:12:19 2022 +0800

    fix offlineApp does not work as expected, because of empty revision check stops the de-registration. (#10009)
    
    fixes #9986
---
 .../main/java/org/apache/dubbo/metadata/MetadataInfo.java   |  5 ++---
 .../dubbo/registry/client/AbstractServiceDiscovery.java     | 13 ++++++-------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
index b412e05596..37bf338eb6 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
@@ -171,10 +171,9 @@ public class MetadataInfo implements Serializable {
     }
 
     /**
-     * Calculation of this instance's status and modification of the instance must be synchronized among different threads.
+     * Calculation of this instance's status like revision and modification of the same instance must be synchronized among different threads.
      * <p>
-     * Usage of this method is strictly restricted at certain point of registration, always try using {@link this#getRevision()}
-     * instead of this method.
+     * Usage of this method is strictly restricted to certain points such as when during registration. Always try to use {@link this#getRevision()} instead.
      */
     public synchronized String calAndGetRevision() {
         if (revision != null && !updated) {
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 7388a46d20..eb44d8c9d6 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
@@ -40,6 +40,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_
 import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
 import static org.apache.dubbo.metadata.RevisionResolver.EMPTY_REVISION;
 import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.EXPORTED_SERVICES_REVISION_PROPERTY_NAME;
+import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getExportedServicesRevision;
 import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.isValidInstance;
 import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.setMetadataStorageType;
 
@@ -235,11 +236,12 @@ public abstract class AbstractServiceDiscovery implements ServiceDiscovery {
     }
 
     protected void doUpdate(ServiceInstance serviceInstance) throws RuntimeException {
-
         this.unregister();
 
-        reportMetadata(serviceInstance.getServiceMetadata());
-        this.doRegister(serviceInstance);
+        if (!EMPTY_REVISION.equals(getExportedServicesRevision(serviceInstance))) {
+            reportMetadata(serviceInstance.getServiceMetadata());
+            this.doRegister(serviceInstance);
+        }
     }
 
     @Override
@@ -262,13 +264,10 @@ public abstract class AbstractServiceDiscovery implements ServiceDiscovery {
     }
 
     protected boolean calOrUpdateInstanceRevision(ServiceInstance instance) {
-        String existingInstanceRevision = instance.getMetadata().get(EXPORTED_SERVICES_REVISION_PROPERTY_NAME);
+        String existingInstanceRevision = getExportedServicesRevision(instance);
         MetadataInfo metadataInfo = instance.getServiceMetadata();
         String newRevision = metadataInfo.calAndGetRevision();
         if (!newRevision.equals(existingInstanceRevision)) {
-            if (EMPTY_REVISION.equals(newRevision)) {
-                return false;
-            }
             instance.getMetadata().put(EXPORTED_SERVICES_REVISION_PROPERTY_NAME, metadataInfo.getRevision());
             return true;
         }