From f83d0a1831fdd275ff88a414fb075c8a1dd2c539 Mon Sep 17 00:00:00 2001 From: shuwenwei Date: Wed, 8 Jan 2025 10:23:43 +0800 Subject: [PATCH] ArrayDeviceTimeIndex does not update minStartTime and maxEndTime & Reading old version resource file with mods file may cause error --- .../impl/RewriteCrossSpaceCompactionSelector.java | 6 ++++++ .../dataregion/tsfile/TsFileResource.java | 3 ++- .../tsfile/timeindex/ArrayDeviceTimeIndex.java | 4 ++++ .../compaction/repair/RepairDataFileScanUtilTest.java | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/RewriteCrossSpaceCompactionSelector.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/RewriteCrossSpaceCompactionSelector.java index ef1fe4e02083e..f11fc56e665ab 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/RewriteCrossSpaceCompactionSelector.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/RewriteCrossSpaceCompactionSelector.java @@ -595,6 +595,12 @@ private boolean isOverlap( TsFileResourceCandidate candidate2, boolean loadDeviceTimeIndex) throws IOException { + if (candidate1.resource.getFileStartTime() > candidate1.resource.getFileEndTime()) { + System.out.println("1"); + } + if (candidate2.resource.getFileStartTime() > candidate2.resource.getFileEndTime()) { + System.out.println("1"); + } TimeRange timeRangeOfFile1 = new TimeRange( candidate1.resource.getFileStartTime(), candidate1.resource.getFileEndTime()); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java index d173de421e63a..fea8f9f2668e2 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java @@ -313,7 +313,8 @@ public void deserialize() throws IOException { if (inputStream.available() > 0) { String modFilePath = ReadWriteIOUtils.readString(inputStream); - if (modFilePath != null && !modFilePath.isEmpty()) { + // ends with ".mods2" means it is a new version resource file + if (modFilePath != null && modFilePath.endsWith(ModificationFile.FILE_SUFFIX)) { sharedModFileOffset = ReadWriteIOUtils.readLong(inputStream); if (sharedModFilePathFuture != null) { sharedModFilePathFuture.complete(modFilePath); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/timeindex/ArrayDeviceTimeIndex.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/timeindex/ArrayDeviceTimeIndex.java index cf1cf1dd1db70..f0c0065b446e6 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/timeindex/ArrayDeviceTimeIndex.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/timeindex/ArrayDeviceTimeIndex.java @@ -86,6 +86,10 @@ public ArrayDeviceTimeIndex( this.startTimes = startTimes; this.endTimes = endTimes; this.deviceToIndex = deviceToIndex; + for (Integer index : deviceToIndex.values()) { + this.minStartTime = Math.min(minStartTime, startTimes[index]); + this.maxEndTime = Math.max(maxEndTime, endTimes[index]); + } } @Override diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/repair/RepairDataFileScanUtilTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/repair/RepairDataFileScanUtilTest.java index a4fe8e20e13e6..38a9d36275604 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/repair/RepairDataFileScanUtilTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/repair/RepairDataFileScanUtilTest.java @@ -37,6 +37,7 @@ import org.junit.Before; import org.junit.Test; +import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -54,6 +55,15 @@ public void tearDown() throws IOException, StorageEngineException { super.tearDown(); } + @Test + public void test1() throws IOException { + File file = + new File( + "/Users/shuww/Downloads/0108/data/unsequence/root.local/1/2858/1728981000065-11-0-0.tsfile"); + TsFileResource resource = new TsFileResource(file); + resource.deserialize(); + } + @Test public void testScanNormalFile() throws IOException { TsFileResource resource = createEmptyFileAndResource(true);