[ 
https://issues.apache.org/jira/browse/SCB-718?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16545972#comment-16545972
 ] 

ASF GitHub Bot commented on SCB-718:
------------------------------------

laijianbin closed pull request #795: [SCB-718] If auto discovery failed , will 
cause a dead cycle
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/795
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/IpPortManager.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/IpPortManager.java
index 0d5db0a6b..97bac81ce 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/IpPortManager.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/IpPortManager.java
@@ -70,13 +70,21 @@ public IpPortManager(ServiceRegistryConfig 
serviceRegistryConfig, InstanceCacheM
     maxRetryTimes = defaultIpPort.size();
   }
 
+  public void setAutoDiscoveryInited(boolean autoDiscoveryInited) {
+    this.autoDiscoveryInited = autoDiscoveryInited;
+  }
+
   // we have to do this operation after the first time setup has already done
   public void initAutoDiscovery() {
     if (!autoDiscoveryInited && 
this.serviceRegistryConfig.isRegistryAutoDiscovery()) {
-      instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
+      InstanceCache cache = instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
           REGISTRY_SERVICE_NAME,
           DefinitionConst.VERSION_RULE_LATEST);
-      autoDiscoveryInited = true;
+      if (cache.getInstanceMap().size() > 0) {
+        setAutoDiscoveryInited(true);
+      } else {
+        setAutoDiscoveryInited(false);
+      }
     }
   }
 
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
index 6e3b933a5..a80e70a1d 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
@@ -26,13 +26,12 @@
 import 
org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl;
 import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
 import 
org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition;
-import org.apache.servicecomb.serviceregistry.task.MicroserviceRegisterTask;
 import org.apache.servicecomb.serviceregistry.task.event.PeriodicPullEvent;
 import 
org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent;
 import org.apache.servicecomb.serviceregistry.task.event.ShutdownEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
+import 
org.apache.servicecomb.serviceregistry.task.MicroserviceInstanceHeartbeatTask;
 import com.google.common.eventbus.EventBus;
 import com.google.common.eventbus.Subscribe;
 
@@ -96,10 +95,8 @@ public void 
onPullMicroserviceVersionsInstancesEvent(PullMicroserviceVersionsIns
   }
 
   @Subscribe
-  public void onMicroserviceRegistryTask(MicroserviceRegisterTask event) {
-    if (event.isRegistered()) {
+  public void onMicroserviceRegistryTask(MicroserviceInstanceRegisterTask 
event) {
       ipPortManager.initAutoDiscovery();
-    }
   }
 
   // for testing
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceInstanceRegisterTask.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceInstanceRegisterTask.java
index f0132b635..5a36ce4bc 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceInstanceRegisterTask.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceInstanceRegisterTask.java
@@ -80,7 +80,7 @@ protected boolean doRegister() {
         instanceId,
         microserviceInstance.getEndpoints(),
         microserviceInstance.getHealthCheck().getTTL());
-
+    this.registered = true;
     return true;
   }
 }
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
index 771b2d9e7..4a1cd11af 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
@@ -122,6 +122,7 @@ public void testGetAvailableAddress(@Injectable 
ServiceRegistryConfig config,
     };
 
     manager.initAutoDiscovery();
+    manager.setAutoDiscoveryInited(true);
     IpPort address4 = manager.getNextAvailableAddress(address3);
     if (address1.getPort() == 9980) {
       Assert.assertEquals("127.0.0.1", address4.getHostOrIp());
@@ -135,6 +136,22 @@ public void testGetAvailableAddress(@Injectable 
ServiceRegistryConfig config,
     IpPort address5 = manager.getNextAvailableAddress(address4);
     Assert.assertEquals("127.0.0.1", address5.getHostOrIp());
     Assert.assertEquals(9980, address5.getPort());
+    
+    manager.initAutoDiscovery();
+    manager.setAutoDiscoveryInited(false);
+    IpPort address6 = manager.getNextAvailableAddress(address3);
+    if (address1.getPort() == 9980) {
+      Assert.assertEquals("127.0.0.1", address6.getHostOrIp());
+      Assert.assertEquals(9980, address6.getPort());
+    } else {
+      address6 = manager.getNextAvailableAddress(address1);
+      Assert.assertEquals("127.0.0.1", address6.getHostOrIp());
+      Assert.assertEquals(9980, address6.getPort());
+    }
+
+    IpPort address7 = manager.getNextAvailableAddress(address6);
+    Assert.assertEquals("127.0.0.1", address7.getHostOrIp());
+    Assert.assertEquals(9981, address7.getPort());
   }
 
   @Test


 

----------------------------------------------------------------
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:
us...@infra.apache.org


> If auto discovery failed , will cause a dead cycle
> --------------------------------------------------
>
>                 Key: SCB-718
>                 URL: https://issues.apache.org/jira/browse/SCB-718
>             Project: Apache ServiceComb
>          Issue Type: Task
>            Reporter: laijianbin
>            Assignee: laijianbin
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to