maxucheng0 opened a new issue, #2820:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2820

   
RefreshableMicroserviceCache缓存会在pullInstance后更新记录的revisionId,如果在safemode期间pullInstance成功了会导致此处rev被更新的和sc中的一致,在退出安全模式后携带此rev再次pullInstance时如果此时实例在sc中未有变更会直接响应304,不会触发缓存刷新,导致在安全模式中不老化的实例无法正常下线。
   以下为用例复现:
   `@Test
     public void refresh_exit_safe_mode_down_old_instance() {
       ArrayList<MicroserviceInstance> instances = new ArrayList<>();
       findServiceInstancesOprHolder.value = params -> {
         Assert.assertEquals("consumerId", params[0]);
         Assert.assertEquals("app", params[1]);
         Assert.assertEquals("svc", params[2]);
         Assert.assertEquals("0.0.0.0+", params[3]);
         MicroserviceInstances microserviceInstances = new 
MicroserviceInstances();
         
microserviceInstances.setNeedRefresh(!String.valueOf(instances.hashCode()).equals(params[4]));
         
microserviceInstances.setRevision(String.valueOf(instances.hashCode()));
         microserviceInstances.setMicroserviceNotExist(false);
   
         FindInstancesResponse instancesResponse = new FindInstancesResponse();
         instancesResponse.setInstances(instances);
   
         microserviceInstances.setInstancesResponse(instancesResponse);
         return microserviceInstances;
       };
   
       // at the beginning, no instances in cache
       List<MicroserviceInstance> cachedInstances = 
microserviceCache.getInstances();
       Assert.assertEquals(0, cachedInstances.size());
       Assert.assertNull(microserviceCache.getRevisionId());
   
       // find 1 instance from sc
       MicroserviceInstance microserviceInstance = new MicroserviceInstance();
       instances.add(microserviceInstance);
       microserviceInstance.setInstanceId("instanceId00");
   
       microserviceCache.refresh();
       Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, 
microserviceCache.getStatus());
   
       cachedInstances = microserviceCache.getInstances();
       Assert.assertEquals(1, cachedInstances.size());
       MicroserviceInstance instance = cachedInstances.iterator().next();
       Assert.assertEquals("instanceId00", instance.getInstanceId());
       Assert.assertEquals("-738005329", microserviceCache.getRevisionId());
   
       // 2nd time, clear pull instances
       MicroserviceInstance microserviceInstance1 = new MicroserviceInstance();
       instances.clear();
       instances.add(microserviceInstance1);
       microserviceInstance1.setInstanceId("instanceId01");
   
       microserviceCache.refresh();
       Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, 
microserviceCache.getStatus());
       cachedInstances = microserviceCache.getInstances();
       Assert.assertEquals(1, cachedInstances.size());
       Assert.assertEquals("instanceId01", 
cachedInstances.get(0).getInstanceId());
   
       // 3nd time, 进入安全模式,第三次拉取不下线实例
       microserviceCache.onSafeModeChanged(new SafeModeChangeEvent(true));
   
       MicroserviceInstance microserviceInstance2 = new MicroserviceInstance();
       instances.clear();
       instances.add(microserviceInstance2);
       microserviceInstance2.setInstanceId("instanceId02");
   
       microserviceCache.refresh();
       Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, 
microserviceCache.getStatus());
   
       cachedInstances = microserviceCache.getInstances();
       Assert.assertEquals(2, cachedInstances.size());
       Assert.assertEquals("instanceId02", 
cachedInstances.get(0).getInstanceId());
       Assert.assertEquals("instanceId01", 
cachedInstances.get(1).getInstanceId());
   
       // 4nd time, 退出安全模式,第四次拉取需要下线实例
       microserviceCache.onSafeModeChanged(new SafeModeChangeEvent(false));
   
       microserviceCache.refresh();
       Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, 
microserviceCache.getStatus());
   
       cachedInstances = microserviceCache.getInstances();
       Assert.assertEquals(1, cachedInstances.size());
       Assert.assertEquals("instanceId02", 
cachedInstances.get(0).getInstanceId());
     }`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to