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

jackietien 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 45aff042e02 Detect inconsistent chunk type when querying or compacting 
tsfile & fix TsTable(TsTable origin) constructor (#16999)
45aff042e02 is described below

commit 45aff042e021003a16460ee1f6d14de343e08afd
Author: shuwenwei <[email protected]>
AuthorDate: Thu Jan 8 19:51:51 2026 +0800

    Detect inconsistent chunk type when querying or compacting tsfile & fix 
TsTable(TsTable origin) constructor (#16999)
---
 .../view/recent/IoTDBTableViewAddColumnTest.java   | 84 ++++++++++++++++++++++
 .../exception/ChunkTypeInconsistentException.java  | 48 +++++++++++++
 .../execution/fragment/QueryStatistics.java        | 10 ++-
 .../execution/operator/source/FileLoaderUtils.java |  9 ++-
 .../FragmentInstanceStatisticsDrawer.java          |  6 ++
 .../performer/impl/FastCompactionPerformer.java    |  6 +-
 .../execute/task/AbstractCompactionTask.java       | 13 ++++
 .../FastNonAlignedSeriesCompactionExecutor.java    | 11 +++
 .../readchunk/SingleSeriesCompactionExecutor.java  |  8 +++
 .../read/reader/chunk/DiskChunkLoader.java         |  7 ++
 .../apache/iotdb/commons/schema/table/TsTable.java |  6 +-
 .../src/main/thrift/datanode.thrift                |  2 +
 12 files changed, 202 insertions(+), 8 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewAddColumnTest.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewAddColumnTest.java
new file mode 100644
index 00000000000..acd27f663b6
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewAddColumnTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.relational.it.query.view.recent;
+
+import org.apache.iotdb.isession.ISession;
+import org.apache.iotdb.isession.SessionDataSet;
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class IoTDBTableViewAddColumnTest {
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().initClusterEnvironment();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    EnvFactory.getEnv().cleanClusterEnvironment();
+  }
+
+  @Test
+  public void testAddColumn() throws IoTDBConnectionException, 
StatementExecutionException {
+    String[] sqls = {
+      "set sql_dialect=tree",
+      "create database root.db",
+      "insert into root.db.风机组.风机号1(time,电压,current) aligned 
values(10000,99.09,88.07)",
+      "insert into root.db.风机组.风机号2(time,电压,电流) values(20000,99.09,88.07)",
+      "set sql_dialect=table",
+      "create database db",
+      "use db",
+      "CREATE OR REPLACE VIEW \"风机表\""
+          + "(\"风机组\" TAG, "
+          + "\"风机号\" TAG, "
+          + "\"电压\" DOUBLE FIELD, "
+          + "\"电流\" DOUBLE FIELD) "
+          + "with (ttl='INF') "
+          + "AS root.db.**",
+      "ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN IF NOT EXISTS \"风机组\" TAG",
+      "ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN IF NOT EXISTS \"风机组\" string",
+      "ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN if not exists \"风机组\" field",
+      "ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN if not exists \"电流\" DOUBLE 
FIELD from current",
+      "show create view \"风机表\"",
+    };
+    try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+      for (String sql : sqls) {
+        session.executeNonQueryStatement(sql);
+      }
+
+      session.executeNonQueryStatement(
+          "ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN if not exists current 
field");
+      SessionDataSet sessionDataSet = session.executeQueryStatement("desc 
\"风机表\"");
+      int rowNum = 0;
+      while (sessionDataSet.hasNext()) {
+        sessionDataSet.next();
+        rowNum++;
+      }
+      Assert.assertEquals(6, rowNum);
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/ChunkTypeInconsistentException.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/ChunkTypeInconsistentException.java
new file mode 100644
index 00000000000..e1aa5ae5ab4
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/ChunkTypeInconsistentException.java
@@ -0,0 +1,48 @@
+/*
+ * 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.exception;
+
+import org.apache.tsfile.file.metadata.IDeviceID;
+
+import java.io.IOException;
+
+public class ChunkTypeInconsistentException extends IOException {
+
+  public String filePath;
+  public IDeviceID deviceId;
+  public String measurement;
+  public long offsetOfChunkHeader;
+
+  public ChunkTypeInconsistentException() {}
+
+  public ChunkTypeInconsistentException(
+      String filePath, IDeviceID deviceID, String measurement, long 
offsetOfChunk) {
+    this.filePath = filePath;
+    this.deviceId = deviceID;
+    this.measurement = measurement;
+    this.offsetOfChunkHeader = offsetOfChunk;
+  }
+
+  @Override
+  @SuppressWarnings("java:S3551")
+  public Throwable fillInStackTrace() {
+    return this;
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/QueryStatistics.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/QueryStatistics.java
index 277e9106520..5291f96dfb5 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/QueryStatistics.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/QueryStatistics.java
@@ -92,6 +92,9 @@ public class QueryStatistics {
   // statistics for count and time of page decode
   private final AtomicLong pageReaderMaxUsedMemorySize = new AtomicLong(0);
 
+  // statistics for count of chunk with metadata errors
+  private final AtomicLong chunkWithMetadataErrorsCount = new AtomicLong(0);
+
   public AtomicLong getLoadTimeSeriesMetadataDiskSeqCount() {
     return loadTimeSeriesMetadataDiskSeqCount;
   }
@@ -288,6 +291,10 @@ public class QueryStatistics {
     return loadTimeSeriesMetadataFromDiskTime;
   }
 
+  public AtomicLong getChunkWithMetadataErrorsCount() {
+    return chunkWithMetadataErrorsCount;
+  }
+
   public TQueryStatistics toThrift() {
     return new TQueryStatistics(
         loadTimeSeriesMetadataDiskSeqCount.get(),
@@ -336,6 +343,7 @@ public class QueryStatistics {
         loadTimeSeriesMetadataActualIOSize.get(),
         loadChunkFromCacheCount.get(),
         loadChunkFromDiskCount.get(),
-        loadChunkActualIOSize.get());
+        loadChunkActualIOSize.get(),
+        chunkWithMetadataErrorsCount.get());
   }
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/FileLoaderUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/FileLoaderUtils.java
index a92796dacfb..d34abd60946 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/FileLoaderUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/FileLoaderUtils.java
@@ -21,6 +21,7 @@ package 
org.apache.iotdb.db.queryengine.execution.operator.source;
 
 import org.apache.iotdb.commons.path.AlignedFullPath;
 import org.apache.iotdb.commons.path.NonAlignedFullPath;
+import org.apache.iotdb.db.exception.ChunkTypeInconsistentException;
 import 
org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceContext;
 import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext;
 import org.apache.iotdb.db.queryengine.metric.SeriesScanCostMetricSet;
@@ -488,7 +489,13 @@ public class FileLoaderUtils {
         chunkMetaData.setModified(true);
       }
       IChunkLoader chunkLoader = chunkMetaData.getChunkLoader();
-      chunkReader = chunkLoader.getChunkReader(chunkMetaData, 
globalTimeFilter);
+      try {
+        chunkReader = chunkLoader.getChunkReader(chunkMetaData, 
globalTimeFilter);
+      } catch (ChunkTypeInconsistentException e) {
+        // if the chunk in tsfile is a value chunk of aligned series, we 
should skip all data of
+        // this chunk.
+        return Collections.emptyList();
+      }
     }
 
     return isModified
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/statistics/FragmentInstanceStatisticsDrawer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/statistics/FragmentInstanceStatisticsDrawer.java
index 4077552c049..c875d6007cf 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/statistics/FragmentInstanceStatisticsDrawer.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/statistics/FragmentInstanceStatisticsDrawer.java
@@ -439,6 +439,12 @@ public class FragmentInstanceStatisticsDrawer {
         2,
         "pageReaderMaxUsedMemorySize",
         queryStatistics.pageReaderMaxUsedMemorySize);
+
+    addLineWithValueCheck(
+        singleFragmentInstanceArea,
+        2,
+        "chunkWithMetadataErrorsCount",
+        queryStatistics.chunkWithMetadataErrorsCount);
   }
 
   private void addLine(List<StatisticLine> resultForSingleInstance, int level, 
String value) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/performer/impl/FastCompactionPerformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/performer/impl/FastCompactionPerformer.java
index a0b9f0713a8..54b21ddd382 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/performer/impl/FastCompactionPerformer.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/performer/impl/FastCompactionPerformer.java
@@ -24,6 +24,7 @@ import 
org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.path.PatternTreeMap;
 import org.apache.iotdb.commons.utils.TestOnly;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.ChunkTypeInconsistentException;
 import org.apache.iotdb.db.exception.WriteProcessException;
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.exception.CompactionLastTimeCheckFailedException;
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.exception.IllegalCompactionTaskSummaryException;
@@ -345,9 +346,10 @@ public class FastCompactionPerformer
         Throwable cause = e.getCause();
         if (cause instanceof CompactionLastTimeCheckFailedException) {
           throw (CompactionLastTimeCheckFailedException) cause;
-        }
-        if (cause instanceof StopReadTsFileByInterruptException) {
+        } else if (cause instanceof StopReadTsFileByInterruptException) {
           throw (StopReadTsFileByInterruptException) cause;
+        } else if (cause instanceof ChunkTypeInconsistentException) {
+          throw (ChunkTypeInconsistentException) cause;
         }
         throw new IOException("[Compaction] SubCompactionTask meet errors ", 
e);
       } catch (InterruptedException e) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/task/AbstractCompactionTask.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/task/AbstractCompactionTask.java
index dd37f626d70..0f6e927a465 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/task/AbstractCompactionTask.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/task/AbstractCompactionTask.java
@@ -22,6 +22,7 @@ package 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.task;
 import org.apache.iotdb.commons.conf.IoTDBConstant;
 import org.apache.iotdb.commons.utils.TestOnly;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.ChunkTypeInconsistentException;
 import org.apache.iotdb.db.service.metrics.CompactionMetrics;
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.constant.CompactionTaskType;
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.exception.CompactionFileCountExceededException;
@@ -172,6 +173,18 @@ public abstract class AbstractCompactionTask {
           dataRegionId,
           getCompactionTaskType());
       Thread.currentThread().interrupt();
+    } else if (e instanceof ChunkTypeInconsistentException) {
+      ChunkTypeInconsistentException chunkTypeInconsistentException =
+          (ChunkTypeInconsistentException) e;
+      logger.error(
+          "Unexpected chunk type detected when reading non-aligned chunk 
reader. "
+              + "The chunk metadata indicates a non-aligned chunk, "
+              + "but the actual chunk read from tsfile is a value chunk of 
aligned series. "
+              + "tsFile={}, device={}, measurement={}, offsetOfChunkHeader={}",
+          chunkTypeInconsistentException.filePath,
+          chunkTypeInconsistentException.deviceId,
+          chunkTypeInconsistentException.measurement,
+          chunkTypeInconsistentException.offsetOfChunkHeader);
     } else {
       logger.error(
           "{}-{} [Compaction] {} task meets error: {}.",
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/fast/FastNonAlignedSeriesCompactionExecutor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/fast/FastNonAlignedSeriesCompactionExecutor.java
index 697376c233a..363554fb606 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/fast/FastNonAlignedSeriesCompactionExecutor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/fast/FastNonAlignedSeriesCompactionExecutor.java
@@ -21,6 +21,7 @@ package 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.utils.ex
 
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.path.PatternTreeMap;
+import org.apache.iotdb.db.exception.ChunkTypeInconsistentException;
 import org.apache.iotdb.db.exception.WriteProcessException;
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.task.subtask.FastCompactionTaskSummary;
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.utils.executor.ModifiedStatus;
@@ -38,6 +39,7 @@ import 
org.apache.iotdb.db.utils.datastructure.PatternTreeMapFactory;
 import org.apache.tsfile.encrypt.EncryptUtils;
 import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.exception.write.PageException;
+import org.apache.tsfile.file.MetaMarker;
 import org.apache.tsfile.file.header.ChunkHeader;
 import org.apache.tsfile.file.header.PageHeader;
 import org.apache.tsfile.file.metadata.ChunkMetadata;
@@ -221,6 +223,15 @@ public class FastNonAlignedSeriesCompactionExecutor 
extends SeriesCompactionExec
               .get(chunkMetadataElement.fileElement.resource)
               .readMemChunk((ChunkMetadata) 
chunkMetadataElement.chunkMetadata);
     }
+    byte chunkType = chunkMetadataElement.chunk.getHeader().getChunkType();
+    if (chunkType != MetaMarker.CHUNK_HEADER
+        && chunkType != MetaMarker.ONLY_ONE_PAGE_CHUNK_HEADER) {
+      throw new ChunkTypeInconsistentException(
+          chunkMetadataElement.fileElement.resource.getTsFilePath(),
+          deviceId,
+          chunkMetadataElement.chunkMetadata.getMeasurementUid(),
+          chunkMetadataElement.chunkMetadata.getOffsetOfChunkHeader());
+    }
     if (!hasStartMeasurement) {
       // for nonAligned sensors, only after getting chunkMetadatas can we 
create metadata to
       // start
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/readchunk/SingleSeriesCompactionExecutor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/readchunk/SingleSeriesCompactionExecutor.java
index f4e9e1bc21e..9ffd2b7044d 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/readchunk/SingleSeriesCompactionExecutor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/readchunk/SingleSeriesCompactionExecutor.java
@@ -20,12 +20,14 @@
 package 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.utils.executor.readchunk;
 
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.ChunkTypeInconsistentException;
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.exception.CompactionLastTimeCheckFailedException;
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.task.CompactionTaskSummary;
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.io.CompactionTsFileWriter;
 import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
 
 import org.apache.tsfile.encrypt.EncryptUtils;
+import org.apache.tsfile.file.MetaMarker;
 import org.apache.tsfile.file.header.ChunkHeader;
 import org.apache.tsfile.file.metadata.ChunkMetadata;
 import org.apache.tsfile.file.metadata.IDeviceID;
@@ -134,6 +136,12 @@ public class SingleSeriesCompactionExecutor {
             chunkMetadata.getNewType() != null
                 ? 
reader.readMemChunk(chunkMetadata).rewrite(chunkMetadata.getNewType())
                 : reader.readMemChunk(chunkMetadata);
+        byte chunkType = currentChunk.getHeader().getChunkType();
+        if (chunkType != MetaMarker.CHUNK_HEADER
+            && chunkType != MetaMarker.ONLY_ONE_PAGE_CHUNK_HEADER) {
+          throw new ChunkTypeInconsistentException(
+              reader.getFileName(), device, measurement, 
chunkMetadata.getOffsetOfChunkHeader());
+        }
         summary.increaseProcessChunkNum(1);
         summary.increaseProcessPointNum(chunkMetadata.getNumOfPoints());
         if (chunkMetadata.getNewType() != null) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/DiskChunkLoader.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/DiskChunkLoader.java
index a2ff24233d9..dd595f9eff4 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/DiskChunkLoader.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/DiskChunkLoader.java
@@ -19,6 +19,7 @@
 
 package org.apache.iotdb.db.storageengine.dataregion.read.reader.chunk;
 
+import org.apache.iotdb.db.exception.ChunkTypeInconsistentException;
 import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext;
 import org.apache.iotdb.db.queryengine.metric.SeriesScanCostMetricSet;
 import org.apache.iotdb.db.storageengine.buffer.ChunkCache;
@@ -27,6 +28,7 @@ import 
org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
 import org.apache.iotdb.db.utils.ObjectTypeUtils;
 
 import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.MetaMarker;
 import org.apache.tsfile.file.metadata.ChunkMetadata;
 import org.apache.tsfile.file.metadata.IChunkMetadata;
 import org.apache.tsfile.read.common.Chunk;
@@ -86,6 +88,11 @@ public class DiskChunkLoader implements IChunkLoader {
                   chunkMetaData.getDeleteIntervalList(),
                   chunkMetaData.getStatistics(),
                   context);
+      byte chunkType = chunk.getHeader().getChunkType();
+      if (chunkType != MetaMarker.CHUNK_HEADER
+          && chunkType != MetaMarker.ONLY_ONE_PAGE_CHUNK_HEADER) {
+        throw new ChunkTypeInconsistentException();
+      }
 
       final TsFileID tsFileID = getTsFileID();
       if (tsFileID.regionId > 0 && chunkMetaData.getDataType() == 
TSDataType.OBJECT) {
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
index 0a28cae2ea0..7dd64481a0e 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
@@ -101,8 +101,6 @@ public class TsTable {
   private transient long ttlValue = Long.MIN_VALUE;
   private transient int tagNums = 0;
   private transient int fieldNum = 0;
-  private transient int idNums = 0;
-  private transient int measurementNum = 0;
 
   public TsTable(final String tableName) {
     this.tableName = tableName;
@@ -122,8 +120,8 @@ public class TsTable {
     this.idColumnIndexMap.putAll(origin.idColumnIndexMap);
     this.props = origin.props == null ? null : new HashMap<>(origin.props);
     this.ttlValue = origin.ttlValue;
-    this.idNums = origin.idNums;
-    this.measurementNum = origin.measurementNum;
+    this.tagNums = origin.tagNums;
+    this.fieldNum = origin.fieldNum;
   }
 
   public String getTableName() {
diff --git a/iotdb-protocol/thrift-datanode/src/main/thrift/datanode.thrift 
b/iotdb-protocol/thrift-datanode/src/main/thrift/datanode.thrift
index 942a04f5f2a..585e5e36be5 100644
--- a/iotdb-protocol/thrift-datanode/src/main/thrift/datanode.thrift
+++ b/iotdb-protocol/thrift-datanode/src/main/thrift/datanode.thrift
@@ -749,6 +749,8 @@ struct TQueryStatistics {
   45: i64 loadChunkFromCacheCount
   46: i64 loadChunkFromDiskCount
   47: i64 loadChunkActualIOSize
+
+  48: i64 chunkWithMetadataErrorsCount
 }
 
 

Reply via email to