@SafeVarargs
  public static void prepareCompactionModFiles(
      List<TsFileResource> targets, List<TsFileResource>... sourceLists) throws IOException {
    if (!TsFileResource.useSharedModFile) {
      Set<ModificationFile> compactionModFileSet =
          targets.stream()
              .map(
                  tsFileResource -> {
                    try {
                      return tsFileResource.getModFileForWrite();
                    } catch (IOException e) {
                      logger.error("Can not get mod file of {}", tsFileResource, e);
                      return null;
                    }
                  })
              .filter(Objects::nonNull)
              .collect(Collectors.toSet());
      for (List<TsFileResource> sourceList : sourceLists) {
        for (TsFileResource tsFileResource : sourceList) {
          tsFileResource.getModFileForWrite().setCascadeFile(compactionModFileSet);
        }
      }
      return;
    }
    TsFileResource firstSource = sourceLists[0].get(0);
    TsFileResource firstTarget = targets.get(0);
    ModFileManagement modFileManagement = firstSource.getModFileManagement();
    ModificationFile modificationFile = modFileManagement.allocateFor(firstTarget);
    for (TsFileResource tsFileResource : targets) {
      tsFileResource.setModFileManagement(modFileManagement);
      modFileManagement.addReference(tsFileResource, modificationFile);
      tsFileResource.setSharedModFile(modificationFile, false);
    }
    for (List<TsFileResource> sources : sourceLists) {
      for (TsFileResource tsFileResource : sources) {
        // lock so that the compaction mod file will not be omitted by deletion
        tsFileResource.writeLock();
        tsFileResource.setCompactionModFile(modificationFile);
        tsFileResource.writeUnlock();
      }
    }
  }
Collect all the compaction modification files of source files, and combines them as the
modification file of target file.

@throws IOException if io errors occurred
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/CompactionUtils.java