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 d2f4ef124d Fix after offline and online error (#12044)
d2f4ef124d is described below
commit d2f4ef124d9ba1c84f5ccbd3bf7b01c26afffbba
Author: xieshouyu <[email protected]>
AuthorDate: Mon Apr 10 17:46:41 2023 +0800
Fix after offline and online error (#12044)
---
.../registry/nacos/NacosServiceDiscovery.java | 24 ++++++++++++----------
.../zookeeper/ZookeeperServiceDiscovery.java | 15 ++++++++------
2 files changed, 22 insertions(+), 17 deletions(-)
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 a589ec19ee..d30b5c2f62 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
@@ -49,6 +49,7 @@ import static
com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
import static
org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_NACOS_EXCEPTION;
import static org.apache.dubbo.common.function.ThrowableConsumer.execute;
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.nacos.util.NacosNamingServiceUtils.createNamingService;
import static
org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.getGroup;
@@ -78,7 +79,7 @@ public class NacosServiceDiscovery extends
AbstractServiceDiscovery {
this.namingService = createNamingService(registryURL);
// backward compatibility for 3.0.x
this.group =
Boolean.parseBoolean(ConfigurationUtils.getProperty(applicationModel,
NACOS_SD_USE_DEFAULT_GROUP_KEY, "false")) ?
- DEFAULT_GROUP : getGroup(registryURL);
+ DEFAULT_GROUP : getGroup(registryURL);
}
@Override
@@ -105,14 +106,15 @@ public class NacosServiceDiscovery extends
AbstractServiceDiscovery {
@Override
protected void doUpdate(ServiceInstance oldServiceInstance,
ServiceInstance newServiceInstance) throws RuntimeException {
- if
(EMPTY_REVISION.equals(getExportedServicesRevision(newServiceInstance))) {
+ if
(EMPTY_REVISION.equals(getExportedServicesRevision(newServiceInstance))
+ ||
EMPTY_REVISION.equals(oldServiceInstance.getMetadata().get(EXPORTED_SERVICES_REVISION_PROPERTY_NAME)))
{
super.doUpdate(oldServiceInstance, newServiceInstance);
return;
}
if (!Objects.equals(oldServiceInstance.getServiceName(),
newServiceInstance.getServiceName()) ||
- !Objects.equals(oldServiceInstance.getAddress(),
newServiceInstance.getAddress()) ||
- !Objects.equals(oldServiceInstance.getPort(),
newServiceInstance.getPort())) {
+ !Objects.equals(oldServiceInstance.getAddress(),
newServiceInstance.getAddress()) ||
+ !Objects.equals(oldServiceInstance.getPort(),
newServiceInstance.getPort())) {
// Ignore if host-ip changed. Should unregister first.
super.doUpdate(oldServiceInstance, newServiceInstance);
return;
@@ -140,15 +142,15 @@ public class NacosServiceDiscovery extends
AbstractServiceDiscovery {
@Override
public List<ServiceInstance> getInstances(String serviceName) throws
NullPointerException {
return ThrowableFunction.execute(namingService, service ->
- service.selectInstances(serviceName, group, true)
- .stream().map((i) ->
NacosNamingServiceUtils.toServiceInstance(registryURL, i))
- .collect(Collectors.toList())
+ service.selectInstances(serviceName, group, true)
+ .stream().map((i) ->
NacosNamingServiceUtils.toServiceInstance(registryURL, i))
+ .collect(Collectors.toList())
);
}
@Override
public void
addServiceInstancesChangedListener(ServiceInstancesChangedListener listener)
- throws NullPointerException, IllegalArgumentException {
+ throws NullPointerException, IllegalArgumentException {
// check if listener has already been added through another
interface/service
if (!instanceListeners.add(listener)) {
return;
@@ -225,9 +227,9 @@ public class NacosServiceDiscovery extends
AbstractServiceDiscovery {
private void handleEvent(NamingEvent event,
ServiceInstancesChangedListener listener) {
String serviceName = event.getServiceName();
List<ServiceInstance> serviceInstances = event.getInstances()
- .stream()
- .map((i) -> NacosNamingServiceUtils.toServiceInstance(registryURL,
i))
- .collect(Collectors.toList());
+ .stream()
+ .map((i) ->
NacosNamingServiceUtils.toServiceInstance(registryURL, i))
+ .collect(Collectors.toList());
listener.onEvent(new ServiceInstancesChangedEvent(serviceName,
serviceInstances));
}
}
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 a27675b5c4..1dd2ea8896 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
@@ -28,6 +28,7 @@ import java.util.concurrent.CountDownLatch;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.CuratorWatcher;
import org.apache.curator.x.discovery.ServiceCache;
+
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.function.ThrowableConsumer;
import org.apache.dubbo.common.function.ThrowableFunction;
@@ -44,6 +45,7 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
import static
org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_ZOOKEEPER_EXCEPTION;
import static org.apache.dubbo.common.function.ThrowableFunction.execute;
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.zookeeper.util.CuratorFrameworkUtils.build;
import static
org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkUtils.buildCuratorFramework;
@@ -111,7 +113,8 @@ public class ZookeeperServiceDiscovery extends
AbstractServiceDiscovery {
@Override
protected void doUpdate(ServiceInstance oldServiceInstance,
ServiceInstance newServiceInstance) throws RuntimeException {
- if
(EMPTY_REVISION.equals(getExportedServicesRevision(newServiceInstance))) {
+ if
(EMPTY_REVISION.equals(getExportedServicesRevision(newServiceInstance))
+ ||
EMPTY_REVISION.equals(oldServiceInstance.getMetadata().get(EXPORTED_SERVICES_REVISION_PROPERTY_NAME)))
{
super.doUpdate(oldServiceInstance, newServiceInstance);
return;
}
@@ -119,7 +122,7 @@ public class ZookeeperServiceDiscovery extends
AbstractServiceDiscovery {
org.apache.curator.x.discovery.ServiceInstance<ZookeeperInstance>
oldInstance = build(oldServiceInstance);
org.apache.curator.x.discovery.ServiceInstance<ZookeeperInstance>
newInstance = build(newServiceInstance);
if (!Objects.equals(newInstance.getName(), oldInstance.getName()) ||
- !Objects.equals(newInstance.getId(), oldInstance.getId())) {
+ !Objects.equals(newInstance.getId(), oldInstance.getId())) {
// Ignore if id changed. Should unregister first.
super.doUpdate(oldServiceInstance, newServiceInstance);
return;
@@ -146,7 +149,7 @@ public class ZookeeperServiceDiscovery extends
AbstractServiceDiscovery {
@Override
public void
addServiceInstancesChangedListener(ServiceInstancesChangedListener listener)
- throws NullPointerException, IllegalArgumentException {
+ throws NullPointerException, IllegalArgumentException {
// check if listener has already been added through another
interface/service
if (!instanceListeners.add(listener)) {
return;
@@ -169,7 +172,7 @@ public class ZookeeperServiceDiscovery extends
AbstractServiceDiscovery {
watcher.getCacheInstance().close();
} catch (IOException e) {
logger.error(REGISTRY_ZOOKEEPER_EXCEPTION, "curator
stop watch failed", "",
- "Curator Stop service discovery watch failed.
Service Name: " + serviceName);
+ "Curator Stop service discovery watch failed.
Service Name: " + serviceName);
}
}
}
@@ -190,8 +193,8 @@ public class ZookeeperServiceDiscovery extends
AbstractServiceDiscovery {
ZookeeperServiceDiscoveryChangeWatcher watcher =
watcherCaches.computeIfAbsent(serviceName, name -> {
ServiceCache<ZookeeperInstance> serviceCache =
serviceDiscovery.serviceCacheBuilder()
- .name(name)
- .build();
+ .name(name)
+ .build();
ZookeeperServiceDiscoveryChangeWatcher newer = new
ZookeeperServiceDiscoveryChangeWatcher(this, serviceCache, name, latch);
serviceCache.addListener(newer);