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/20 01:43:32 UTC

[iotdb] branch AutoClose11 created (now 3da6da1)

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

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


      at 3da6da1  Automatically close the dataset while there is no more data

This branch includes the following new commits:

     new 3da6da1  Automatically 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: Automatically 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 AutoClose11
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 3da6da15ffc92aaae6a73d4cc1b75575a4336ca6
Author: JackieTien97 <Ja...@foxmail.com>
AuthorDate: Thu May 20 09:42:46 2021 +0800

    Automatically close the dataset while there is no more data
---
 .../iotdb/jdbc/IoTDBNonAlignJDBCResultSet.java       | 17 +++++++++++------
 .../java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java   | 20 +++++++++++++++++---
 2 files changed, 28 insertions(+), 9 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 8c827d8..f5ab61a 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignJDBCResultSet.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignJDBCResultSet.java
@@ -21,8 +21,15 @@ package org.apache.iotdb.jdbc;
 
 import static org.apache.iotdb.rpc.IoTDBRpcDataSet.START_INDEX;
 import static org.apache.iotdb.rpc.IoTDBRpcDataSet.TIMESTAMP_STR;
-import static org.apache.iotdb.rpc.IoTDBRpcDataSet.VALUE_IS_NULL;
 
+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;
@@ -35,11 +42,6 @@ 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.*;
-
 public class IoTDBNonAlignJDBCResultSet extends AbstractIoTDBJDBCResultSet {
 
   private static final int TIMESTAMP_STR_LENGTH = 4;
@@ -121,9 +123,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 5c9e8f5..a7eeb57 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
@@ -192,13 +192,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 {
@@ -210,6 +223,7 @@ public class IoTDBRpcDataSet {
       RpcUtils.verifySuccess(resp.getStatus());
       if (!resp.hasResultSet) {
         emptyResultSet = true;
+        close();
       } else {
         tsQueryDataSet = resp.getQueryDataSet();
       }