You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2022/04/28 11:37:00 UTC

[iotdb] branch master updated: ConfignodeClient reconnect without random pick (#5717)

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

tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 2c1ef036ea ConfignodeClient reconnect without random pick (#5717)
2c1ef036ea is described below

commit 2c1ef036eae4bae8c13961157ff7460bbb087e29
Author: Mrquan <50...@users.noreply.github.com>
AuthorDate: Thu Apr 28 19:36:54 2022 +0800

    ConfignodeClient reconnect without random pick (#5717)
    
    * [MPP] Reconnect without random pick
    
    * [MPP] Reconnect without random pick
---
 .../apache/iotdb/db/client/ConfigNodeClient.java    | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/client/ConfigNodeClient.java b/server/src/main/java/org/apache/iotdb/db/client/ConfigNodeClient.java
index 24b232554a..15bdd581af 100644
--- a/server/src/main/java/org/apache/iotdb/db/client/ConfigNodeClient.java
+++ b/server/src/main/java/org/apache/iotdb/db/client/ConfigNodeClient.java
@@ -51,7 +51,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.List;
-import java.util.Random;
 
 public class ConfigNodeClient {
   private static final Logger logger = LoggerFactory.getLogger(ConfigNodeClient.class);
@@ -71,6 +70,8 @@ public class ConfigNodeClient {
 
   private List<TEndPoint> configNodes;
 
+  private int cursor = 0;
+
   public ConfigNodeClient() throws BadNodeUrlException, IoTDBConnectionException {
     // Read config nodes from configuration
     configNodes =
@@ -123,21 +124,14 @@ public class ConfigNodeClient {
       }
     }
 
-    Random random = new Random();
     if (transport != null) {
       transport.close();
     }
-    int currHostIndex = random.nextInt(configNodes.size());
-    int tryHostNum = 0;
-    for (int j = currHostIndex; j < configNodes.size(); j++) {
-      if (tryHostNum == configNodes.size()) {
-        break;
-      }
-      TEndPoint tryEndpoint = configNodes.get(j);
-      if (j == configNodes.size() - 1) {
-        j = -1;
-      }
-      tryHostNum++;
+
+    for (int tryHostNum = 0; tryHostNum < configNodes.size(); tryHostNum++) {
+      cursor = (cursor + 1) % configNodes.size();
+      TEndPoint tryEndpoint = configNodes.get(cursor);
+
       try {
         connect(tryEndpoint);
         return;
@@ -145,6 +139,7 @@ public class ConfigNodeClient {
         logger.warn("The current node may have been down {},try next node", tryEndpoint);
       }
     }
+
     throw new IoTDBConnectionException(MSG_RECONNECTION_FAIL);
   }