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 9a4aadd917 Fix abstractServiceDiscovery update exception caused by
loading order (#12033)
9a4aadd917 is described below
commit 9a4aadd9173a57dd9a44c1429637f34f78784848
Author: xieshouyu <[email protected]>
AuthorDate: Mon Apr 10 07:24:36 2023 +0800
Fix abstractServiceDiscovery update exception caused by loading order
(#12033)
* 1、fix abstractServiceDiscovery update exception caused by loading order
* 1、delete registry status and replace it with serviceInstance
* 1.fix code style
---
.../registry/client/AbstractServiceDiscovery.java | 55 ++++++++++------------
1 file changed, 25 insertions(+), 30 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 6241fe1778..15d8fe9f92 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
@@ -49,7 +49,6 @@ import static
org.apache.dubbo.common.constants.CommonConstants.METADATA_INFO_CA
import static
org.apache.dubbo.common.constants.CommonConstants.REGISTRY_LOCAL_FILE_CACHE_ENABLED;
import static
org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
import static
org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
-import static
org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_FETCH_INSTANCE;
import static
org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_LOAD_METADATA;
import static
org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
import static org.apache.dubbo.metadata.RevisionResolver.EMPTY_REVISION;
@@ -97,32 +96,32 @@ public abstract class AbstractServiceDiscovery implements
ServiceDiscovery {
this.metadataInfo = new MetadataInfo(serviceName);
boolean localCacheEnabled =
registryURL.getParameter(REGISTRY_LOCAL_FILE_CACHE_ENABLED, true);
this.metaCacheManager = new MetaCacheManager(localCacheEnabled,
getCacheNameSuffix(),
- applicationModel.getFrameworkModel().getBeanFactory()
-
.getBean(FrameworkExecutorRepository.class).getCacheRefreshingScheduledExecutor());
+ applicationModel.getFrameworkModel().getBeanFactory()
+
.getBean(FrameworkExecutorRepository.class).getCacheRefreshingScheduledExecutor());
int metadataInfoCacheExpireTime =
registryURL.getParameter(METADATA_INFO_CACHE_EXPIRE_KEY,
DEFAULT_METADATA_INFO_CACHE_EXPIRE);
int metadataInfoCacheSize =
registryURL.getParameter(METADATA_INFO_CACHE_SIZE_KEY,
DEFAULT_METADATA_INFO_CACHE_SIZE);
this.refreshCacheFuture =
applicationModel.getFrameworkModel().getBeanFactory()
-
.getBean(FrameworkExecutorRepository.class).getSharedScheduledExecutor()
- .scheduleAtFixedRate(() -> {
- try {
- while (metadataInfos.size() > metadataInfoCacheSize) {
- AtomicReference<String> oldestRevision = new
AtomicReference<>();
- AtomicReference<MetadataInfoStat> oldestStat = new
AtomicReference<>();
- metadataInfos.forEach((k, v) -> {
- if (System.currentTimeMillis() - v.getUpdateTime()
> metadataInfoCacheExpireTime &&
- (oldestStat.get() == null ||
oldestStat.get().getUpdateTime() > v.getUpdateTime())) {
- oldestRevision.set(k);
- oldestStat.set(v);
+
.getBean(FrameworkExecutorRepository.class).getSharedScheduledExecutor()
+ .scheduleAtFixedRate(() -> {
+ try {
+ while (metadataInfos.size() > metadataInfoCacheSize) {
+ AtomicReference<String> oldestRevision = new
AtomicReference<>();
+ AtomicReference<MetadataInfoStat> oldestStat = new
AtomicReference<>();
+ metadataInfos.forEach((k, v) -> {
+ if (System.currentTimeMillis() -
v.getUpdateTime() > metadataInfoCacheExpireTime &&
+ (oldestStat.get() == null ||
oldestStat.get().getUpdateTime() > v.getUpdateTime())) {
+ oldestRevision.set(k);
+ oldestStat.set(v);
+ }
+ });
+ if (oldestStat.get() != null) {
+ metadataInfos.remove(oldestRevision.get(),
oldestStat.get());
}
- });
- if (oldestStat.get() != null) {
- metadataInfos.remove(oldestRevision.get(),
oldestStat.get());
}
+ } catch (Throwable t) {
+ logger.error(INTERNAL_ERROR, "", "", "Error occurred
when clean up metadata info cache.", t);
}
- } catch (Throwable t) {
- logger.error(INTERNAL_ERROR, "", "", "Error occurred when
clean up metadata info cache.", t);
- }
- }, metadataInfoCacheExpireTime / 2, metadataInfoCacheExpireTime /
2, TimeUnit.MILLISECONDS);
+ }, metadataInfoCacheExpireTime / 2,
metadataInfoCacheExpireTime / 2, TimeUnit.MILLISECONDS);
}
@@ -131,12 +130,11 @@ public abstract class AbstractServiceDiscovery implements
ServiceDiscovery {
if (isDestroy) {
return;
}
- this.serviceInstance = createServiceInstance(this.metadataInfo);
- if (!isValidInstance(this.serviceInstance)) {
- logger.warn(REGISTRY_FAILED_FETCH_INSTANCE, "", "", "No valid
instance found, stop registering instance address to registry.");
+ ServiceInstance serviceInstance =
createServiceInstance(this.metadataInfo);
+ if (!isValidInstance(serviceInstance)) {
return;
}
-
+ this.serviceInstance = serviceInstance;
boolean revisionUpdated =
calOrUpdateInstanceRevision(this.serviceInstance);
if (revisionUpdated) {
reportMetadata(this.metadataInfo);
@@ -156,15 +154,12 @@ public abstract class AbstractServiceDiscovery implements
ServiceDiscovery {
}
if (this.serviceInstance == null) {
- this.serviceInstance = createServiceInstance(this.metadataInfo);
- } else if (!isValidInstance(this.serviceInstance)) {
-
ServiceInstanceMetadataUtils.customizeInstance(this.serviceInstance,
this.applicationModel);
+ register();
}
if (!isValidInstance(this.serviceInstance)) {
return;
}
-
ServiceInstance oldServiceInstance = this.serviceInstance;
DefaultServiceInstance newServiceInstance = new
DefaultServiceInstance((DefaultServiceInstance) oldServiceInstance);
boolean revisionUpdated =
calOrUpdateInstanceRevision(newServiceInstance);
@@ -301,7 +296,7 @@ public abstract class AbstractServiceDiscovery implements
ServiceDiscovery {
* 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)}
+ * and report metadata by {@link
AbstractServiceDiscovery#reportMetadata(MetadataInfo)}
*
* @param oldServiceInstance origin service instance
* @param newServiceInstance new service instance