This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch 2.8.x
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/2.8.x by this push:
new fd35498a2 [SCB-2804]Fix instance not found when instances frequently
change (#3926)
fd35498a2 is described below
commit fd35498a27b26ce2e81496ae64e603db9eaa4867
Author: liubao68 <[email protected]>
AuthorDate: Wed Aug 30 15:27:24 2023 +0800
[SCB-2804]Fix instance not found when instances frequently change (#3926)
---
.../servicecomb/registry/RegistrationManager.java | 12 +++--
.../event/MicroserviceInstanceChangedEvent.java | 3 ++
.../servicecomb/registry/consumer/AppManager.java | 8 +--
.../registry/consumer/MicroserviceManager.java | 20 +++++---
.../registry/consumer/MicroserviceVersions.java | 27 ----------
.../discovery/AbstractDiscoveryFilter.java | 6 ++-
.../registry/swagger/SwaggerLoader.java | 37 +++++++++-----
.../registry/discovery/TestDiscoveryTree.java | 58 +++++++++++++++++++++-
.../reference/TestCseClientHttpRequest.java | 2 +
.../async/CseAsyncClientHttpRequestTest.java | 2 +
.../servicecomb/serviceregistry/RegistryUtils.java | 8 ++-
.../registry/AbstractServiceRegistry.java | 2 -
.../servicecomb/serviceregistry/TestConsumers.java | 6 +--
13 files changed, 124 insertions(+), 67 deletions(-)
diff --git
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/RegistrationManager.java
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/RegistrationManager.java
index be59114a5..f3c61b0e1 100644
---
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/RegistrationManager.java
+++
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/RegistrationManager.java
@@ -28,7 +28,6 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import com.google.common.annotations.VisibleForTesting;
import org.apache.http.client.utils.URIBuilder;
import
org.apache.servicecomb.foundation.common.event.EnableExceptionPropagation;
import org.apache.servicecomb.foundation.common.event.EventManager;
@@ -51,6 +50,7 @@ import org.apache.servicecomb.registry.swagger.SwaggerLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.eventbus.Subscribe;
import com.netflix.config.DynamicPropertyFactory;
@@ -64,10 +64,10 @@ public class RegistrationManager {
private static final String PUBLISH_PORT =
"servicecomb.{transport_name}.publishPort";
- private static final SwaggerLoader swaggerLoader = new SwaggerLoader();
-
public static RegistrationManager INSTANCE = new RegistrationManager();
+ private final SwaggerLoader swaggerLoader = new SwaggerLoader();
+
private final List<Registration> registrationList = new ArrayList<>();
private Registration primary;
@@ -85,6 +85,11 @@ public class RegistrationManager {
RegistrationManager.INSTANCE = INSTANCE;
}
+ @VisibleForTesting
+ public static void renewInstance() {
+ RegistrationManager.INSTANCE = new RegistrationManager();
+ }
+
public MicroserviceInstance getMicroserviceInstance() {
return primary.getMicroserviceInstance();
}
@@ -308,7 +313,6 @@ public class RegistrationManager {
.getHostAddress();
}
-
return new IpPort(publicAddressSetting, publishPort);
}
diff --git
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/event/MicroserviceInstanceChangedEvent.java
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/event/MicroserviceInstanceChangedEvent.java
index c850be99e..42d86940f 100644
---
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/event/MicroserviceInstanceChangedEvent.java
+++
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/event/MicroserviceInstanceChangedEvent.java
@@ -23,6 +23,9 @@ import
org.apache.servicecomb.registry.api.registry.WatchAction;
/**
* Created by on 2016/12/25.
+ *
+ * This event is sent by service-center watcher, and indicates the
status(CREATE/UPDATE/DELETE, etc.)
+ * of one instance change.
*/
public class MicroserviceInstanceChangedEvent {
private WatchAction action;
diff --git
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/AppManager.java
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/AppManager.java
index f149516e9..ef72228c2 100644
---
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/AppManager.java
+++
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/AppManager.java
@@ -23,7 +23,7 @@ import java.util.concurrent.CompletableFuture;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.event.EventManager;
-import
org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent;
+import org.apache.servicecomb.registry.api.MicroserviceKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,13 +70,13 @@ public class AppManager {
return
microserviceManager.getOrCreateMicroserviceVersions(microserviceName);
}
- public void onMicroserviceInstanceChanged(MicroserviceInstanceChangedEvent
changedEvent) {
- MicroserviceManager microserviceManager =
apps.get(changedEvent.getKey().getAppId());
+ public void onMicroserviceInstancesChanged(MicroserviceKey microserviceKey) {
+ MicroserviceManager microserviceManager =
apps.get(microserviceKey.getAppId());
if (microserviceManager == null) {
return;
}
- microserviceManager.onMicroserviceInstanceChanged(changedEvent);
+ microserviceManager.onMicroserviceInstancesChanged(microserviceKey);
}
public void pullInstances() {
diff --git
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java
index e873a94db..226bd7323 100644
---
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java
+++
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java
@@ -18,11 +18,12 @@
package org.apache.servicecomb.registry.consumer;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import
org.apache.servicecomb.foundation.vertx.executor.SinglePoolBlockingExecutor;
-import
org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent;
+import org.apache.servicecomb.registry.api.MicroserviceKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,7 +51,7 @@ public class MicroserviceManager {
}
/**
- * update instance information triggered by first timeout pull
+ * update instance information triggered by first time pull
*/
public MicroserviceVersions getOrCreateMicroserviceVersions(String
microserviceName) {
// do not use ConcurrentHashMap computeIfAbsent for versionsByName
@@ -126,14 +127,17 @@ public class MicroserviceManager {
}
/**
- * update instance information triggered by event
+ * Update instance information triggered by event, called when instance list
changed.
*/
- public void onMicroserviceInstanceChanged(MicroserviceInstanceChangedEvent
changedEvent) {
+ public void onMicroserviceInstancesChanged(MicroserviceKey microserviceKey) {
synchronized (lock) {
- for (MicroserviceVersions microserviceVersions :
versionsByName.values()) {
- microserviceVersions.onMicroserviceInstanceChanged(changedEvent);
-
- tryRemoveInvalidMicroservice(microserviceVersions);
+ for (Entry<String, MicroserviceVersions> item :
versionsByName.entrySet()) {
+ if (item.getKey().equals(microserviceKey.getServiceName())) {
+ versionsByName.remove(item.getKey());
+ item.getValue().destroy();
+ LOGGER.info("remove microservice version when instance changed,
appId={}, microserviceName={}.",
+ appId, item.getKey());
+ }
}
}
}
diff --git
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
index 563f872b6..c2c2446ba 100644
---
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
+++
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
@@ -32,7 +32,6 @@ import
org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.registry.DiscoveryManager;
import org.apache.servicecomb.registry.api.event.CreateMicroserviceEvent;
import org.apache.servicecomb.registry.api.event.DestroyMicroserviceEvent;
-import
org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent;
import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.registry.api.registry.MicroserviceInstanceStatus;
import org.apache.servicecomb.registry.api.registry.MicroserviceInstances;
@@ -298,32 +297,6 @@ public class MicroserviceVersions {
return microserviceVersionRule;
}
- public void onMicroserviceInstanceChanged(MicroserviceInstanceChangedEvent
changedEvent) {
- if (!isEventAccept(changedEvent)) {
- return;
- }
- // pull instances always replace old instances, not append
- //
- // pull result and watch event sequence is not defined even inside SC.
- // it's not safe to trust the event, so we just send a new pull request
- //
- // CREATE/UPDATE:
- // if pull 1/2/3, and then add 4, but "add 4" received before pull
result, will lost 4.
- // DELETE:
- // if pull 1/2/3, and then delete 3, but "delete 3" received before pull
result, will have wrong 3.
- // EXPIRE::
- // black/white config in SC changed, we must refresh all data from sc.
- pullInstances();
- }
-
- protected boolean isEventAccept(MicroserviceInstanceChangedEvent
changedEvent) {
- return (appId.equals(changedEvent.getKey().getAppId()) &&
- microserviceName.equals(changedEvent.getKey().getServiceName())) ||
- microserviceName.equals(
- changedEvent.getKey().getAppId() +
DefinitionConst.APP_SERVICE_SEPARATOR + changedEvent.getKey()
- .getServiceName());
- }
-
public void destroy() {
synchronized (lock) {
for (MicroserviceVersion microserviceVersion : versions.values()) {
diff --git
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/discovery/AbstractDiscoveryFilter.java
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/discovery/AbstractDiscoveryFilter.java
index 36e88770e..d77a9227f 100644
---
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/discovery/AbstractDiscoveryFilter.java
+++
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/discovery/AbstractDiscoveryFilter.java
@@ -18,6 +18,7 @@
package org.apache.servicecomb.registry.discovery;
import java.util.HashMap;
+import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,9 +40,12 @@ public abstract class AbstractDiscoveryFilter implements
DiscoveryFilter {
String childName = findChildName(context, parent);
DiscoveryTreeNode node = parent.child(childName);
if (node == null) {
- LOGGER.warn("discovery filter {} return null.",
this.getClass().getName());
+ LOGGER.warn("discovery filter {}/{} return null.",
this.getClass().getName(), childName);
return new DiscoveryTreeNode().subName(parent, "empty").data(new
HashMap<>());
}
+ if (node.data() == null || ((Map<?, ?>) node.data()).isEmpty()) {
+ LOGGER.info("discovery filter {}/{} return empty data.",
this.getClass().getName(), childName);
+ }
return node;
}
diff --git
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/swagger/SwaggerLoader.java
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/swagger/SwaggerLoader.java
index 8d08d24e2..6c49ae442 100644
---
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/swagger/SwaggerLoader.java
+++
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/swagger/SwaggerLoader.java
@@ -52,6 +52,9 @@ public class SwaggerLoader {
// third key : schemaId
private final Map<String, Map<String, Map<String, Swagger>>> apps = new
ConcurrentHashMapEx<>();
+ // first key: appId + microservice short name + service id
+ private final Map<String, Swagger> remoteSwagger = new
ConcurrentHashMapEx<>();
+
public SwaggerLoader() {
}
@@ -117,7 +120,7 @@ public class SwaggerLoader {
apps.computeIfAbsent(appId, k -> new ConcurrentHashMapEx<>())
.computeIfAbsent(shortName, k -> new ConcurrentHashMapEx<>())
.put(schemaId, swagger);
- LOGGER.info("register swagger appId={}, name={}, schemaId={}.", appId,
shortName, schemaId);
+ LOGGER.debug("register swagger appId={}, name={}, schemaId={}.", appId,
shortName, schemaId);
}
public void unregisterSwagger(String appId, String shortName, String
schemaId) {
@@ -136,7 +139,7 @@ public class SwaggerLoader {
}
public Swagger loadLocalSwagger(String appId, String shortName, String
schemaId) {
- LOGGER.info("try to load schema locally, appId=[{}], serviceName=[{}],
schemaId=[{}]",
+ LOGGER.debug("try to load schema locally, appId=[{}], serviceName=[{}],
schemaId=[{}]",
appId, shortName, schemaId);
Swagger swagger = loadFromMemory(appId, shortName, schemaId);
if (swagger != null) {
@@ -178,17 +181,25 @@ public class SwaggerLoader {
private Swagger loadFromRemote(Microservice microservice,
Collection<MicroserviceInstance> instances,
String schemaId) {
- String schemaContent =
DiscoveryManager.INSTANCE.getSchema(microservice.getServiceId(), instances,
schemaId);
- if (schemaContent != null) {
- LOGGER.info(
- "load schema from service center, appId={}, microserviceName={},
version={}, serviceId={}, schemaId={}.",
- microservice.getAppId(),
- microservice.getServiceName(),
- microservice.getVersion(),
- microservice.getServiceId(),
- schemaId);
- LOGGER.debug(schemaContent);
- return SwaggerUtils.parseAndValidateSwagger(schemaContent);
+ String key = microservice.getServiceId() + "." + schemaId;
+ Swagger result = remoteSwagger.computeIfAbsent(key, k -> {
+ String schemaContent =
DiscoveryManager.INSTANCE.getSchema(microservice.getServiceId(), instances,
schemaId);
+ if (schemaContent != null) {
+ LOGGER.info(
+ "load schema from service center, appId={}, microserviceName={},
version={}, serviceId={}, schemaId={}.",
+ microservice.getAppId(),
+ microservice.getServiceName(),
+ microservice.getVersion(),
+ microservice.getServiceId(),
+ schemaId);
+ LOGGER.debug(schemaContent);
+ return SwaggerUtils.parseAndValidateSwagger(schemaContent);
+ }
+ return null;
+ });
+
+ if (result != null) {
+ return result;
}
LOGGER.warn("no schema in local, and can not get schema from service
center, "
diff --git
a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
index 4aed14238..4868654ca 100644
---
a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
+++
b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
@@ -18,7 +18,12 @@
package org.apache.servicecomb.registry.discovery;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.foundation.common.cache.VersionedCache;
@@ -26,6 +31,8 @@ import
org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.DiscoveryManager;
+import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.registry.api.registry.MicroserviceInstanceStatus;
import org.apache.servicecomb.registry.cache.InstanceCacheManager;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
@@ -42,6 +49,7 @@ public class TestDiscoveryTree {
public void before() {
ConfigUtil.installDynamicConfig();
}
+
@AfterEach
public void tearDown() {
ArchaiusUtils.resetConfig();
@@ -176,7 +184,6 @@ public class TestDiscoveryTree {
Mockito.when(DiscoveryManager.INSTANCE.getInstanceCacheManager()).thenReturn(instanceCacheManager);
Mockito.when(instanceCacheManager.getOrCreateVersionedCache(null, null,
null)).thenReturn(parent);
-
result = discoveryTree.discovery(context, null, null, null);
Assertions.assertEquals(parent.name(), result.name());
Assertions.assertEquals(parent.cacheVersion(), result.cacheVersion());
@@ -203,7 +210,7 @@ public class TestDiscoveryTree {
discoveryTree.addFilter(filter);
ServiceCombException exception =
Assertions.assertThrows(ServiceCombException.class,
- () -> result = discoveryTree.discovery(context, null, null, null));
+ () -> result = discoveryTree.discovery(context, null, null, null));
Assertions.assertEquals(filter.getClass().getName() + " discovery return
null.", exception.getMessage());
}
@@ -278,4 +285,51 @@ public class TestDiscoveryTree {
Assertions.assertEquals(inputCache.cacheVersion(), root.cacheVersion());
Assertions.assertNotSame(discoveryTree.getRoot(), root);
}
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void test_one_service_concurrent_correct() throws Exception {
+ DiscoveryTree discoveryTree = new DiscoveryTree();
+ DiscoveryContext discoveryContext = new DiscoveryContext();
+ discoveryTree.addFilter(new InstanceStatusDiscoveryFilter());
+
+ Map<String, MicroserviceInstance> service1 = new HashMap<>();
+ MicroserviceInstance instance1 = Mockito.mock(MicroserviceInstance.class);
+ MicroserviceInstance instance2 = Mockito.mock(MicroserviceInstance.class);
+ Mockito.when(instance1.getInstanceId()).thenReturn("instance1");
+
Mockito.when(instance1.getStatus()).thenReturn(MicroserviceInstanceStatus.UP);
+ Mockito.when(instance2.getInstanceId()).thenReturn("instance2");
+
Mockito.when(instance2.getStatus()).thenReturn(MicroserviceInstanceStatus.UP);
+ service1.put(instance1.getInstanceId(), instance1);
+ service1.put(instance2.getInstanceId(), instance2);
+
+ InstanceCacheManager instanceCacheManager =
Mockito.mock(InstanceCacheManager.class);
+ DiscoveryManager.INSTANCE = Mockito.spy(DiscoveryManager.INSTANCE);
+
Mockito.when(DiscoveryManager.INSTANCE.getInstanceCacheManager()).thenReturn(instanceCacheManager);
+
+ VersionedCache expects0 = new
VersionedCache().autoCacheVersion().name("0+").data(service1);
+ VersionedCache[] expects999 = new VersionedCache[999];
+ for (int i = 0; i < 999; i++) {
+ expects999[i] = new
VersionedCache().name("0+").data(service1).cacheVersion(i + 1);
+ }
+ Mockito.when(instanceCacheManager.getOrCreateVersionedCache("app",
"service1",
+ "0+")).thenReturn(expects0, expects999);
+
+ CountDownLatch countDownLatch = new CountDownLatch(1000);
+ AtomicInteger success = new AtomicInteger(0);
+ for (int i = 0; i < 10; i++) {
+ new Thread(() -> {
+ for (int j = 0; j < 100; j++) {
+ DiscoveryTreeNode result = discoveryTree.discovery(discoveryContext,
"app", "service1", "0+");
+ if (((Map<String, MicroserviceInstance>) result.data()).size() == 2)
{
+ success.getAndIncrement();
+ }
+ countDownLatch.countDown();
+ }
+ }).start();
+ }
+
+ countDownLatch.await(3000, TimeUnit.MILLISECONDS);
+ Assertions.assertEquals(1000, success.get());
+ }
}
diff --git
a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
index 779711805..50dc59bce 100644
---
a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
+++
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
@@ -25,6 +25,7 @@ import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.DiscoveryManager;
+import org.apache.servicecomb.registry.RegistrationManager;
import org.apache.servicecomb.swagger.invocation.Response;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
@@ -52,6 +53,7 @@ public class TestCseClientHttpRequest {
public static void classTeardown() {
scbEngine.destroy();
DiscoveryManager.renewInstance();
+ RegistrationManager.renewInstance();
ArchaiusUtils.resetConfig();
}
diff --git
a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
index c58d77b37..6045044b0 100644
---
a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
+++
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
@@ -28,6 +28,7 @@ import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import
org.apache.servicecomb.provider.springmvc.reference.CseClientHttpResponse;
import org.apache.servicecomb.registry.DiscoveryManager;
+import org.apache.servicecomb.registry.RegistrationManager;
import org.apache.servicecomb.swagger.invocation.Response;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
@@ -55,6 +56,7 @@ public class CseAsyncClientHttpRequestTest {
public static void classTeardown() {
scbEngine.destroy();
DiscoveryManager.renewInstance();
+ RegistrationManager.renewInstance();
ArchaiusUtils.resetConfig();
}
diff --git
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
index 72022f6a1..fb398bba8 100644
---
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
+++
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
@@ -36,6 +36,7 @@ import
org.apache.servicecomb.foundation.common.event.EnableExceptionPropagation
import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.registry.DiscoveryManager;
+import org.apache.servicecomb.registry.api.MicroserviceKey;
import
org.apache.servicecomb.registry.api.event.MicroserviceInstanceRegisteredEvent;
import org.apache.servicecomb.registry.api.registry.FindInstancesResponse;
import org.apache.servicecomb.registry.api.registry.Microservice;
@@ -97,7 +98,12 @@ public final class RegistryUtils {
executeOnEachServiceRegistry(serviceRegistries::add);
aggregateServiceRegistryCache = new
AggregateServiceRegistryCache(serviceRegistries);
aggregateServiceRegistryCache
- .setCacheRefreshedWatcher(refreshedCaches ->
DiscoveryManager.INSTANCE.getAppManager().pullInstances());
+ .setCacheRefreshedWatcher(refreshedCaches -> {
+ MicroserviceKey microserviceKey = new MicroserviceKey();
+ microserviceKey.setAppId(refreshedCaches.get(0).getKey().getAppId());
+
microserviceKey.setServiceName(refreshedCaches.get(0).getKey().getServiceName());
+
DiscoveryManager.INSTANCE.getAppManager().onMicroserviceInstancesChanged(microserviceKey);
+ });
executeOnEachServiceRegistry(
serviceRegistry -> serviceRegistry
diff --git
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
index cf32dde8c..0640a5933 100644
---
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
+++
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
@@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.configuration.Configuration;
import
org.apache.servicecomb.foundation.common.concurrency.SuppressedRunnableWrapper;
-import org.apache.servicecomb.registry.DiscoveryManager;
import
org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent;
import org.apache.servicecomb.registry.api.registry.BasePath;
import org.apache.servicecomb.registry.api.registry.Microservice;
@@ -277,7 +276,6 @@ public abstract class AbstractServiceRegistry implements
ServiceRegistry {
executorService.execute(new SuppressedRunnableWrapper(
() -> {
serviceRegistryCache.onMicroserviceInstanceChanged(changedEvent);
-
DiscoveryManager.INSTANCE.getAppManager().onMicroserviceInstanceChanged(changedEvent);
}));
} catch (Exception e) {
LOGGER.info("instance changed event ignored, {}", e.getMessage());
diff --git
a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/TestConsumers.java
b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/TestConsumers.java
index 977a5e2f2..1458cf1e5 100644
---
a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/TestConsumers.java
+++
b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/TestConsumers.java
@@ -23,7 +23,6 @@ import
org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
import org.apache.servicecomb.registry.DiscoveryManager;
import org.apache.servicecomb.registry.RegistrationManager;
import org.apache.servicecomb.registry.api.MicroserviceKey;
-import
org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent;
import org.apache.servicecomb.registry.api.registry.Microservice;
import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.registry.consumer.MicroserviceVersion;
@@ -83,12 +82,9 @@ public class TestConsumers extends TestRegistryBase {
mockNotExist();
MicroserviceKey key = new MicroserviceKey();
- MicroserviceInstanceChangedEvent event = new
MicroserviceInstanceChangedEvent();
- event.setKey(key);
-
key.setAppId(appId);
key.setServiceName(serviceName);
- eventBus.post(event);
+ microserviceManager.onMicroserviceInstancesChanged(key);
long begin = System.currentTimeMillis();
while (microserviceManager.getVersionsByName().size() > 0 &&
System.currentTimeMillis() - begin < 1000) {
Thread.yield();