Skip to content

Commit 8c6d65a

Browse files
authored
Merge pull request #4878 from chengyouling/2.8.x-cache
[#4877] not clear service instances cache when pull instance exception and add telnet check
2 parents 0cad4cc + 679e266 commit 8c6d65a

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterDiscovery.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.apache.servicecomb.service.center.client;
1919

20-
import java.io.IOException;
21-
import java.util.ArrayList;
2220
import java.util.Collections;
2321
import java.util.List;
2422
import java.util.Map;
@@ -153,13 +151,12 @@ public void onPullInstanceEvent(PullInstanceEvent event) {
153151
startTask(new PullInstanceOnceTask());
154152
}
155153

156-
private List<SubscriptionKey> pullInstance(SubscriptionKey k, SubscriptionValue v, boolean sendChangedEvent) {
154+
private void pullInstance(SubscriptionKey k, SubscriptionValue v, boolean sendChangedEvent) {
157155
if (myselfServiceId == null) {
158156
// registration not ready
159-
return Collections.emptyList();
157+
return;
160158
}
161159

162-
List<SubscriptionKey> failedKeys = new ArrayList<>();
163160
try {
164161
FindMicroserviceInstancesResponse instancesResponse = serviceCenterClient
165162
.findMicroserviceInstance(myselfServiceId, k.appId, k.serviceName, ALL_VERSION, v.revision);
@@ -186,17 +183,9 @@ private List<SubscriptionKey> pullInstance(SubscriptionKey k, SubscriptionValue
186183
}
187184
}
188185
} catch (Exception e) {
189-
if (!(e.getCause() instanceof IOException)) {
190-
// for IOException, do not remove cache, or when service center
191-
// not available, invocation between microservices will fail.
192-
failedKeys.add(k);
193-
LOGGER.error("find service {}#{} instance failed and remove local cache.", k.appId, k.serviceName, e);
194-
} else {
195-
LOGGER.warn("find service {}#{} instance failed, remaining local instances cache, cause message: {}",
196-
k.appId, k.serviceName, e.getMessage());
197-
}
186+
LOGGER.warn("find service {}#{} instance failed, remaining local instances cache [{}], cause message: {}",
187+
k.appId, k.serviceName, instanceToString(v.instancesCache), e.getMessage());
198188
}
199-
return failedKeys;
200189
}
201190

202191
private void setMicroserviceInfo(List<MicroserviceInstance> instances) {
@@ -235,13 +224,9 @@ public void execute() {
235224
}
236225

237226
private synchronized void pullAllInstance() {
238-
List<SubscriptionKey> failedInstances = new ArrayList<>();
239-
instancesCache.forEach((k, v) -> failedInstances.addAll(pullInstance(k, v, true)));
240-
if (failedInstances.isEmpty()) {
241-
return;
242-
}
243-
failedInstances.forEach(instancesCache::remove);
244-
failedInstances.clear();
227+
instancesCache.forEach((k, v) -> {
228+
pullInstance(k, v, true);
229+
});
245230
}
246231

247232
private static String instanceToString(List<MicroserviceInstance> instances) {

0 commit comments

Comments
 (0)