You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2023/09/08 07:03:31 UTC
[iotdb] branch master updated: Tsfile resource validation and repair tool (#10984)
This is an automated email from the ASF dual-hosted git repository.
xingtanzjr 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 624895955d3 Tsfile resource validation and repair tool (#10984)
624895955d3 is described below
commit 624895955d3ce89b827e7184bdccef75c99b13cf
Author: shuwenwei <55...@users.noreply.github.com>
AuthorDate: Fri Sep 8 15:03:25 2023 +0800
Tsfile resource validation and repair tool (#10984)
---
.../check-overlap-sequence-files-and-repair.bat | 62 +++++
.../check-overlap-sequence-files-and-repair.sh | 51 ++++
.../TsFileOverlapValidationAndRepairTool.java | 276 +++++++++++++++++++++
.../TsFileOverlapValidationAndRepairToolTest.java | 193 ++++++++++++++
4 files changed, 582 insertions(+)
diff --git a/iotdb-core/datanode/src/assembly/resources/tools/tsfile/check-overlap-sequence-files-and-repair.bat b/iotdb-core/datanode/src/assembly/resources/tools/tsfile/check-overlap-sequence-files-and-repair.bat
new file mode 100644
index 00000000000..4af5e1a4a5e
--- /dev/null
+++ b/iotdb-core/datanode/src/assembly/resources/tools/tsfile/check-overlap-sequence-files-and-repair.bat
@@ -0,0 +1,62 @@
+@REM
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM
+
+
+@echo off
+echo ````````````````````````
+echo Starting Validating the TsFile resources
+echo ````````````````````````
+
+if "%OS%" == "Windows_NT" setlocal
+
+pushd %~dp0..\..
+if NOT DEFINED IOTDB_HOME set IOTDB_HOME=%CD%
+popd
+
+if NOT DEFINED MAIN_CLASS set MAIN_CLASS=org.apache.iotdb.db.tools.validate.TsFileOverlapValidationAndRepairTool
+if NOT DEFINED JAVA_HOME goto :err
+
+@REM -----------------------------------------------------------------------------
+@REM ***** CLASSPATH library setting *****
+@REM Ensure that any user defined CLASSPATH variables are not used on startup
+set CLASSPATH="%IOTDB_HOME%\lib\*"
+
+goto okClasspath
+
+:append
+set CLASSPATH=%CLASSPATH%;%1
+goto :eof
+
+@REM -----------------------------------------------------------------------------
+:okClasspath
+
+"%JAVA_HOME%\bin\java" -cp "%CLASSPATH%" %MAIN_CLASS% %*
+
+goto finally
+
+
+:err
+echo JAVA_HOME environment variable must be set!
+pause
+
+
+@REM -----------------------------------------------------------------------------
+:finally
+
+ENDLOCAL
diff --git a/iotdb-core/datanode/src/assembly/resources/tools/tsfile/check-overlap-sequence-files-and-repair.sh b/iotdb-core/datanode/src/assembly/resources/tools/tsfile/check-overlap-sequence-files-and-repair.sh
new file mode 100644
index 00000000000..76557b2f068
--- /dev/null
+++ b/iotdb-core/datanode/src/assembly/resources/tools/tsfile/check-overlap-sequence-files-and-repair.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+#
+# 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.
+#
+
+echo ---------------------
+echo Starting Validating the TsFile resources
+echo ---------------------
+
+source "$(dirname "$0")/../../sbin/iotdb-common.sh"
+#get_iotdb_include and checkAllVariables is in iotdb-common.sh
+VARS=$(get_iotdb_include "$*")
+checkAllVariables
+export IOTDB_HOME="${IOTDB_HOME}/.."
+eval set -- "$VARS"
+
+if [ -n "$JAVA_HOME" ]; then
+ for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
+ if [ -x "$java" ]; then
+ JAVA="$java"
+ break
+ fi
+ done
+else
+ JAVA=java
+fi
+
+CLASSPATH=""
+for f in ${IOTDB_HOME}/lib/*.jar; do
+ CLASSPATH=${CLASSPATH}":"$f
+done
+
+MAIN_CLASS=org.apache.iotdb.db.tools.validate.TsFileOverlapValidationAndRepairTool
+
+"$JAVA" -cp "$CLASSPATH" "$MAIN_CLASS" "$@"
+exit $?
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/validate/TsFileOverlapValidationAndRepairTool.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/validate/TsFileOverlapValidationAndRepairTool.java
new file mode 100644
index 00000000000..3f99a9e8678
--- /dev/null
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/validate/TsFileOverlapValidationAndRepairTool.java
@@ -0,0 +1,276 @@
+/*
+ * 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.tools.validate;
+
+import org.apache.iotdb.db.storageengine.dataregion.compaction.execute.utils.log.CompactionLogger;
+import org.apache.iotdb.db.storageengine.dataregion.modification.ModificationFile;
+import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
+import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
+
+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.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Scanner;
+import java.util.Set;
+
+public class TsFileOverlapValidationAndRepairTool {
+
+ private static final Set<File> toMoveFiles = new HashSet<>();
+ private static final List<File> partitionDirsWhichHaveOverlapFiles = new ArrayList<>();
+ private static int overlapTsFileNum = 0;
+ private static int totalTsFileNum = 0;
+
+ public static void main(String[] args) throws IOException {
+ if (args.length == 0) {
+ System.out.println("Please input sequence data dir path.");
+ return;
+ }
+ List<String> sequenceDataDirs = getDataDirs(args);
+ validateSequenceDataDirs(sequenceDataDirs);
+ if (!confirmMoveOverlapFilesToUnsequenceSpace()) {
+ return;
+ }
+ moveOverlapFilesToUnsequenceSpace(toMoveFiles);
+ }
+
+ private static List<String> getDataDirs(String[] args) {
+ return Arrays.asList(args);
+ }
+
+ private static boolean confirmMoveOverlapFilesToUnsequenceSpace() {
+ System.out.println("TimePartitions which have overlap files:");
+ for (File partitionDirsWhichHaveOverlapFile : partitionDirsWhichHaveOverlapFiles) {
+ System.out.println(partitionDirsWhichHaveOverlapFile.getAbsolutePath());
+ }
+ System.out.println();
+
+ System.out.printf(
+ "Overlap tsfile num is %d, total tsfile num is %d\n", overlapTsFileNum, totalTsFileNum);
+ System.out.println("Corresponding file num is " + toMoveFiles.size());
+ if (overlapTsFileNum == 0) {
+ return false;
+ }
+ System.out.println("Repair overlap tsfiles (y/n)");
+ Scanner scanner = new Scanner(System.in);
+ String input = scanner.nextLine();
+ return "y".equals(input);
+ }
+
+ private static void moveOverlapFilesToUnsequenceSpace(Set<File> toMoveFiles) {
+ for (File f : toMoveFiles) {
+ if (!f.exists()) {
+ System.out.println(f.getAbsolutePath() + "is not exist in repairing");
+ continue;
+ }
+ String filePath = f.getAbsolutePath();
+ String replaceStr = File.separator + "sequence" + File.separator;
+ String replaceToStr = File.separator + "unsequence" + File.separator;
+ int sequenceDirIndex = filePath.indexOf(replaceStr);
+ if (sequenceDirIndex == -1) {
+ continue;
+ }
+ String moveToPath =
+ filePath.substring(0, sequenceDirIndex)
+ + replaceToStr
+ + filePath.substring(sequenceDirIndex + replaceStr.length());
+ File targetFile = new File(moveToPath);
+ File targetParentFile = targetFile.getParentFile();
+ if (targetParentFile.exists()) {
+ targetParentFile.mkdirs();
+ }
+ boolean success = f.renameTo(targetFile);
+ if (!success) {
+ System.out.println("Failed to repair " + f.getAbsolutePath());
+ }
+ System.out.println("Repair file " + targetFile.getName());
+ }
+ }
+
+ private static void validateSequenceDataDirs(List<String> sequenceDataDirPaths)
+ throws IOException {
+ Map<String, List<File>> partitionMap = new HashMap<>();
+ for (String sequenceDataDirPath : sequenceDataDirPaths) {
+ File sequenceDataDir = new File(sequenceDataDirPath);
+ if (!sequenceDataDir.exists() || sequenceDataDir.isFile()) {
+ System.out.println(sequenceDataDir.getAbsolutePath() + " is not a correct path");
+ continue;
+ }
+ for (File sg : Objects.requireNonNull(sequenceDataDir.listFiles())) {
+ if (!sg.isDirectory()) {
+ continue;
+ }
+ for (File dataRegionDir : Objects.requireNonNull(sg.listFiles())) {
+ if (!dataRegionDir.isDirectory()) {
+ continue;
+ }
+ for (File timePartitionDir : Objects.requireNonNull(dataRegionDir.listFiles())) {
+ if (!timePartitionDir.isDirectory()) {
+ continue;
+ }
+ String partitionKey =
+ calculateTimePartitionKey(
+ sg.getName(), dataRegionDir.getName(), timePartitionDir.getName());
+ List<File> partitionDirs =
+ partitionMap.computeIfAbsent(partitionKey, v -> new ArrayList<>());
+ partitionDirs.add(timePartitionDir);
+ }
+ }
+ }
+ }
+
+ for (Map.Entry<String, List<File>> partition : partitionMap.entrySet()) {
+ String partitionName = partition.getKey();
+ List<TsFileResource> resources = loadSortedTsFileResources(partition.getValue());
+ if (resources.isEmpty()) {
+ continue;
+ }
+ int overlapTsFileNumInCurrentTimePartition = checkTimePartitionHasOverlap(resources);
+ if (overlapTsFileNumInCurrentTimePartition == 0) {
+ continue;
+ }
+ System.out.println(
+ "TimePartition " + partitionName + " has overlap file, dir is " + partition.getValue());
+ partitionDirsWhichHaveOverlapFiles.addAll(partition.getValue());
+ overlapTsFileNum += overlapTsFileNumInCurrentTimePartition;
+ }
+ }
+
+ private static String calculateTimePartitionKey(
+ String storageGroup, String dataRegion, String timePartition) {
+ return storageGroup + "-" + dataRegion + "-" + timePartition;
+ }
+
+ public static int checkTimePartitionHasOverlap(List<TsFileResource> resources) {
+ int overlapTsFileNum = 0;
+ Map<String, Long> deviceEndTimeMap = new HashMap<>();
+ Map<String, TsFileResource> deviceLastExistTsFileMap = new HashMap<>();
+ for (TsFileResource resource : resources) {
+ Set<String> devices = resource.getDevices();
+ boolean fileHasOverlap = false;
+ // check overlap
+ for (String device : devices) {
+ long deviceStartTimeInCurrentFile = resource.getStartTime(device);
+ if (deviceStartTimeInCurrentFile > resource.getEndTime(device)) {
+ continue;
+ }
+ if (!deviceEndTimeMap.containsKey(device)) {
+ continue;
+ }
+ long deviceEndTimeInPreviousFile = deviceEndTimeMap.get(device);
+ if (deviceStartTimeInCurrentFile <= deviceEndTimeInPreviousFile) {
+ System.out.printf(
+ "previous file: %s, current file: %s, device %s in previous file end time is %d,"
+ + " device in current file start time is %d\n",
+ deviceLastExistTsFileMap.get(device).getTsFilePath(),
+ resource.getTsFilePath(),
+ device,
+ deviceEndTimeInPreviousFile,
+ deviceStartTimeInCurrentFile);
+ fileHasOverlap = true;
+ recordOverlapTsFile(resource);
+ overlapTsFileNum++;
+ break;
+ }
+ }
+ // update end time map
+ if (!fileHasOverlap) {
+ for (String device : devices) {
+ long deviceEndTimeInCurrentFile = resource.getEndTime(device);
+ if (!deviceLastExistTsFileMap.containsKey(device)) {
+ deviceEndTimeMap.put(device, deviceEndTimeInCurrentFile);
+ deviceLastExistTsFileMap.put(device, resource);
+ continue;
+ }
+ deviceEndTimeMap.put(device, resource.getEndTime(device));
+ deviceLastExistTsFileMap.put(device, resource);
+ }
+ }
+ }
+ return overlapTsFileNum;
+ }
+
+ private static void recordOverlapTsFile(TsFileResource overlapFile) {
+ String filePath = overlapFile.getTsFilePath();
+ toMoveFiles.add(overlapFile.getTsFile());
+ toMoveFiles.add(new File(filePath + TsFileResource.RESOURCE_SUFFIX));
+ ModificationFile modsFile = overlapFile.getModFile();
+ if (modsFile.exists()) {
+ toMoveFiles.add(new File(modsFile.getFilePath()));
+ }
+ }
+
+ private static List<TsFileResource> loadSortedTsFileResources(List<File> timePartitionDirs)
+ throws IOException {
+ List<TsFileResource> resources = new ArrayList<>();
+ for (File timePartitionDir : timePartitionDirs) {
+ for (File tsfile : Objects.requireNonNull(timePartitionDir.listFiles())) {
+ String filePath = tsfile.getAbsolutePath();
+ // has compaction log
+ if (filePath.endsWith(CompactionLogger.INNER_COMPACTION_LOG_NAME_SUFFIX)
+ || filePath.endsWith(CompactionLogger.CROSS_COMPACTION_LOG_NAME_SUFFIX)) {
+ System.out.println(
+ "Time partition "
+ + timePartitionDir.getName()
+ + " is skipped because a compaction is not finished");
+ return Collections.emptyList();
+ }
+
+ if (!filePath.endsWith(TsFileConstant.TSFILE_SUFFIX) || !tsfile.isFile()) {
+ continue;
+ }
+ String resourcePath = tsfile.getAbsolutePath() + TsFileResource.RESOURCE_SUFFIX;
+
+ if (!new File(resourcePath).exists()) {
+ System.out.println(
+ tsfile.getAbsolutePath() + " is skipped because resource file is not exist.");
+ continue;
+ }
+
+ TsFileResource resource = new TsFileResource();
+ resource.setFile(tsfile);
+ resource.deserialize();
+ resource.close();
+ resources.add(resource);
+ }
+ }
+ resources.sort(
+ (f1, f2) -> {
+ int timeDiff =
+ Long.compareUnsigned(
+ Long.parseLong(f1.getTsFile().getName().split("-")[0]),
+ Long.parseLong(f2.getTsFile().getName().split("-")[0]));
+ return timeDiff == 0
+ ? Long.compareUnsigned(
+ Long.parseLong(f1.getTsFile().getName().split("-")[1]),
+ Long.parseLong(f2.getTsFile().getName().split("-")[1]))
+ : timeDiff;
+ });
+
+ totalTsFileNum += resources.size();
+ return resources;
+ }
+}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/TsFileOverlapValidationAndRepairToolTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/TsFileOverlapValidationAndRepairToolTest.java
new file mode 100644
index 00000000000..0029677bf59
--- /dev/null
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/TsFileOverlapValidationAndRepairToolTest.java
@@ -0,0 +1,193 @@
+/*
+ * 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.tools;
+
+import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.storageengine.dataregion.compaction.AbstractCompactionTest;
+import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
+import org.apache.iotdb.db.tools.validate.TsFileOverlapValidationAndRepairTool;
+import org.apache.iotdb.tsfile.exception.write.WriteProcessException;
+import org.apache.iotdb.tsfile.write.writer.TsFileIOWriter;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+public class TsFileOverlapValidationAndRepairToolTest extends AbstractCompactionTest {
+ @Before
+ public void setUp()
+ throws IOException, WriteProcessException, MetadataException, InterruptedException {
+ super.setUp();
+ }
+
+ @After
+ public void tearDown() throws IOException, StorageEngineException {
+ super.tearDown();
+ }
+
+ @Test
+ public void test1() throws IOException {
+ String device1 = "d1", device2 = "d2";
+ TsFileResource resource1 = createTsFileAndResource();
+ resource1.updateStartTime(device1, 10);
+ resource1.updateEndTime(device1, 30);
+ resource1.updateStartTime(device2, 20);
+ resource1.updateEndTime(device2, 40);
+ resource1.serialize();
+ resource1.close();
+
+ TsFileResource resource2 = createTsFileAndResource();
+ resource2.updateStartTime(device1, 29);
+ resource2.updateEndTime(device1, 30);
+ resource2.updateStartTime(device2, 50);
+ resource2.updateEndTime(device2, 60);
+ resource2.serialize();
+ resource2.close();
+
+ TsFileResource resource3 = createTsFileAndResource();
+ resource3.updateStartTime(device1, 40);
+ resource3.updateEndTime(device1, 50);
+ resource3.updateStartTime(device2, 70);
+ resource3.updateEndTime(device2, 80);
+ resource3.serialize();
+ resource3.close();
+
+ int overlapFileNum =
+ TsFileOverlapValidationAndRepairTool.checkTimePartitionHasOverlap(
+ Arrays.asList(resource1, resource2, resource3));
+
+ Assert.assertEquals(1, overlapFileNum);
+ }
+
+ @Test
+ public void test2() throws IOException {
+ String device1 = "d1", device2 = "d2";
+ TsFileResource resource1 = createTsFileAndResource();
+ resource1.updateStartTime(device1, 10);
+ resource1.updateEndTime(device1, 30);
+ resource1.updateStartTime(device2, 20);
+ resource1.updateEndTime(device2, 40);
+ resource1.serialize();
+ resource1.close();
+
+ TsFileResource resource2 = createTsFileAndResource();
+ resource2.updateStartTime(device1, 29);
+ resource2.updateEndTime(device1, 30);
+ resource2.updateStartTime(device2, 50);
+ resource2.updateEndTime(device2, 60);
+ resource2.serialize();
+ resource2.close();
+
+ TsFileResource resource3 = createTsFileAndResource();
+ resource3.updateStartTime(device1, 30);
+ resource3.updateEndTime(device1, 50);
+ resource3.updateStartTime(device2, 70);
+ resource3.updateEndTime(device2, 80);
+ resource3.serialize();
+ resource3.close();
+
+ int overlapFileNum =
+ TsFileOverlapValidationAndRepairTool.checkTimePartitionHasOverlap(
+ Arrays.asList(resource1, resource2, resource3));
+
+ Assert.assertEquals(2, overlapFileNum);
+ }
+
+ @Test
+ public void test3() throws IOException {
+ String device1 = "d1", device2 = "d2";
+ TsFileResource resource1 = createTsFileAndResource();
+ resource1.updateStartTime(device1, 10);
+ resource1.updateEndTime(device1, 30);
+ resource1.updateStartTime(device2, 20);
+ resource1.updateEndTime(device2, 40);
+ resource1.serialize();
+ resource1.close();
+
+ TsFileResource resource2 = createTsFileAndResource();
+ resource2.updateStartTime(device1, 10);
+ resource2.updateEndTime(device1, 20);
+ resource2.updateStartTime(device2, 50);
+ resource2.updateEndTime(device2, 60);
+ resource2.serialize();
+ resource2.close();
+
+ TsFileResource resource3 = createTsFileAndResource();
+ resource3.updateStartTime(device1, 30);
+ resource3.updateEndTime(device1, 50);
+ resource3.updateStartTime(device2, 70);
+ resource3.updateEndTime(device2, 80);
+ resource3.serialize();
+ resource3.close();
+
+ int overlapFileNum =
+ TsFileOverlapValidationAndRepairTool.checkTimePartitionHasOverlap(
+ Arrays.asList(resource1, resource2, resource3));
+
+ Assert.assertEquals(2, overlapFileNum);
+ }
+
+ @Test
+ public void test4() throws IOException {
+ String device1 = "d1", device2 = "d2";
+ TsFileResource resource1 = createTsFileAndResource();
+ resource1.updateStartTime(device1, 10);
+ resource1.updateEndTime(device1, 30);
+ resource1.updateStartTime(device2, 20);
+ resource1.updateEndTime(device2, 40);
+ resource1.serialize();
+ resource1.close();
+
+ TsFileResource resource2 = createTsFileAndResource();
+ resource2.updateStartTime(device1, 10);
+ resource2.updateEndTime(device1, 50);
+ resource2.updateStartTime(device2, 50);
+ resource2.updateEndTime(device2, 60);
+ resource2.serialize();
+ resource2.close();
+
+ TsFileResource resource3 = createTsFileAndResource();
+ resource3.updateStartTime(device1, 40);
+ resource3.updateEndTime(device1, 50);
+ resource3.updateStartTime(device2, 70);
+ resource3.updateEndTime(device2, 80);
+ resource3.serialize();
+ resource3.close();
+
+ int overlapFileNum =
+ TsFileOverlapValidationAndRepairTool.checkTimePartitionHasOverlap(
+ Arrays.asList(resource1, resource2, resource3));
+
+ Assert.assertEquals(1, overlapFileNum);
+ }
+
+ private TsFileResource createTsFileAndResource() throws IOException {
+ TsFileResource resource = createEmptyFileAndResource(true);
+ TsFileIOWriter writer = new TsFileIOWriter(resource.getTsFile());
+ writer.endFile();
+ writer.close();
+ return resource;
+ }
+}