You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/01/08 02:20:47 UTC

[GitHub] wujimin commented on a change in pull request #486: [SCB-165] Service registry not given proper instances

wujimin commented on a change in pull request #486: [SCB-165] Service registry not given proper instances
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/486#discussion_r160068678
 
 

 ##########
 File path: service-registry/src/main/java/io/servicecomb/serviceregistry/client/IpPortManager.java
 ##########
 @@ -65,45 +66,47 @@ public IpPortManager(ServiceRegistryConfig serviceRegistryConfig, InstanceCacheM
 
   // we have to do this operation after the first time setup has already done
   public void initAutoDiscovery() {
-    if (this.serviceRegistryConfig.isRegistryAutoDiscovery()) {
-      instanceCache = instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
+    if (!autoDiscoveryInited && this.serviceRegistryConfig.isRegistryAutoDiscovery()) {
+      instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
           REGISTRY_SERVICE_NAME,
           DefinitionConst.VERSION_RULE_LATEST);
+      autoDiscoveryInited = true;
     }
   }
 
-  public IpPort getAvailableAddress(boolean invalidate) {
-    int index;
-    if (invalidate) {
-      index = currentAvailableIndex.incrementAndGet();
-    } else {
-      index = currentAvailableIndex.get();
+  public IpPort getNextAvailableAddress(IpPort failedIpPort) {
+    IpPort current = getAvailableAddress();
+    if (current.equals(failedIpPort)) {
+      currentAvailableIndex.incrementAndGet();
 
 Review comment:
   multiple threads all run with "current.equals(failedIpPort) return true", then cause inc multiple times
   
   so we should record old index when enter "public IpPort getNextAvailableAddress(IpPort failedIpPort)", and then assign currentAvailableIndex = old + 1 or use compareAndSet

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services