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 2021/11/23 01:25:23 UTC

[iotdb] branch rel/0.12 updated: [To rel/0.12] [IOTDB-2047] Fix NPE when memControl is disabled and insert TEXT value to a non-TEXT series (#4443)

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

qiaojialin pushed a commit to branch rel/0.12
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.12 by this push:
     new 51a7c26  [To rel/0.12] [IOTDB-2047] Fix NPE when memControl is disabled and insert TEXT value to a non-TEXT series (#4443)
51a7c26 is described below

commit 51a7c260fad62537a4eec5b9d301e14c1fe57d5c
Author: Haonan <hh...@outlook.com>
AuthorDate: Tue Nov 23 09:24:52 2021 +0800

    [To rel/0.12] [IOTDB-2047] Fix NPE when memControl is disabled and insert TEXT value to a non-TEXT series (#4443)
---
 .../java/org/apache/iotdb/db/utils/MemUtils.java   |   2 +-
 .../org/apache/iotdb/db/utils/MemUtilsTest.java    |   8 ++
 .../session/IoTDBSessionDisableMemControlIT.java   | 133 +++++++++++++++++++++
 3 files changed, 142 insertions(+), 1 deletion(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/utils/MemUtils.java b/server/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
index 2d8488b..95e2ca5 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
@@ -89,7 +89,7 @@ public class MemUtils {
     }
     long memSize = 0;
     for (int i = 0; i < insertTabletPlan.getMeasurements().length; i++) {
-      if (insertTabletPlan.getDataTypes()[i] == null) {
+      if (insertTabletPlan.getColumns()[i] == null) {
         continue;
       }
       switch (insertTabletPlan.getDataTypes()[i]) {
diff --git a/server/src/test/java/org/apache/iotdb/db/utils/MemUtilsTest.java b/server/src/test/java/org/apache/iotdb/db/utils/MemUtilsTest.java
index 7468467..4aea660 100644
--- a/server/src/test/java/org/apache/iotdb/db/utils/MemUtilsTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/utils/MemUtilsTest.java
@@ -47,6 +47,13 @@ public class MemUtilsTest {
   public void getRecordSizeWithInsertPlanTest() throws IllegalPathException {
     PartialPath device = new PartialPath("root.sg.d1");
     String[] measurements = {"s1", "s2", "s3", "s4", "s5"};
+    Object[] columns = {
+      new int[] {1},
+      new long[] {2},
+      new float[] {3},
+      new double[] {4},
+      new Binary[] {new Binary("5")}
+    };
     List<Integer> dataTypes = new ArrayList<>();
     int sizeSum = 0;
     dataTypes.add(TSDataType.INT32.ordinal());
@@ -60,6 +67,7 @@ public class MemUtilsTest {
     dataTypes.add(TSDataType.TEXT.ordinal());
     sizeSum += TSDataType.TEXT.getDataTypeSize();
     InsertTabletPlan insertPlan = new InsertTabletPlan(device, measurements, dataTypes);
+    insertPlan.setColumns(columns);
     Assert.assertEquals(sizeSum, MemUtils.getRecordSize(insertPlan, 0, 1, false));
   }
 
diff --git a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionDisableMemControlIT.java b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionDisableMemControlIT.java
new file mode 100644
index 0000000..67024ae
--- /dev/null
+++ b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionDisableMemControlIT.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.session;
+
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class IoTDBSessionDisableMemControlIT {
+
+  private static Logger logger = LoggerFactory.getLogger(IoTDBSessionDisableMemControlIT.class);
+
+  private Session session;
+
+  @Before
+  public void setUp() {
+    System.setProperty(IoTDBConstant.IOTDB_CONF, "src/test/resources/");
+    EnvironmentUtils.closeStatMonitor();
+    IoTDBDescriptor.getInstance().getConfig().setEnableMemControl(false);
+    EnvironmentUtils.envSetUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    session.close();
+    EnvironmentUtils.cleanEnv();
+    IoTDBDescriptor.getInstance().getConfig().setEnableMemControl(true);
+  }
+
+  @Test
+  public void testInsertPartialTablet()
+      throws IoTDBConnectionException, StatementExecutionException {
+    session = new Session("127.0.0.1", 6667, "root", "root");
+    session.open();
+
+    if (!session.checkTimeseriesExists("root.sg.d.s1")) {
+      session.createTimeseries(
+          "root.sg.d.s1", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
+    }
+    if (!session.checkTimeseriesExists("root.sg.d.s2")) {
+      session.createTimeseries(
+          "root.sg.d.s2", TSDataType.DOUBLE, TSEncoding.GORILLA, CompressionType.SNAPPY);
+    }
+    if (!session.checkTimeseriesExists("root.sg.d.s3")) {
+      session.createTimeseries(
+          "root.sg.d.s3", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
+    }
+    List<MeasurementSchema> schemaList = new ArrayList<>();
+    schemaList.add(new MeasurementSchema("s1", TSDataType.INT64));
+    schemaList.add(new MeasurementSchema("s2", TSDataType.DOUBLE));
+    schemaList.add(new MeasurementSchema("s3", TSDataType.TEXT));
+
+    Tablet tablet = new Tablet("root.sg.d", schemaList, 10);
+
+    long timestamp = System.currentTimeMillis();
+
+    for (long row = 0; row < 15; row++) {
+      int rowIndex = tablet.rowSize++;
+      tablet.addTimestamp(rowIndex, timestamp);
+      tablet.addValue("s1", rowIndex, 1L);
+      tablet.addValue("s2", rowIndex, 1D);
+      tablet.addValue("s3", rowIndex, new Binary("1"));
+      if (tablet.rowSize == tablet.getMaxRowNumber()) {
+        try {
+          session.insertTablet(tablet, true);
+        } catch (StatementExecutionException e) {
+          Assert.assertEquals(
+              "313: failed to insert measurements [s3] caused by DataType mismatch, Insert measurement s3 type TEXT, metadata tree type INT64",
+              e.getMessage());
+        }
+        tablet.reset();
+      }
+      timestamp++;
+    }
+
+    if (tablet.rowSize != 0) {
+      try {
+        session.insertTablet(tablet);
+      } catch (StatementExecutionException e) {
+        Assert.assertEquals(
+            "313: failed to insert measurements [s3] caused by DataType mismatch, Insert measurement s3 type TEXT, metadata tree type INT64",
+            e.getMessage());
+      }
+      tablet.reset();
+    }
+
+    SessionDataSet dataSet =
+        session.executeQueryStatement("select count(s1), count(s2), count(s3) from root.sg.d");
+    while (dataSet.hasNext()) {
+      RowRecord rowRecord = dataSet.next();
+      Assert.assertEquals(15L, rowRecord.getFields().get(0).getLongV());
+      Assert.assertEquals(15L, rowRecord.getFields().get(1).getLongV());
+      Assert.assertEquals(0L, rowRecord.getFields().get(2).getLongV());
+    }
+    session.close();
+  }
+}