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

shuwenwei pushed a commit to branch cp-19386-aligned-null-fill-dev1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 7ec2673614140a261db391e1d6c191d50c2de238
Author: shuwenwei <[email protected]>
AuthorDate: Tue Nov 24 17:51:05 2026 +0800

    Fix aligned null fill order in fast compaction
    
    (cherry picked from commit 177d47131e3b6053525bfeafc452e3ead373e604)
---
 .../executor/fast/SeriesCompactionExecutor.java    |  3 +-
 .../execute/utils/reader/PointPriorityReader.java  | 13 ++-
 .../inner/FastCompactionPerformerAlignedTest.java  | 92 ++++++++++++++++++++++
 3 files changed, 103 insertions(+), 5 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/fast/SeriesCompactionExecutor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/fast/SeriesCompactionExecutor.java
index 778c2e7f844..b0edcd78dce 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/fast/SeriesCompactionExecutor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/fast/SeriesCompactionExecutor.java
@@ -265,6 +265,7 @@ public abstract class SeriesCompactionExecutor {
           // finish writing this page
           break;
         }
+        point = pointPriorityReader.currentPointForOutput();
         compactionWriter.write(point, subTaskId);
         pointPriorityReader.next();
       }
@@ -306,7 +307,7 @@ public abstract class SeriesCompactionExecutor {
       }
 
       // write data point into chunk writer
-      compactionWriter.write(currentPoint, subTaskId);
+      compactionWriter.write(pointPriorityReader.currentPointForOutput(), 
subTaskId);
       pointPriorityReader.next();
     }
   }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/reader/PointPriorityReader.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/reader/PointPriorityReader.java
index d6f1c032611..62501b0ecbd 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/reader/PointPriorityReader.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/reader/PointPriorityReader.java
@@ -63,17 +63,22 @@ public class PointPriorityReader {
     this.isAligned = isAligned;
   }
 
+  /** Returns the current point without aligned null filling. */
   public TimeValuePair currentPoint() {
     if (currentPointElement == null) {
       // if the current point is overlapped with other pages, then get the 
highest priority point
       // from queue
       currentPoint = pointQueue.peek().timeValuePair;
       lastTime = currentPoint.getTimestamp();
+    }
+    return currentPoint;
+  }
 
-      // fill aligned null value with the same timestamp
-      if (isAligned) {
-        fillAlignedNullValue();
-      }
+  /** Fill aligned null values when the current point is ready to be written. 
*/
+  public TimeValuePair currentPointForOutput() {
+    currentPoint();
+    if (isAligned && currentPointElement == null) {
+      fillAlignedNullValue();
     }
     return currentPoint;
   }
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/inner/FastCompactionPerformerAlignedTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/inner/FastCompactionPerformerAlignedTest.java
index 4acd68cacd2..fee4e831ccf 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/inner/FastCompactionPerformerAlignedTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/inner/FastCompactionPerformerAlignedTest.java
@@ -42,15 +42,19 @@ import org.apache.commons.io.FileUtils;
 import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.read.TimeValuePair;
 import org.apache.tsfile.utils.Pair;
+import org.apache.tsfile.write.chunk.AlignedChunkWriterImpl;
 import org.apache.tsfile.write.schema.IMeasurementSchema;
 import org.apache.tsfile.write.schema.MeasurementSchema;
+import org.apache.tsfile.write.writer.TsFileIOWriter;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -288,6 +292,94 @@ public class FastCompactionPerformerAlignedTest {
     CompactionCheckerUtils.validDataByValueList(originData, compactedData);
   }
 
