Skip to content

Commit 849b3f1

Browse files
committed
[#4902] not deleted cache to ensure that instances are available after the microservice and engine are recovered from exceptions
1 parent 8e00127 commit 849b3f1

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

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

Lines changed: 9 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;
@@ -156,13 +154,12 @@ public void onPullInstanceEvent(PullInstanceEvent event) {
156154
startTask(new PullInstanceOnceTask());
157155
}
158156

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

165-
List<SubscriptionKey> failedKeys = new ArrayList<>();
166163
try {
167164
FindMicroserviceInstancesResponse instancesResponse = serviceCenterClient
168165
.findMicroserviceInstance(myselfServiceId, k.appId, k.serviceName, ALL_VERSION, v.revision);
@@ -189,17 +186,9 @@ private List<SubscriptionKey> pullInstance(SubscriptionKey k, SubscriptionValue
189186
}
190187
}
191188
} catch (Exception e) {
192-
if (!(e.getCause() instanceof IOException)) {
193-
// for IOException, do not remove cache, or when service center
194-
// not available, invocation between microservices will fail.
195-
failedKeys.add(k);
196-
LOGGER.error("find service {}#{} instance failed and remove local cache.", k.appId, k.serviceName, e);
197-
} else {
198-
LOGGER.warn("find service {}#{} instance failed, remaining local instances cache, cause message: {}",
199-
k.appId, k.serviceName, e.getMessage());
200-
}
189+
LOGGER.warn("find service {}#{} instance failed, remaining local instances cache [{}], cause message: {}",
190+
k.appId, k.serviceName, instanceToString(v.instancesCache), e.getMessage());
201191
}
202-
return failedKeys;
203192
}
204193

205194
private void setMicroserviceInfo(List<MicroserviceInstance> instances) {
@@ -245,13 +234,9 @@ public void execute() {
245234
}
246235

247236
private synchronized void pullAllInstance() {
248-
List<SubscriptionKey> failedInstances = new ArrayList<>();
249-
instancesCache.forEach((k, v) -> failedInstances.addAll(pullInstance(k, v, true)));
250-
if (failedInstances.isEmpty()) {
251-
return;
252-
}
253-
failedInstances.forEach(instancesCache::remove);
254-
failedInstances.clear();
237+
instancesCache.forEach((k, v) -> {
238+
pullInstance(k, v, true);
239+
});
255240
}
256241

257242
private static String instanceToString(List<MicroserviceInstance> instances) {
@@ -265,6 +250,8 @@ private static String instanceToString(List<MicroserviceInstance> instances) {
265250
sb.append(endpoint.length() > 64 ? endpoint.substring(0, 64) : endpoint);
266251
sb.append("|");
267252
}
253+
sb.append(instance.getStatus());
254+
sb.append("|");
268255
}
269256
return sb.toString();
270257
}

0 commit comments

Comments
 (0)