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

jackietien pushed a commit to branch ty/HA
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/ty/HA by this push:
     new 92357ad1516 delete retry for write api in session pool
92357ad1516 is described below

commit 92357ad1516c60271f14c164320e0cd3150612cc
Author: JackieTien97 <[email protected]>
AuthorDate: Thu Jan 25 13:21:24 2024 +0800

    delete retry for write api in session pool
---
 .../java/org/apache/iotdb/session/Session.java     |    1 -
 .../apache/iotdb/session/SessionConnection.java    |    2 +-
 .../org/apache/iotdb/session/pool/SessionPool.java | 1289 +++++++++-----------
 .../apache/iotdb/commons/utils/StatusUtils.java    |    7 +-
 4 files changed, 608 insertions(+), 691 deletions(-)

diff --git 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
index bf0a53bd8f6..4d0ad33efd7 100644
--- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -1269,7 +1269,6 @@ public class Session implements ISession {
               });
       if (connection == null) {
         deviceIdToEndpoint.remove(deviceId);
-        logger.warn("Can not redirect to {}, because session can not connect 
to it.", endpoint);
       }
     }
   }
diff --git 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
index 1965afd1d89..dc89a55dbd2 100644
--- 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
+++ 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
@@ -1320,7 +1320,7 @@ public class SessionConnection {
             init(endPoint, session.useSSL, session.trustStore, 
session.trustStorePwd);
             connectedSuccess = true;
           } catch (IoTDBConnectionException e) {
-            logger.error("The current node may have been down {},try next 
node", endPoint);
+            logger.warn("The current node may have been down {},try next 
node", endPoint);
             continue;
           }
           break;
diff --git 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
index ef3f5385738..aab6b118391 100644
--- 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
+++ 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
@@ -148,6 +148,10 @@ public class SessionPool implements ISessionPool {
 
   private boolean enableAutoFetch = true;
 
+  protected int maxRetryCount = SessionConfig.MAX_RETRY_COUNT;
+
+  protected long retryIntervalInMs = SessionConfig.RETRY_INTERVAL_IN_MS;
+
   private static final String INSERT_RECORD_FAIL = "insertRecord failed";
 
   private static final String INSERT_RECORD_ERROR_MSG = "unexpected error in 
insertRecord";
@@ -479,6 +483,9 @@ public class SessionPool implements ISessionPool {
     this.useSSL = builder.useSSL;
     this.trustStore = builder.trustStore;
     this.trustStorePwd = builder.trustStorePwd;
+    this.maxRetryCount = builder.maxRetryCount;
+    this.retryIntervalInMs = builder.retryIntervalInMs;
+
     if (enableAutoFetch) {
       initThreadPool();
     }
@@ -529,6 +536,8 @@ public class SessionPool implements ISessionPool {
               .useSSL(useSSL)
               .trustStore(trustStore)
               .trustStorePwd(trustStorePwd)
+              .maxRetryCount(maxRetryCount)
+              .retryIntervalInMs(retryIntervalInMs)
               .build();
     } else {
       // Construct redirect-able Session
@@ -546,6 +555,8 @@ public class SessionPool implements ISessionPool {
               .useSSL(useSSL)
               .trustStore(trustStore)
               .trustStorePwd(trustStorePwd)
+              .maxRetryCount(maxRetryCount)
+              .retryIntervalInMs(retryIntervalInMs)
               .build();
     }
     session.setEnableQueryRedirection(enableQueryRedirection);
@@ -848,24 +859,21 @@ public class SessionPool implements ISessionPool {
      *     3,   3,  3,  3
      */
 
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertTablet(tablet, sorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertTablet failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertTablet", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertTablet(tablet, sorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertTablet failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertTablet", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -894,24 +902,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void insertAlignedTablet(Tablet tablet, boolean sorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedTablet(tablet, sorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedTablet failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertAlignedTablet", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedTablet(tablet, sorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedTablet failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertAlignedTablet", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -946,24 +951,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void insertTablets(Map<String, Tablet> tablets, boolean sorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertTablets(tablets, sorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertTablets failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertTablets", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertTablets(tablets, sorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertTablets failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertTablets", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -976,24 +978,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void insertAlignedTablets(Map<String, Tablet> tablets, boolean sorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedTablets(tablets, sorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedTablets failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertAlignedTablets", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedTablets(tablets, sorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedTablets failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertAlignedTablets", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1013,24 +1012,21 @@ public class SessionPool implements ISessionPool {
       List<List<TSDataType>> typesList,
       List<List<Object>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertRecords(deviceIds, times, measurementsList, typesList, 
valuesList);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertRecords failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(INSERT_RECORDS_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertRecords(deviceIds, times, measurementsList, typesList, 
valuesList);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertRecords failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(INSERT_RECORDS_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1050,25 +1046,22 @@ public class SessionPool implements ISessionPool {
       List<List<TSDataType>> typesList,
       List<List<Object>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedRecords(
-            multiSeriesIds, times, multiMeasurementComponentsList, typesList, 
valuesList);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedRecords failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertAlignedRecords", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedRecords(
+          multiSeriesIds, times, multiMeasurementComponentsList, typesList, 
valuesList);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedRecords failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertAlignedRecords", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1087,25 +1080,22 @@ public class SessionPool implements ISessionPool {
       List<List<TSDataType>> typesList,
       List<List<Object>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertRecordsOfOneDevice(
-            deviceId, times, measurementsList, typesList, valuesList, false);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn(INSERT_RECORDS_OF_ONE_DEVICE_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(INSERT_RECORDS_OF_ONE_DEVICE_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertRecordsOfOneDevice(
+          deviceId, times, measurementsList, typesList, valuesList, false);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn(INSERT_RECORDS_OF_ONE_DEVICE_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(INSERT_RECORDS_OF_ONE_DEVICE_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1126,25 +1116,22 @@ public class SessionPool implements ISessionPool {
       List<List<TSDataType>> typesList,
       List<List<Object>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertRecordsOfOneDevice(
-            deviceId, times, measurementsList, typesList, valuesList, false);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn(INSERT_RECORDS_OF_ONE_DEVICE_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(INSERT_RECORDS_OF_ONE_DEVICE_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertRecordsOfOneDevice(
+          deviceId, times, measurementsList, typesList, valuesList, false);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn(INSERT_RECORDS_OF_ONE_DEVICE_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(INSERT_RECORDS_OF_ONE_DEVICE_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1163,25 +1150,21 @@ public class SessionPool implements ISessionPool {
       List<List<String>> measurementsList,
       List<List<String>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertStringRecordsOfOneDevice(
-            deviceId, times, measurementsList, valuesList, false);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertStringRecordsOfOneDevice failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertStringRecordsOfOneDevice", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertStringRecordsOfOneDevice(deviceId, times, 
measurementsList, valuesList, false);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertStringRecordsOfOneDevice failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertStringRecordsOfOneDevice", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1202,25 +1185,22 @@ public class SessionPool implements ISessionPool {
       List<List<Object>> valuesList,
       boolean haveSorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertRecordsOfOneDevice(
-            deviceId, times, measurementsList, typesList, valuesList, 
haveSorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn(INSERT_RECORDS_OF_ONE_DEVICE_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(INSERT_RECORDS_OF_ONE_DEVICE_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertRecordsOfOneDevice(
+          deviceId, times, measurementsList, typesList, valuesList, 
haveSorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn(INSERT_RECORDS_OF_ONE_DEVICE_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(INSERT_RECORDS_OF_ONE_DEVICE_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1243,25 +1223,22 @@ public class SessionPool implements ISessionPool {
       List<List<Object>> valuesList,
       boolean haveSorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertRecordsOfOneDevice(
-            deviceId, times, measurementsList, typesList, valuesList, 
haveSorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn(INSERT_RECORDS_OF_ONE_DEVICE_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(INSERT_RECORDS_OF_ONE_DEVICE_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertRecordsOfOneDevice(
+          deviceId, times, measurementsList, typesList, valuesList, 
haveSorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn(INSERT_RECORDS_OF_ONE_DEVICE_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(INSERT_RECORDS_OF_ONE_DEVICE_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1282,25 +1259,22 @@ public class SessionPool implements ISessionPool {
       List<List<String>> valuesList,
       boolean haveSorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertStringRecordsOfOneDevice(
-            deviceId, times, measurementsList, valuesList, haveSorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertStringRecordsOfOneDevice failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertStringRecordsOfOneDevice", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertStringRecordsOfOneDevice(
+          deviceId, times, measurementsList, valuesList, haveSorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertStringRecordsOfOneDevice failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertStringRecordsOfOneDevice", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1320,25 +1294,22 @@ public class SessionPool implements ISessionPool {
       List<List<TSDataType>> typesList,
       List<List<Object>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedRecordsOfOneDevice(
-            deviceId, times, measurementsList, typesList, valuesList, false);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedRecordsOfOneDevice failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertAlignedRecordsOfOneDevice", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedRecordsOfOneDevice(
+          deviceId, times, measurementsList, typesList, valuesList, false);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedRecordsOfOneDevice failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertAlignedRecordsOfOneDevice", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1357,25 +1328,21 @@ public class SessionPool implements ISessionPool {
       List<List<String>> measurementsList,
       List<List<String>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedStringRecordsOfOneDevice(
-            deviceId, times, measurementsList, valuesList);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedStringRecordsOfOneDevice failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in 
insertAlignedStringRecordsOfOneDevice", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedStringRecordsOfOneDevice(deviceId, times, 
measurementsList, valuesList);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedStringRecordsOfOneDevice failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in 
insertAlignedStringRecordsOfOneDevice", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1397,25 +1364,23 @@ public class SessionPool implements ISessionPool {
       List<List<Object>> valuesList,
       boolean haveSorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedRecordsOfOneDevice(
-            deviceId, times, measurementsList, typesList, valuesList, 
haveSorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedRecordsOfOneDevice failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertAlignedRecordsOfOneDevice", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedRecordsOfOneDevice(
+          deviceId, times, measurementsList, typesList, valuesList, 
haveSorted);
+      putBack(session);
+      return;
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedRecordsOfOneDevice failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertAlignedRecordsOfOneDevice", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1436,25 +1401,22 @@ public class SessionPool implements ISessionPool {
       List<List<String>> valuesList,
       boolean haveSorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedStringRecordsOfOneDevice(
-            deviceId, times, measurementsList, valuesList, haveSorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedStringRecordsOfOneDevice failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in 
insertAlignedStringRecordsOfOneDevice", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedStringRecordsOfOneDevice(
+          deviceId, times, measurementsList, valuesList, haveSorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedStringRecordsOfOneDevice failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in 
insertAlignedStringRecordsOfOneDevice", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1472,24 +1434,21 @@ public class SessionPool implements ISessionPool {
       List<List<String>> measurementsList,
       List<List<String>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertRecords(deviceIds, times, measurementsList, valuesList);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertRecords failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(INSERT_RECORDS_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertRecords(deviceIds, times, measurementsList, valuesList);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertRecords failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(INSERT_RECORDS_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1507,25 +1466,22 @@ public class SessionPool implements ISessionPool {
       List<List<String>> multiMeasurementComponentsList,
       List<List<String>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedRecords(
-            multiSeriesIds, times, multiMeasurementComponentsList, valuesList);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedRecords failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertAlignedRecords", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedRecords(
+          multiSeriesIds, times, multiMeasurementComponentsList, valuesList);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedRecords failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertAlignedRecords", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1544,24 +1500,21 @@ public class SessionPool implements ISessionPool {
       List<TSDataType> types,
       Object... values)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertRecord(deviceId, time, measurements, types, values);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.error(INSERT_RECORD_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(INSERT_RECORD_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertRecord(deviceId, time, measurements, types, values);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.error(INSERT_RECORD_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(INSERT_RECORD_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1580,24 +1533,21 @@ public class SessionPool implements ISessionPool {
       List<TSDataType> types,
       List<Object> values)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertRecord(deviceId, time, measurements, types, values);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn(INSERT_RECORD_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(INSERT_RECORD_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertRecord(deviceId, time, measurements, types, values);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn(INSERT_RECORD_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(INSERT_RECORD_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1642,24 +1592,21 @@ public class SessionPool implements ISessionPool {
       List<TSDataType> types,
       List<Object> values)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedRecord(multiSeriesId, time, 
multiMeasurementComponents, types, values);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedRecord failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertAlignedRecord", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedRecord(multiSeriesId, time, 
multiMeasurementComponents, types, values);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedRecord failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertAlignedRecord", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1674,24 +1621,21 @@ public class SessionPool implements ISessionPool {
   public void insertRecord(
       String deviceId, long time, List<String> measurements, List<String> 
values)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertRecord(deviceId, time, measurements, values);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn(INSERT_RECORD_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(INSERT_RECORD_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertRecord(deviceId, time, measurements, values);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn(INSERT_RECORD_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(INSERT_RECORD_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1706,52 +1650,46 @@ public class SessionPool implements ISessionPool {
   public void insertAlignedRecord(
       String multiSeriesId, long time, List<String> 
multiMeasurementComponents, List<String> values)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.insertAlignedRecord(multiSeriesId, time, 
multiMeasurementComponents, values);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("insertAlignedRecord failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in insertAlignedRecord", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
-    }
-  }
-
-  /**
-   * This method NOT insert data into database and the server just return 
after accept the request,
-   * this method should be used to test other time cost in client
-   */
-  @Override
-  public void testInsertTablet(Tablet tablet)
-      throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.testInsertTablet(tablet);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("testInsertTablet failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in testInsertTablet", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.insertAlignedRecord(multiSeriesId, time, 
multiMeasurementComponents, values);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("insertAlignedRecord failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in insertAlignedRecord", e);
+      putBack(session);
+      throw new RuntimeException(e);
+    }
+  }
+
+  /**
+   * This method NOT insert data into database and the server just return 
after accept the request,
+   * this method should be used to test other time cost in client
+   */
+  @Override
+  public void testInsertTablet(Tablet tablet)
+      throws IoTDBConnectionException, StatementExecutionException {
+    ISession session = getSession();
+    try {
+      session.testInsertTablet(tablet);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("testInsertTablet failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in testInsertTablet", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1762,24 +1700,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void testInsertTablet(Tablet tablet, boolean sorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.testInsertTablet(tablet, sorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("testInsertTablet failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in testInsertTablet", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.testInsertTablet(tablet, sorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("testInsertTablet failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in testInsertTablet", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1790,24 +1725,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void testInsertTablets(Map<String, Tablet> tablets)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.testInsertTablets(tablets);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("testInsertTablets failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in testInsertTablets", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.testInsertTablets(tablets);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("testInsertTablets failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in testInsertTablets", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1818,24 +1750,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void testInsertTablets(Map<String, Tablet> tablets, boolean sorted)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.testInsertTablets(tablets, sorted);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("testInsertTablets failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in testInsertTablets", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.testInsertTablets(tablets, sorted);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("testInsertTablets failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in testInsertTablets", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1850,24 +1779,21 @@ public class SessionPool implements ISessionPool {
       List<List<String>> measurementsList,
       List<List<String>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.testInsertRecords(deviceIds, times, measurementsList, 
valuesList);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("testInsertRecords failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in testInsertRecords", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.testInsertRecords(deviceIds, times, measurementsList, 
valuesList);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("testInsertRecords failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in testInsertRecords", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1883,24 +1809,21 @@ public class SessionPool implements ISessionPool {
       List<List<TSDataType>> typesList,
       List<List<Object>> valuesList)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.testInsertRecords(deviceIds, times, measurementsList, 
typesList, valuesList);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("testInsertRecords failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in testInsertRecords", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.testInsertRecords(deviceIds, times, measurementsList, typesList, 
valuesList);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("testInsertRecords failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in testInsertRecords", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1912,24 +1835,21 @@ public class SessionPool implements ISessionPool {
   public void testInsertRecord(
       String deviceId, long time, List<String> measurements, List<String> 
values)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.testInsertRecord(deviceId, time, measurements, values);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("testInsertRecord failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in testInsertRecord", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.testInsertRecord(deviceId, time, measurements, values);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("testInsertRecord failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in testInsertRecord", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1945,24 +1865,21 @@ public class SessionPool implements ISessionPool {
       List<TSDataType> types,
       List<Object> values)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.testInsertRecord(deviceId, time, measurements, types, values);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("testInsertRecord failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in testInsertRecord", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.testInsertRecord(deviceId, time, measurements, types, values);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("testInsertRecord failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in testInsertRecord", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1974,24 +1891,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void deleteTimeseries(String path)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.deleteTimeseries(path);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("deleteTimeseries failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in deleteTimeseries", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.deleteTimeseries(path);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("deleteTimeseries failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in deleteTimeseries", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -2003,24 +1917,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void deleteTimeseries(List<String> paths)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.deleteTimeseries(paths);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("deleteTimeseries failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in deleteTimeseries", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.deleteTimeseries(paths);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("deleteTimeseries failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in deleteTimeseries", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -2033,24 +1944,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void deleteData(String path, long time)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.deleteData(path, time);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn(DELETE_DATA_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(DELETE_DATA_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.deleteData(path, time);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn(DELETE_DATA_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(DELETE_DATA_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -2063,24 +1971,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void deleteData(List<String> paths, long time)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.deleteData(paths, time);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn(DELETE_DATA_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(DELETE_DATA_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.deleteData(paths, time);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn(DELETE_DATA_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(DELETE_DATA_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -2094,24 +1999,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void deleteData(List<String> paths, long startTime, long endTime)
       throws IoTDBConnectionException, StatementExecutionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.deleteData(paths, startTime, endTime);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn(DELETE_DATA_FAIL, e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error(DELETE_DATA_ERROR_MSG, e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.deleteData(paths, startTime, endTime);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn(DELETE_DATA_FAIL, e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error(DELETE_DATA_ERROR_MSG, e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -3111,24 +3013,21 @@ public class SessionPool implements ISessionPool {
   @Override
   public void executeNonQueryStatement(String sql)
       throws StatementExecutionException, IoTDBConnectionException {
-    for (int i = 0; i < RETRY; i++) {
-      ISession session = getSession();
-      try {
-        session.executeNonQueryStatement(sql);
-        putBack(session);
-        return;
-      } catch (IoTDBConnectionException e) {
-        // TException means the connection is broken, remove it and get a new 
one.
-        LOGGER.warn("executeNonQueryStatement failed", e);
-        cleanSessionAndMayThrowConnectionException(session, i, e);
-      } catch (StatementExecutionException | RuntimeException e) {
-        putBack(session);
-        throw e;
-      } catch (Throwable e) {
-        LOGGER.error("unexpected error in executeNonQueryStatement", e);
-        putBack(session);
-        throw new RuntimeException(e);
-      }
+    ISession session = getSession();
+    try {
+      session.executeNonQueryStatement(sql);
+      putBack(session);
+    } catch (IoTDBConnectionException e) {
+      // TException means the connection is broken, remove it and get a new 
one.
+      LOGGER.warn("executeNonQueryStatement failed", e);
+      cleanSessionAndMayThrowConnectionException(session, FINAL_RETRY, e);
+    } catch (StatementExecutionException | RuntimeException e) {
+      putBack(session);
+      throw e;
+    } catch (Throwable e) {
+      LOGGER.error("unexpected error in executeNonQueryStatement", e);
+      putBack(session);
+      throw new RuntimeException(e);
     }
   }
 
@@ -3615,6 +3514,10 @@ public class SessionPool implements ISessionPool {
 
     private boolean enableAutoFetch;
 
+    private int maxRetryCount = SessionConfig.MAX_RETRY_COUNT;
+
+    private long retryIntervalInMs = SessionConfig.RETRY_INTERVAL_IN_MS;
+
     public Builder useSSL(boolean useSSL) {
       this.useSSL = useSSL;
       return this;
@@ -3710,6 +3613,16 @@ public class SessionPool implements ISessionPool {
       return this;
     }
 
+    public Builder maxRetryCount(int maxRetryCount) {
+      this.maxRetryCount = maxRetryCount;
+      return this;
+    }
+
+    public Builder retryIntervalInMs(long retryIntervalInMs) {
+      this.retryIntervalInMs = retryIntervalInMs;
+      return this;
+    }
+
     public SessionPool build() {
       return new SessionPool(this);
     }
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/StatusUtils.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/StatusUtils.java
index ba5dfc81160..1d841d05b72 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/StatusUtils.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/StatusUtils.java
@@ -43,12 +43,17 @@ public class StatusUtils {
   private static final CommonConfig COMMON_CONFIG = 
CommonDescriptor.getInstance().getConfig();
 
   static {
+    NEED_RETRY.add(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
+    NEED_RETRY.add(TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
     NEED_RETRY.add(TSStatusCode.DISPATCH_ERROR.getStatusCode());
     NEED_RETRY.add(TSStatusCode.SYSTEM_READ_ONLY.getStatusCode());
     NEED_RETRY.add(TSStatusCode.STORAGE_ENGINE_NOT_READY.getStatusCode());
-    NEED_RETRY.add(TSStatusCode.TIMESERIES_IN_BLACK_LIST.getStatusCode());
+    NEED_RETRY.add(TSStatusCode.WRITE_PROCESS_ERROR.getStatusCode());
     NEED_RETRY.add(TSStatusCode.WAL_ERROR.getStatusCode());
     NEED_RETRY.add(TSStatusCode.DISK_SPACE_INSUFFICIENT.getStatusCode());
+    NEED_RETRY.add(TSStatusCode.QUERY_PROCESS_ERROR.getStatusCode());
+    NEED_RETRY.add(TSStatusCode.INTERNAL_REQUEST_TIME_OUT.getStatusCode());
+    NEED_RETRY.add(TSStatusCode.INTERNAL_REQUEST_RETRY_ERROR.getStatusCode());
     NEED_RETRY.add(TSStatusCode.CREATE_REGION_ERROR.getStatusCode());
     NEED_RETRY.add(TSStatusCode.CONSENSUS_NOT_INITIALIZED.getStatusCode());
     NEED_RETRY.add(TSStatusCode.NO_AVAILABLE_REGION_GROUP.getStatusCode());

Reply via email to