This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 26c42ea190 [IOTDB-3730][ISSUE-6551] ArrayIndexOutOfBounds when
flushing a memtable (#6577)
26c42ea190 is described below
commit 26c42ea190e44cf0c6ed23e1bbc6a3b04d918dbb
Author: Chen YZ <[email protected]>
AuthorDate: Mon Jul 4 14:25:53 2022 +0800
[IOTDB-3730][ISSUE-6551] ArrayIndexOutOfBounds when flushing a memtable
(#6577)
---
.../iotdb/db/rescon/PrimitiveArrayManager.java | 6 +++-
.../db/utils/datastructure/AlignedTVList.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 | 42 ++++++++++++++++++++++
9 files changed, 75 insertions(+), 15 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 54704bea4b..0f5b667c49 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
@@ -278,7 +278,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][];
@@ -320,4 +320,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/AlignedTVList.java
b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
index d827d48d2f..27c1bf8510 100644
---
a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
+++
b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
@@ -558,11 +558,13 @@ public class AlignedTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < rowCount) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedTimestamps =
(long[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, rowCount);
}
- if (sortedIndices == null || sortedIndices.length < rowCount) {
+ if (sortedIndices == null
+ || sortedIndices.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedIndices =
(int[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT32, rowCount);
}
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 b7e3dbf197..4b27e068a6 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
@@ -105,11 +105,13 @@ public class BinaryTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < rowCount) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedTimestamps =
(long[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, rowCount);
}
- if (sortedValues == null || sortedValues.length < rowCount) {
+ if (sortedValues == null
+ || sortedValues.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedValues =
(Binary[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.TEXT, rowCount);
}
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 8ebeb189db..228aea2502 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
@@ -104,11 +104,13 @@ public class BooleanTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < rowCount) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedTimestamps =
(long[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, rowCount);
}
- if (sortedValues == null || sortedValues.length < rowCount) {
+ if (sortedValues == null
+ || sortedValues.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedValues =
(boolean[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.BOOLEAN, rowCount);
}
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 9f4295054b..dc1160e608 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
@@ -104,11 +104,13 @@ public class DoubleTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < rowCount) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedTimestamps =
(long[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, rowCount);
}
- if (sortedValues == null || sortedValues.length < rowCount) {
+ if (sortedValues == null
+ || sortedValues.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedValues =
(double[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.DOUBLE, rowCount);
}
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 c157c7ee53..0e44dffed0 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
@@ -104,11 +104,13 @@ public class FloatTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < rowCount) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedTimestamps =
(long[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, rowCount);
}
- if (sortedValues == null || sortedValues.length < rowCount) {
+ if (sortedValues == null
+ || sortedValues.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedValues =
(float[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.FLOAT, rowCount);
}
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 3876009ec0..5d8999b5a8 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
@@ -103,11 +103,13 @@ public class IntTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < rowCount) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedTimestamps =
(long[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, rowCount);
}
- if (sortedValues == null || sortedValues.length < rowCount) {
+ if (sortedValues == null
+ || sortedValues.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedValues =
(int[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT32, rowCount);
}
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 d28bc76e56..07c2073614 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
@@ -103,11 +103,13 @@ public class LongTVList extends TVList {
@Override
public void sort() {
- if (sortedTimestamps == null || sortedTimestamps.length < rowCount) {
+ if (sortedTimestamps == null
+ || sortedTimestamps.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedTimestamps =
(long[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, rowCount);
}
- if (sortedValues == null || sortedValues.length < rowCount) {
+ if (sortedValues == null
+ || sortedValues.length <
PrimitiveArrayManager.getArrayRowCount(rowCount)) {
sortedValues =
(long[][])
PrimitiveArrayManager.createDataListsByType(TSDataType.INT64, rowCount);
}
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..c03008b4dd
--- /dev/null
+++
b/server/src/test/java/org/apache/iotdb/db/utils/datastructure/PrimitiveArrayManagerTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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));
+ }
+}