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

hxd pushed a commit to branch IOTDB-693
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit 8245dc15ac675fab977f38851e7d1d0670df68bd
Author: xiangdong huang <[email protected]>
AuthorDate: Fri May 22 15:40:13 2020 +0800

    print more info if the sessionPool retry and fails more than RETRY times
---
 .../org/apache/iotdb/session/pool/SessionPool.java | 115 +++++++--------------
 1 file changed, 35 insertions(+), 80 deletions(-)

diff --git 
a/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java 
b/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
index 7ad90ce..77c3eb0 100644
--- a/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
+++ b/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
@@ -76,6 +76,7 @@ public class SessionPool {
 
   private long timeout; //ms
   private static int RETRY = 3;
+  private static int FINAL_RETRY = RETRY - 1;
   private boolean enableCompression = false;
 
   public SessionPool(String ip, int port, String user, String password, int 
maxSize) {
@@ -221,6 +222,16 @@ public class SessionPool {
     }
   }
 
+  private void mayThrowConnectionException(Session session, int times, 
IoTDBConnectionException e) throws IoTDBConnectionException {
+    closeSession(session);
+    removeSession();
+    if (times == FINAL_RETRY) {
+      throw new IoTDBConnectionException(
+          String.format("retry to execute statement on %s:%s failed %d times: 
%s", ip, port,
+              RETRY, e.getMessage()), e);
+    }
+  }
+
   /**
    * insert the data of a device. For each timestamp, the number of 
measurements is the same.
    *
@@ -267,15 +278,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (BatchExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
 
@@ -304,15 +312,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (BatchExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   /**
@@ -333,15 +338,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (BatchExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   /**
@@ -361,15 +363,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   /**
@@ -386,15 +385,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (BatchExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   /**
@@ -412,15 +408,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (BatchExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   /**
@@ -437,15 +430,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   /**
@@ -463,15 +453,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   /**
@@ -489,15 +476,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   /**
@@ -516,15 +500,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   /**
@@ -543,15 +524,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   public void setStorageGroup(String storageGroupId)
@@ -564,15 +542,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   public void deleteStorageGroup(String storageGroup)
@@ -585,15 +560,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   public void deleteStorageGroups(List<String> storageGroup)
@@ -606,15 +578,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   public void createTimeseries(String path, TSDataType dataType, TSEncoding 
encoding,
@@ -627,15 +596,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   public void createTimeseries(String path, TSDataType dataType, TSEncoding 
encoding,
@@ -651,15 +617,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   public void createMultiTimeseries(List<String> paths, List<TSDataType> 
dataTypes,
@@ -676,15 +639,12 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (BatchExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 
   public boolean checkTimeseriesExists(String path) throws 
IoTDBConnectionException {
@@ -696,12 +656,11 @@ public class SessionPool {
         return resp;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
+    //never go here.
+    return false;
   }
 
   /**
@@ -724,15 +683,14 @@ public class SessionPool {
         return wrapper;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
+    // never go here
+    return null;
   }
 
   /**
@@ -750,14 +708,11 @@ public class SessionPool {
         return;
       } catch (IoTDBConnectionException e) {
         // TException means the connection is broken, remove it and get a new 
one.
-        closeSession(session);
-        removeSession();
+        mayThrowConnectionException(session, i, e);
       } catch (StatementExecutionException e) {
         putBack(session);
         throw e;
       }
     }
-    throw new IoTDBConnectionException(
-        String.format("retry to execute statement on %s:%s failed %d times", 
ip, port, RETRY));
   }
 }

Reply via email to