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 2022/07/05 13:49:39 UTC
[iotdb] branch rel/0.12 updated: [To rel/0.12][IOTDB-3730][ISSUE-6551] ArrayIndexOutOfBounds when flushing a memtable (#6572)
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 a219290520 [To rel/0.12][IOTDB-3730][ISSUE-6551] ArrayIndexOutOfBounds when flushing a memtable (#6572)
a219290520 is described below
commit a2192905208007f32c1b783cf55f6601e0664acb
Author: Chen YZ <43...@users.noreply.github.com>
AuthorDate: Tue Jul 5 21:49:33 2022 +0800
[To rel/0.12][IOTDB-3730][ISSUE-6551] ArrayIndexOutOfBounds when flushing a memtable (#6572)
---
.../iotdb/db/rescon/PrimitiveArrayManager.java | 6 +++-
.../iotdb/db/utils/datastructure/BinaryTVList.java | 6 ++--
.../db/utils/datastructure/BooleanTVList.java | 6 ++--
.../iotdb/db/utils/datastructure/DoubleTVList.java | 6 ++--
.../iotdb/db/utils/datastructure/FloatTVList.java | 6 ++--
.../iotdb/db/utils/datastructure/IntTVList.java | 6 ++--
.../iotdb/db/utils/datastructure/LongTVList.java | 6 ++--
.../datastructure/PrimitiveArrayManagerTest.java | 35 ++++++++++++++++++++++
8 files changed, 64 insertions(+), 13 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/rescon/PrimitiveArrayManager.java b/server/src/main/java/org/apache/iotdb/db/rescon/PrimitiveArrayManager.java
index e595cfc6ea..776183487a 100644
--- a/server/src/main/java/org/apache/iotdb/db/rescon/PrimitiveArrayManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/rescon/PrimitiveArrayManager.java
@@ -266,7 +266,7 @@ public class PrimitiveArrayManager {
* @return an array of primitive data arrays
*/
public static Object createDataListsByType(TSDataType dataType, int size) {
- int arrayNumber = (int) Math.ceil((float) size / (float) ARRAY_SIZE);
+ int arrayNumber = getArrayRowCount(size);
switch (dataType) {
case BOOLEAN:
boolean[][] booleans = new boolean[arrayNumber][];
@@ -308,4 +308,8 @@ public class PrimitiveArrayManager {
throw new UnSupportedDataTypeException(dataType.name());
}
}
+
+ public static int getArrayRowCount(int size) {
+ return size / ARRAY_SIZE + (size % ARRAY_SIZE == 0 ? 0 : 1);
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/BinaryTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/BinaryTVList.java
index 69464d3945..372780bd3c 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/BinaryTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/BinaryTVList.java
@@ -94,11 +94,13 @@ public class BinaryTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < size) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedTimestamps =
(long[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, size);
}
- if (sortedValues == null || sortedValues.length < size) {
+ if (sortedValues == null
+ || sortedValues.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedValues =
(Binary[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.TEXT, size);
}
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/BooleanTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/BooleanTVList.java
index d513512f82..54f0c2e639 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/BooleanTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/BooleanTVList.java
@@ -93,11 +93,13 @@ public class BooleanTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < size) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedTimestamps =
(long[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, size);
}
- if (sortedValues == null || sortedValues.length < size) {
+ if (sortedValues == null
+ || sortedValues.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedValues =
(boolean[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.BOOLEAN, size);
}
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
index a2d6e8f3f9..dde4008b7c 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
@@ -94,11 +94,13 @@ public class DoubleTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < size) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedTimestamps =
(long[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, size);
}
- if (sortedValues == null || sortedValues.length < size) {
+ if (sortedValues == null
+ || sortedValues.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedValues =
(double[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.DOUBLE, size);
}
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java
index 3ff4d687e5..c1255c2820 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java
@@ -94,11 +94,13 @@ public class FloatTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < size) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedTimestamps =
(long[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, size);
}
- if (sortedValues == null || sortedValues.length < size) {
+ if (sortedValues == null
+ || sortedValues.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedValues =
(float[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.FLOAT, size);
}
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/IntTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/IntTVList.java
index a72069d5de..a7d40eeca1 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/IntTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/IntTVList.java
@@ -93,11 +93,13 @@ public class IntTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < size) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedTimestamps =
(long[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, size);
}
- if (sortedValues == null || sortedValues.length < size) {
+ if (sortedValues == null
+ || sortedValues.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedValues = (int[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.INT32, size);
}
sort(0, size);
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java
index bd27a0b716..e6d99af22b 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java
@@ -93,11 +93,13 @@ public class LongTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < size) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedTimestamps =
(long[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, size);
}
- if (sortedValues == null || sortedValues.length < size) {
+ if (sortedValues == null
+ || sortedValues.length < PrimitiveArrayManager.getArrayRowCount(size)) {
sortedValues = (long[][]) PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, size);
}
sort(0, size);
diff --git a/server/src/test/java/org/apache/iotdb/db/utils/datastructure/PrimitiveArrayManagerTest.java b/server/src/test/java/org/apache/iotdb/db/utils/datastructure/PrimitiveArrayManagerTest.java
new file mode 100644
index 0000000000..b8ef1ad994
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/utils/datastructure/PrimitiveArrayManagerTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.db.utils.datastructure;
+
+import org.apache.iotdb.db.rescon.PrimitiveArrayManager;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PrimitiveArrayManagerTest {
+ @Test
+ public void testGetArrayRowCount() {
+ Assert.assertEquals(1224827, PrimitiveArrayManager.getArrayRowCount(1224826 * 32 + 1));
+ Assert.assertEquals(1224826, PrimitiveArrayManager.getArrayRowCount(1224826 * 32));
+ Assert.assertEquals(1, PrimitiveArrayManager.getArrayRowCount(32));
+ Assert.assertEquals(1, PrimitiveArrayManager.getArrayRowCount(5));
+ Assert.assertEquals(2, PrimitiveArrayManager.getArrayRowCount(33));
+ }
+}