You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2020/04/16 05:11:42 UTC

[incubator-iotdb] 01/01: add insertMultiple batch in SessionPool

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

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

commit df8f1e74dfe74d5a59541de352c7882dc3786853
Author: qiaojialin <64...@qq.com>
AuthorDate: Thu Apr 16 13:11:22 2020 +0800

    add insertMultiple batch in SessionPool
---
 .../org/apache/iotdb/session/pool/SessionPool.java | 54 ++++++++++++++++++++++
 1 file changed, 54 insertions(+)

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 6aaf1be..43271f1 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
@@ -19,6 +19,7 @@
 package org.apache.iotdb.session.pool;
 
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.ConcurrentMap;
@@ -273,6 +274,59 @@ public class SessionPool {
         String.format("retry to execute statement on %s:%s failed %d times", ip, port, RETRY));
   }
 
+
+  /**
+   * use batch interface to insert data
+   *
+   * @param rowBatchMap multiple batch
+   */
+  public void insertMultipleSortedBatch(Map<String, RowBatch> rowBatchMap)
+      throws IoTDBConnectionException, BatchExecutionException {
+    for (int i = 0; i < RETRY; i++) {
+      Session session = getSession();
+      try {
+        session.insertMultipleDeviceSortedBatch(rowBatchMap);
+        putBack(session);
+        return;
+      } catch (IoTDBConnectionException e) {
+        // TException means the connection is broken, remove it and get a new one.
+        closeSession(session);
+        removeSession();
+      } 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));
+  }
+
+  /**
+   * use batch interface to insert data
+   *
+   * @param rowBatchMap multiple batch
+   */
+  public void insertMultipleBatch(Map<String, RowBatch> rowBatchMap)
+      throws IoTDBConnectionException, BatchExecutionException {
+    for (int i = 0; i < RETRY; i++) {
+      Session session = getSession();
+      try {
+        session.insertMultipleDeviceBatch(rowBatchMap);
+        putBack(session);
+        return;
+      } catch (IoTDBConnectionException e) {
+        // TException means the connection is broken, remove it and get a new one.
+        closeSession(session);
+        removeSession();
+      } 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));
+  }
+
   /**
    * Insert data in batch format, which can reduce the overhead of network. This method is just like
    * jdbc batch insert, we pack some insert request in batch and send them to server If you want