This is an automated email from the ASF dual-hosted git repository.
JackieTien97 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 68e5278969f Fix aligned null fill order in fast compaction (#19386)
68e5278969f is described below
commit 68e5278969fc33bff9e9fe3d1ac592f2dcf2f43d
Author: shuwenwei <[email protected]>
AuthorDate: Tue Nov 24 19:10:12 2026 +0800
Fix aligned null fill order in fast compaction (#19386)
---
.../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 1452b27f239..68e862ba29b 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 e1a15ecf2f7..37f2cd6e692 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
@@ -43,15 +43,19 @@ import org.apache.tsfile.external.commons.io.FileUtils;
import org.apache.tsfile.file.metadata.IDeviceID;
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;
@@ -295,6 +299,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<>();