1717
1818package org .apache .servicecomb .service .center .client ;
1919
20- import java .io .IOException ;
21- import java .util .ArrayList ;
2220import java .util .Collections ;
2321import java .util .List ;
2422import 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