+  @Test
+  public void testAlignedCompactionWithLazilyLoadedIntermediatePriorityPage() 
throws Exception {
+    String device = storageGroup + ".d0";
+    List<IMeasurementSchema> schemas =
+        Arrays.asList(
+            new MeasurementSchema("s0", TSDataType.INT64),
+            new MeasurementSchema("s1", TSDataType.INT64));
+    IDeviceID deviceId = IDeviceID.Factory.DEFAULT_FACTORY.create(device);
+
+    TsFileResource highPriorityResource =
+        writeAlignedTsFile(
+            "1-3-0-0.tsfile",
+            deviceId,
+            schemas,
+            new long[] {1, 2},
+            new Long[][] {{10L, null}, {12L, null}});
+    TsFileResource lowPriorityResource =
+        writeAlignedTsFile(
+            "1-1-0-0.tsfile",
+            deviceId,
+            schemas,
+            new long[] {1, 2},
+            new Long[][] {{null, 11L}, {null, 1L}});
+    TsFileResource intermediatePriorityResource =
+        writeAlignedTsFile(
+            "2-2-0-0.tsfile", deviceId, schemas, new long[] {2}, new Long[][] 
{{null, 2L}});
+
+    List<TsFileResource> sourceResources =
+        Arrays.asList(highPriorityResource, lowPriorityResource, 
intermediatePriorityResource);
+    TsFileResource targetResource =
+        
TsFileNameGenerator.getInnerCompactionTargetFileResource(sourceResources, true);
+    performer.setSourceFiles(sourceResources);
+    performer.setTargetFiles(Collections.singletonList(targetResource));
+    performer.setSummary(new FastCompactionTaskSummary());
+    performer.perform();
+    CompactionUtils.moveTargetFile(
+        Collections.singletonList(targetResource), 
CompactionTaskType.INNER_SEQ, storageGroup);
+
+    IFullPath alignedPath = new AlignedFullPath(deviceId, Arrays.asList("s0", 
"s1"), schemas);
+    List<TimeValuePair> compactedData =
+        CompactionCheckerUtils.getDataByQuery(
+                Collections.singletonList(alignedPath),
+                Collections.singletonList(targetResource),
+                Collections.emptyList())
+            .get(alignedPath);
+    TimeValuePair compactedPoint =
+        compactedData.stream().filter(point -> point.getTimestamp() == 
2).findFirst().orElse(null);
+
+    Assert.assertNotNull(compactedPoint);
+    Assert.assertEquals(12L, 
compactedPoint.getValue().getVector()[0].getLong());
+    Assert.assertEquals(2L, 
compactedPoint.getValue().getVector()[1].getLong());
+  }
+
+  private TsFileResource writeAlignedTsFile(
+      String fileName,
+      IDeviceID deviceId,
+      List<IMeasurementSchema> schemas,
+      long[] timestamps,
+      Long[][] values)
+      throws IOException {
+    TsFileResource resource = new TsFileResource(new File(dataDirectory, 
fileName));
+    resource.setSeq(true);
+    try (TsFileIOWriter writer = new TsFileIOWriter(resource.getTsFile())) {
+      AlignedChunkWriterImpl chunkWriter = new AlignedChunkWriterImpl(schemas);
+      for (int row = 0; row < timestamps.length; row++) {
+        long timestamp = timestamps[row];
+        chunkWriter.getTimeChunkWriter().write(timestamp);
+        for (int column = 0; column < schemas.size(); column++) {
+          Long value = values[row][column];
+          chunkWriter
+              .getValueChunkWriterByIndex(column)
+              .write(timestamp, value == null ? 0 : value, value == null);
+        }
+      }
+      writer.startChunkGroup(deviceId);
+      chunkWriter.writeToFileWriter(writer);
+      writer.endChunkGroup();
+      writer.endFile();
+    }
+    for (long timestamp : timestamps) {
+      resource.updateStartTime(deviceId, timestamp);
+      resource.updateEndTime(deviceId, timestamp);
+    }
+    resource.close();
+    resource.serialize();
+    return resource;
+  }
+
   @Test
   public void 
testAlignedTsFileWithDifferentSchemaInDifferentTsFileCompaction() throws 
Exception {
     List<String> devices = new ArrayList<>();

Reply via email to