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

ColinLeeo 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 2d8f7698e57 Fix non-aligned memory page decode count (#19013)
2d8f7698e57 is described below

commit 2d8f7698e57c078794bd050fc42ba003e99d95b8
Author: Colin Lee <[email protected]>
AuthorDate: Mon Oct 26 22:55:21 2026 +0800

    Fix non-aligned memory page decode count (#19013)
    
    * Fix non-aligned memory page decode count
    
    * Add regression tests for memory page decode statistics
---
 .../execution/operator/source/SeriesScanUtil.java  |   2 +-
 .../source/LazyMemVersionPageReaderTest.java       | 107 +++++++++++++++++++++
 2 files changed, 108 insertions(+), 1 deletion(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
index 1582cacabc6..0611eb85fa4 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
@@ -1864,7 +1864,7 @@ public class SeriesScanUtil implements Accountable {
           
context.getQueryStatistics().getPageReadersDecodeAlignedMemCount().getAndAdd(1);
           
context.getQueryStatistics().getPageReadersDecodeAlignedMemTime().getAndAdd(time);
         } else {
-          
context.getQueryStatistics().getPageReadersDecodeAlignedMemCount().getAndAdd(1);
+          
context.getQueryStatistics().getPageReadersDecodeNonAlignedMemCount().getAndAdd(1);
           
context.getQueryStatistics().getPageReadersDecodeNonAlignedMemTime().getAndAdd(time);
         }
       }
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/source/LazyMemVersionPageReaderTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/source/LazyMemVersionPageReaderTest.java
new file mode 100644
index 00000000000..a1277368c57
--- /dev/null
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/source/LazyMemVersionPageReaderTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.queryengine.execution.operator.source;
+
+import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext;
+import org.apache.iotdb.db.queryengine.execution.fragment.QueryStatistics;
+import 
org.apache.iotdb.db.queryengine.execution.operator.source.SeriesScanUtil.LazyMemVersionPageReader;
+import org.apache.iotdb.db.utils.datastructure.MemPointIterator;
+
+import org.apache.tsfile.file.metadata.statistics.IntegerStatistics;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(Parameterized.class)
+public class LazyMemVersionPageReaderTest {
+
+  private final boolean aligned;
+  private QueryStatistics statistics;
+  private MemPointIterator iterator;
+  private LazyMemVersionPageReader reader;
+
+  @Parameterized.Parameters(name = "aligned={0}")
+  public static Object[][] parameters() {
+    return new Object[][] {{false}, {true}};
+  }
+
+  public LazyMemVersionPageReaderTest(boolean aligned) {
+    this.aligned = aligned;
+  }
+
+  @Before
+  public void setUp() {
+    QueryContext context = new QueryContext(false, false);
+    statistics = context.getQueryStatistics();
+    iterator = mock(MemPointIterator.class);
+    reader =
+        new LazyMemVersionPageReader(
+            context, 0, 0, 0, aligned, new IntegerStatistics(), iterator, 
true);
+  }
+
+  @Test
+  public void testNextBatchAccumulatesDecodeStatistics() {
+    TsBlock batch = new TsBlock(0);
+    when(iterator.nextBatch()).thenReturn(batch);
+
+    assertSame(batch, reader.nextBatch());
+    assertDecodeStatistics(1);
+    assertSame(batch, reader.nextBatch());
+    assertDecodeStatistics(2);
+    verify(iterator, times(2)).nextBatch();
+  }
+
+  @Test
+  public void testNextBatchRecordsDecodeStatisticsOnFailure() {
+    RuntimeException failure = new RuntimeException();
+    when(iterator.nextBatch()).thenThrow(failure);
+
+    assertSame(failure, assertThrows(RuntimeException.class, 
reader::nextBatch));
+    assertDecodeStatistics(1);
+    verify(iterator).nextBatch();
+  }
+
+  private void assertDecodeStatistics(long count) {
+    assertEquals(aligned ? count : 0, 
statistics.getPageReadersDecodeAlignedMemCount().get());
+    assertEquals(aligned ? 0 : count, 
statistics.getPageReadersDecodeNonAlignedMemCount().get());
+    if (aligned) {
+      assertTrue(statistics.getPageReadersDecodeAlignedMemTime().get() > 0);
+      assertEquals(0, 
statistics.getPageReadersDecodeNonAlignedMemTime().get());
+    } else {
+      assertEquals(0, statistics.getPageReadersDecodeAlignedMemTime().get());
+      assertTrue(statistics.getPageReadersDecodeNonAlignedMemTime().get() > 0);
+    }
+    assertEquals(0, statistics.getPageReadersDecodeAlignedDiskCount().get());
+    assertEquals(0, 
statistics.getPageReadersDecodeNonAlignedDiskCount().get());
+    assertEquals(0, statistics.getPageReadersDecodeAlignedDiskTime().get());
+    assertEquals(0, statistics.getPageReadersDecodeNonAlignedDiskTime().get());
+  }
+}

Reply via email to