@Test
  public void getDeletedDevicesWithSameNameFromSeqFilesByFastPerformer2() throws Exception {
    TSFileDescriptor.getInstance().getConfig().setMaxDegreeOfIndexNode(3);
    int oldAlignedDeviceOffset = TsFileGeneratorUtils.alignDeviceOffset;
    TsFileGeneratorUtils.alignDeviceOffset = 0;
    registerTimeseriesInMManger(30, 5, true);
    createFiles(3, 10, 5, 100, 0, 0, 50, 50, true, true);
    createFiles(4, 30, 5, 100, 1000, 0, 50, 50, true, true);

    // generate mods file, delete d0 ~ d9 with aligned property
    List<String> seriesPaths = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 5; j++) {
        seriesPaths.add(COMPACTION_TEST_SG + PATH_SEPARATOR + "d" + i + PATH_SEPARATOR + "s" + j);
      }
    }
    generateModsFile(seriesPaths, seqResources, Long.MIN_VALUE, Long.MAX_VALUE);
    generateModsFile(seriesPaths, unseqResources, Long.MIN_VALUE, Long.MAX_VALUE);
    deleteTimeseriesInMManager(seriesPaths);

    // generate d0 ~ d9 with nonAligned property
    createFiles(2, 10, 15, 100, 2000, 2000, 50, 50, false, true);
    resetFileName(seqResources.get(7), 100);
    resetFileName(seqResources.get(8), 101);
    tsFileManager.addAll(seqResources, true);

    // sort the deviceId in lexicographical order from small to large
    List<IDeviceID> deviceIds = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
      deviceIds.add(
          IDeviceID.Factory.DEFAULT_FACTORY.create(
              "root.testsg.d" + (i + TsFileGeneratorUtils.getAlignDeviceOffset())));
    }
    deviceIds.sort(IDeviceID::compareTo);

    int deviceNum = 0;
    try (MultiTsFileDeviceIterator multiTsFileDeviceIterator =
        new MultiTsFileDeviceIterator(tsFileManager.getTsFileList(true))) {
      while (multiTsFileDeviceIterator.hasNextDevice()) {
        Pair<IDeviceID, Boolean> deviceInfo = multiTsFileDeviceIterator.nextDevice();
        Assert.assertEquals(deviceIds.get(deviceNum), deviceInfo.left);
        if (Integer.parseInt(deviceInfo.left.toString().substring(13)) < 10) {
          Assert.assertFalse(deviceInfo.right);
        } else {
          Assert.assertTrue(deviceInfo.right);
        }
        deviceNum++;
      }
    }
    Assert.assertEquals(30, deviceNum);

    List<IFullPath> timeseriesPaths = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
      for (int j = 0; j < 15; j++) {
        if (i < 10) {
          timeseriesPaths.add(
              new AlignedFullPath(
                  IDeviceID.Factory.DEFAULT_FACTORY.create(
                      COMPACTION_TEST_SG + PATH_SEPARATOR + "d" + i),
                  Collections.singletonList("s" + j),
                  Collections.singletonList(new MeasurementSchema("s" + j, TSDataType.INT64))));
        } else {
          timeseriesPaths.add(
              new NonAlignedFullPath(
                  IDeviceID.Factory.DEFAULT_FACTORY.create(
                      COMPACTION_TEST_SG + PATH_SEPARATOR + "d" + i),
                  new MeasurementSchema("s" + j, TSDataType.INT64)));
        }
      }
    }
    Map<IFullPath, List<TimeValuePair>> sourceData =
        readSourceFiles(timeseriesPaths, Collections.emptyList());

    InnerSpaceCompactionTask task =
        new InnerSpaceCompactionTask(
            0,
            tsFileManager,
            tsFileManager.getTsFileList(true),
            true,
            new FastCompactionPerformer(false),
            0L);
    Assert.assertTrue(task.start());

    validateSeqFiles(true);
    validateTargetDatas(sourceData, Collections.emptyList());

    // generate mods file, delete d0 ~ d9 with nonAligned property
    seriesPaths.clear();
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 15; j++) {
        seriesPaths.add(COMPACTION_TEST_SG + PATH_SEPARATOR + "d" + i + PATH_SEPARATOR + "s" + j);
      }
    }
    generateModsFile(
        seriesPaths, tsFileManager.getTsFileList(true), Long.MIN_VALUE, Long.MAX_VALUE);

    deleteTimeseriesInMManager(seriesPaths);

    // generate mods file, delete d0 ~ d9 with aligned property
    createFiles(1, 10, 5, 100, 2000, 2000, 50, 50, true, true);
    tsFileManager.add(seqResources.get(seqResources.size() - 1), true);

    timeseriesPaths.clear();
    for (int i = 0; i < 30; i++) {
      for (int j = 0; j < 15; j++) {
        timeseriesPaths.add(
            new AlignedFullPath(
                IDeviceID.Factory.DEFAULT_FACTORY.create(
                    COMPACTION_TEST_SG + PATH_SEPARATOR + "d" + i),
                Collections.singletonList("s" + j),
                Collections.singletonList(new MeasurementSchema("s" + j, TSDataType.INT64))));
      }
    }
    sourceData = readSourceFiles(timeseriesPaths, Collections.emptyList());

    // sort the deviceId in lexicographical order from small to large
    deviceIds = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
      deviceIds.add(
          IDeviceID.Factory.DEFAULT_FACTORY.create(
              "root.testsg.d" + (i + TsFileGeneratorUtils.getAlignDeviceOffset())));
    }
    deviceIds.sort(IDeviceID::compareTo);

    deviceNum = 0;
    try (MultiTsFileDeviceIterator multiTsFileDeviceIterator =
        new MultiTsFileDeviceIterator(tsFileManager.getTsFileList(true))) {
      while (multiTsFileDeviceIterator.hasNextDevice()) {
        Pair<IDeviceID, Boolean> deviceInfo = multiTsFileDeviceIterator.nextDevice();
        Assert.assertEquals(deviceIds.get(deviceNum), deviceInfo.left);
        Assert.assertTrue(deviceInfo.right);
        deviceNum++;
      }
    }
    Assert.assertEquals(30, deviceNum);
    TsFileGeneratorUtils.alignDeviceOffset = oldAlignedDeviceOffset;
    List<TsFileResource> targetResources =
        CompactionFileGeneratorUtils.getInnerCompactionTargetTsFileResources(
            tsFileManager.getTsFileList(true), true);
    FastCompactionPerformer performer =
        new FastCompactionPerformer(
            tsFileManager.getTsFileList(true), Collections.emptyList(), targetResources);
    performer.setSummary(new FastCompactionTaskSummary());
    performer.perform();

    CompactionUtils.moveTargetFile(
        targetResources, CompactionTaskType.INNER_SEQ, COMPACTION_TEST_SG);
    tsFileManager.replace(
        tsFileManager.getTsFileList(true), Collections.emptyList(), targetResources, 0);
    tsFileManager.getTsFileList(true).get(0).setStatusForTest(TsFileResourceStatus.NORMAL);

    validateSeqFiles(true);
    validateTargetDatas(sourceData, Collections.emptyList());
  }
Create device with aligned property. Deleted it and create new device with same deviceID but
nonAligned property. Compact it. Then deleted it and create new device with same deviceID but
aligned property. Check whether the deviceID and its property can be obtained correctly.
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/utils/MultiTsFileDeviceIteratorTest.java