You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ca...@apache.org on 2022/10/26 02:48:09 UTC

[iotdb] branch master updated: [IOTDB-4732] Optimize client borrow logic in ClusterIT environment (#7713)

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

caogaofei 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 531f8b3533 [IOTDB-4732] Optimize client borrow logic in ClusterIT environment (#7713)
531f8b3533 is described below

commit 531f8b353349e0436960bdb0d60e8f0e55021ebd
Author: YongzaoDan <33...@users.noreply.github.com>
AuthorDate: Wed Oct 26 10:48:04 2022 +0800

    [IOTDB-4732] Optimize client borrow logic in ClusterIT environment (#7713)
---
 .../java/org/apache/iotdb/it/env/AbstractEnv.java  | 23 +++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractEnv.java b/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractEnv.java
index 994eb323c5..550c2967e0 100644
--- a/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractEnv.java
+++ b/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractEnv.java
@@ -393,6 +393,14 @@ public abstract class AbstractEnv implements BaseEnv {
     this.dataNodeWrapperList = dataNodeWrapperList;
   }
 
+  /**
+   * Get connection to ConfigNode-Leader in ClusterIT environment
+   *
+   * <p>Notice: The caller should always use try-with-resource to invoke this interface in order to
+   * return client to ClientPool automatically
+   *
+   * @return SyncConfigNodeIServiceClient that connects to the ConfigNode-Leader
+   */
   @Override
   public IConfigNodeRPCService.Iface getLeaderConfigNodeConnection()
       throws IOException, InterruptedException {
@@ -402,17 +410,22 @@ public abstract class AbstractEnv implements BaseEnv {
                 new DataNodeClientPoolFactory.SyncConfigNodeIServiceClientPoolFactory());
     for (int i = 0; i < 30; i++) {
       for (ConfigNodeWrapper configNodeWrapper : configNodeWrapperList) {
-        try (SyncConfigNodeIServiceClient client =
-            clientManager.borrowClient(
-                new TEndPoint(configNodeWrapper.getIp(), configNodeWrapper.getPort()))) {
+        try {
+          SyncConfigNodeIServiceClient client =
+              clientManager.borrowClient(
+                  new TEndPoint(configNodeWrapper.getIp(), configNodeWrapper.getPort()));
           TShowClusterResp resp = client.showCluster();
-          // Only the ConfigNodeClient who connects to the ConfigNode-leader
-          // will respond the SUCCESS_STATUS
+
           if (resp.getStatus().getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+            // Only the ConfigNodeClient who connects to the ConfigNode-leader
+            // will respond the SUCCESS_STATUS
             logger.info(
                 "Successfully get connection to the leader ConfigNode: {}",
                 configNodeWrapper.getIpAndPortString());
             return client;
+          } else {
+            // Return client otherwise
+            client.close();
           }
         } catch (Exception e) {
           logger.error(