This is an automated email from the ASF dual-hosted git repository. xiangweiwei pushed a commit to branch clusterDescBug in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit a741410f6bd1c6c642b10989f431655bf84b403a Author: lta <[email protected]> AuthorDate: Fri Jun 25 01:31:05 2021 +0800 fix a serve bug of BatchData serialization and deserialization which will lead to wrong result of query desc --- .../org/apache/iotdb/db/utils/SerializeUtils.java | 5 +++- .../apache/iotdb/tsfile/read/common/BatchData.java | 33 ++++++++++++++++++++++ .../tsfile/read/common/DescReadBatchData.java | 5 +++- .../tsfile/read/common/DescReadWriteBatchData.java | 1 + 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/apache/iotdb/db/utils/SerializeUtils.java b/server/src/main/java/org/apache/iotdb/db/utils/SerializeUtils.java index cb881e0..c2ccae9 100644 --- a/server/src/main/java/org/apache/iotdb/db/utils/SerializeUtils.java +++ b/server/src/main/java/org/apache/iotdb/db/utils/SerializeUtils.java @@ -23,6 +23,7 @@ import org.apache.iotdb.tsfile.common.conf.TSFileConfig; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.apache.iotdb.tsfile.read.TimeValuePair; import org.apache.iotdb.tsfile.read.common.BatchData; +import org.apache.iotdb.tsfile.read.common.BatchData.BatchDataType; import org.apache.iotdb.tsfile.read.filter.basic.Filter; import org.apache.iotdb.tsfile.utils.Binary; import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; @@ -123,6 +124,7 @@ public class SerializeUtils { TSDataType dataType = batchData.getDataType(); outputStream.writeInt(length); outputStream.write(dataType.ordinal()); + outputStream.write(batchData.getBatchDataType().ordinal()); switch (dataType) { case BOOLEAN: for (int i = 0; i < length; i++) { @@ -175,7 +177,7 @@ public class SerializeUtils { int length = buffer.getInt(); TSDataType dataType = TSDataType.values()[buffer.get()]; - BatchData batchData = new BatchData(dataType); + BatchData batchData = BatchDataType.deserialize(buffer.get(), dataType); switch (dataType) { case INT32: for (int i = 0; i < length; i++) { @@ -212,6 +214,7 @@ public class SerializeUtils { } break; } + batchData.resetBatchData(); return batchData; } diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java index c2a7d3b..ab07c0a 100644 --- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java +++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java @@ -57,6 +57,8 @@ public class BatchData { protected TSDataType dataType; + protected BatchDataType batchDataType = BatchDataType.Ordinary; + // outer list index for read protected int readCurListIndex; // inner array index for read @@ -162,6 +164,10 @@ public class BatchData { return dataType; } + public BatchDataType getBatchDataType() { + return batchDataType; + } + /** * initialize batch data. * @@ -599,4 +605,31 @@ public class BatchData { public BatchData flip() { return this; } + + public enum BatchDataType { + Ordinary, + DescRead, + DescReadWrite; + + BatchDataType() {} + + /** + * give an integer to return a BatchType type. + * + * @param type -param to judge enum type + * @return -enum type + */ + public static BatchData deserialize(byte type, TSDataType dataType) { + switch (type) { + case 0: + return new BatchData(dataType); + case 1: + return new DescReadBatchData(dataType); + case 2: + return new DescReadWriteBatchData(dataType); + default: + throw new IllegalArgumentException("Invalid input: " + type); + } + } + } } diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/DescReadBatchData.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/DescReadBatchData.java index 9f7d539..ebfc204 100644 --- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/DescReadBatchData.java +++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/DescReadBatchData.java @@ -28,10 +28,13 @@ import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; */ public class DescReadBatchData extends BatchData { - public DescReadBatchData() {} + public DescReadBatchData() { + batchDataType = BatchDataType.DescRead; + } public DescReadBatchData(TSDataType dataType) { super(dataType); + batchDataType = BatchDataType.DescRead; } @Override diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/DescReadWriteBatchData.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/DescReadWriteBatchData.java index c299534..ed6e6c2 100644 --- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/DescReadWriteBatchData.java +++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/DescReadWriteBatchData.java @@ -34,6 +34,7 @@ public class DescReadWriteBatchData extends DescReadBatchData { public DescReadWriteBatchData(TSDataType dataType) { super(); + this.batchDataType = BatchDataType.DescReadWrite; this.dataType = dataType; this.readCurListIndex = 0; this.readCurArrayIndex = 0;
