This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 14c57ba7721ba7c72cbc435ceef3f3e64acb622e
Author: bao.liu <bao....@huawei.com>
AuthorDate: Fri Feb 9 09:32:14 2018 +0800

    remove service count protection
---
 .../serviceregistry/consumer/MicroserviceManager.java | 19 -------------------
 .../consumer/MicroserviceVersions.java                | 14 +++-----------
 .../consumer/TestMicroserviceManager.java             |  5 ++---
 3 files changed, 5 insertions(+), 33 deletions(-)

diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceManager.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceManager.java
index cc3fde5..a94ec1e 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceManager.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceManager.java
@@ -17,10 +17,6 @@
 
 package org.apache.servicecomb.serviceregistry.consumer;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
@@ -55,21 +51,6 @@ public class MicroserviceManager {
     if (!microserviceVersions.isValidated()) {
       // remove this microservice if it does not exist or not registered in 
order to get it back when access it again
       versionsByName.remove(microserviceName);
-    } else {
-      microserviceVersions.updateLastAccessTime();
-    }
-    if (versionsByName.size() >= MAX_NUM_OF_MICROSERVICES) {
-      // do clean up for cache so many things
-      List<MicroserviceVersions> entries = new 
ArrayList<>(versionsByName.size());
-      versionsByName.values().forEach((item) -> {
-        entries.add(item);
-      });
-      Collections.sort(entries, 
Comparator.comparingLong(MicroserviceVersions::getLastAccessedTime));
-      entries.forEach((item) -> {
-        if (versionsByName.size() > MAX_NUM_OF_MICROSERVICES / 2) {
-          versionsByName.remove(item.getMicroserviceName());
-        }
-      });
     }
     return microserviceVersions;
   }
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
index 5616aa2..0b818df 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
@@ -63,7 +63,7 @@ public class MicroserviceVersions {
   // only pendingPullCount is 0, then do a real pull 
   private AtomicInteger pendingPullCount = new AtomicInteger();
 
-  private long lastAccessedTime = -1;
+  private boolean validated = false;
 
   public MicroserviceVersions(AppManager appManager, String appId, String 
microserviceName) {
     this.appManager = appManager;
@@ -77,16 +77,8 @@ public class MicroserviceVersions {
     appManager.getEventBus().register(this);
   }
 
-  public void updateLastAccessTime() {
-    this.lastAccessedTime = System.currentTimeMillis();
-  }
-
   public boolean isValidated() {
-    return this.lastAccessedTime != -1;
-  }
-
-  public long getLastAccessedTime() {
-    return this.lastAccessedTime;
+    return validated;
   }
 
   public String getAppId() {
@@ -136,7 +128,7 @@ public class MicroserviceVersions {
   protected void safeSetInstances(List<MicroserviceInstance> pulledInstances, 
String rev) {
     try {
       setInstances(pulledInstances, rev);
-      updateLastAccessTime();
+      validated = true;
     } catch (Throwable e) {
       LOGGER.error("Failed to setInstances, appId={}, microserviceName={}.",
           getAppId(),
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceManager.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceManager.java
index 046621b..c87504c 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceManager.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceManager.java
@@ -108,12 +108,11 @@ public class TestMicroserviceManager {
       }
     }
 
-    Assert.assertEquals(505, cachedVersions.size());
+    Assert.assertEquals(1005, cachedVersions.size());
     Assert.assertEquals("msName1004", 
cachedVersions.get("msName1004").getMicroserviceName());
     Assert.assertEquals("msName1000", 
cachedVersions.get("msName1000").getMicroserviceName());
     Assert.assertEquals("msName500", 
cachedVersions.get("msName500").getMicroserviceName());
-    Assert.assertEquals(null, cachedVersions.get("msName0"));
-    Assert.assertEquals(null, cachedVersions.get("msName499"));
+    Assert.assertEquals("msName0", 
cachedVersions.get("msName0").getMicroserviceName());
   }
 
   @Test

-- 
To stop receiving notification emails like this one, please contact
ningji...@apache.org.

Reply via email to