You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2021/05/14 07:10:10 UTC

[iotdb] branch AutoClose created (now 6d1c627)

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

jackietien pushed a change to branch AutoClose
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at 6d1c627  auto close the dataset while there is no more data

This branch includes the following new commits:

     new 6d1c627  auto close the dataset while there is no more data

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[iotdb] 01/01: auto close the dataset while there is no more data

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6d1c6270f13d1eac3f12ac587e823fd2e158b240
Author: JackieTien97 <Ja...@foxmail.com>
AuthorDate: Fri May 14 15:07:17 2021 +0800

    auto close the dataset while there is no more data
---
 .../iotdb/jdbc/IoTDBNonAlignJDBCResultSet.java     | 23 +++++++++++++---------
 .../java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java | 20 ++++++++++++++++---
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignJDBCResultSet.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignJDBCResultSet.java
index c78644c..6cb2336 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignJDBCResultSet.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignJDBCResultSet.java
@@ -19,6 +19,17 @@
 
 package org.apache.iotdb.jdbc;
 
+import static org.apache.iotdb.rpc.IoTDBRpcDataSet.START_INDEX;
+import static org.apache.iotdb.rpc.IoTDBRpcDataSet.TIMESTAMP_STR;
+
+import java.nio.ByteBuffer;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 import org.apache.iotdb.rpc.RpcUtils;
 import org.apache.iotdb.rpc.StatementExecutionException;
 import org.apache.iotdb.service.rpc.thrift.TSFetchResultsReq;
@@ -29,17 +40,8 @@ import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.utils.BytesUtils;
 import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
-
 import org.apache.thrift.TException;
 
-import java.nio.ByteBuffer;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.*;
-
-import static org.apache.iotdb.rpc.IoTDBRpcDataSet.START_INDEX;
-import static org.apache.iotdb.rpc.IoTDBRpcDataSet.TIMESTAMP_STR;
-
 public class IoTDBNonAlignJDBCResultSet extends AbstractIoTDBJDBCResultSet {
 
   private static final int TIMESTAMP_STR_LENGTH = 4;
@@ -143,9 +145,12 @@ public class IoTDBNonAlignJDBCResultSet extends AbstractIoTDBJDBCResultSet {
       }
       if (!resp.hasResultSet) {
         ioTDBRpcDataSet.emptyResultSet = true;
+        close();
       } else {
         tsQueryNonAlignDataSet = resp.getNonAlignQueryDataSet();
         if (tsQueryNonAlignDataSet == null) {
+          ioTDBRpcDataSet.emptyResultSet = true;
+          close();
           return false;
         }
       }
diff --git a/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java b/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
index 8895bf3..a85b21f 100644
--- a/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
+++ b/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
@@ -204,13 +204,26 @@ public class IoTDBRpcDataSet {
       return true;
     }
     if (emptyResultSet) {
-      return false;
+      try {
+        close();
+        return false;
+      } catch (TException e) {
+        throw new IoTDBConnectionException(
+            "Cannot close dataset, because of network connection: {} ", e);
+      }
     }
-    if (fetchResults()) {
+    if (fetchResults() && hasCachedResults()) {
       constructOneRow();
       return true;
+    } else {
+      try {
+        close();
+        return false;
+      } catch (TException e) {
+        throw new IoTDBConnectionException(
+            "Cannot close dataset, because of network connection: {} ", e);
+      }
     }
-    return false;
   }
 
   public boolean fetchResults() throws StatementExecutionException, IoTDBConnectionException {
@@ -223,6 +236,7 @@ public class IoTDBRpcDataSet {
       RpcUtils.verifySuccess(resp.getStatus());
       if (!resp.hasResultSet) {
         emptyResultSet = true;
+        close();
       } else {
         tsQueryDataSet = resp.getQueryDataSet();
       }