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

albumenj pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.1 by this push:
     new f9b27eddef Fix service discovery metadata update failed (#11298)
f9b27eddef is described below

commit f9b27eddef0ea40f17314320ce38f4368e7ca1ae
Author: Albumen Kevin <[email protected]>
AuthorDate: Sat Jan 14 14:32:48 2023 +0800

    Fix service discovery metadata update failed (#11298)
---
 .../dubbo/registry/client/AbstractServiceDiscovery.java    | 14 ++++++++++++--
 .../apache/dubbo/registry/nacos/NacosServiceDiscovery.java |  4 +++-
 .../registry/zookeeper/ZookeeperServiceDiscovery.java      |  2 +-
 3 files changed, 16 insertions(+), 4 deletions(-)

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 77f983a743..d3431d77e9 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
@@ -296,12 +296,22 @@ public abstract class AbstractServiceDiscovery implements 
ServiceDiscovery {
         throw new UnsupportedOperationException("Service discovery 
implementation does not support lookup of url list.");
     }
 
-    protected void doUpdate(ServiceInstance oldServiceInstance, 
ServiceInstance newServiceInstance) throws RuntimeException {
+    /**
+     * Update Service Instance. Unregister and then register by default.
+     * Can be override if registry support update instance directly.
+     * <br/>
+     * NOTICE: Remind to update {@link 
AbstractServiceDiscovery#serviceInstance}'s reference if updated
+     *         and report metadata by {@link 
AbstractServiceDiscovery#reportMetadata(MetadataInfo)}
+     *
+     * @param oldServiceInstance origin service instance
+     * @param newServiceInstance new service instance
+     */
+    protected void doUpdate(ServiceInstance oldServiceInstance, 
ServiceInstance newServiceInstance) {
         this.doUnregister(oldServiceInstance);
 
         if 
(!EMPTY_REVISION.equals(getExportedServicesRevision(serviceInstance))) {
-            reportMetadata(serviceInstance.getServiceMetadata());
             this.serviceInstance = newServiceInstance;
+            reportMetadata(newServiceInstance.getServiceMetadata());
             this.doRegister(newServiceInstance);
         }
     }
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 28c2efd44e..a589ec19ee 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
@@ -113,13 +113,15 @@ public class NacosServiceDiscovery extends 
AbstractServiceDiscovery {
         if (!Objects.equals(oldServiceInstance.getServiceName(), 
newServiceInstance.getServiceName()) ||
             !Objects.equals(oldServiceInstance.getAddress(), 
newServiceInstance.getAddress()) ||
             !Objects.equals(oldServiceInstance.getPort(), 
newServiceInstance.getPort())) {
-            // ignore if host-ip changed
+            // Ignore if host-ip changed. Should unregister first.
             super.doUpdate(oldServiceInstance, newServiceInstance);
             return;
         }
 
         try {
             this.serviceInstance = newServiceInstance;
+            reportMetadata(newServiceInstance.getServiceMetadata());
+
             // override without unregister
             this.doRegister(newServiceInstance);
         } catch (Exception e) {
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 a4897bfc88..a27675b5c4 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
@@ -120,7 +120,7 @@ public class ZookeeperServiceDiscovery extends 
AbstractServiceDiscovery {
         org.apache.curator.x.discovery.ServiceInstance<ZookeeperInstance> 
newInstance = build(newServiceInstance);
         if (!Objects.equals(newInstance.getName(), oldInstance.getName()) ||
             !Objects.equals(newInstance.getId(), oldInstance.getId())) {
-            // ignore if id changed
+            // Ignore if id changed. Should unregister first.
             super.doUpdate(oldServiceInstance, newServiceInstance);
             return;
         }

Reply via email to