@SuppressWarnings({"squid:S3776", "squid:S135"})
  private List<List<TsFileResource>> selectTsFileResourcesByLevel(int level) throws IOException {
    List<TsFileResource> selectedFileList = new ArrayList<>();
    long selectedFileSize = 0L;
    long targetCompactionFileSize = config.getTargetCompactionFileSize();
    int fileLimit = config.getInnerCompactionCandidateFileNum();

    List<List<TsFileResource>> taskList = new ArrayList<>();
    for (TsFileResource currentFile : tsFileResources) {
      TsFileNameGenerator.TsFileName currentName =
          TsFileNameGenerator.getTsFileName(currentFile.getTsFile().getName());
      if (currentName.getInnerCompactionCnt() != level) {
        // meet files of another level
        if (selectedFileList.size() > 1) {
          taskList.add(new ArrayList<>(selectedFileList));
        }
        selectedFileList = new ArrayList<>();
        selectedFileSize = 0L;
        continue;
      }
      if (cannotSelectCurrentFileToNormalCompaction(currentFile)) {
        selectedFileList.clear();
        selectedFileSize = 0L;
        continue;
      }

      long totalSizeIfSelectCurrentFile = selectedFileSize + currentFile.getTsFileSize();
      boolean canNotAddCurrentFileIntoCurrentTask =
          totalSizeIfSelectCurrentFile > targetCompactionFileSize
              || selectedFileList.size() >= fileLimit;
      if (canNotAddCurrentFileIntoCurrentTask) {
        // total file size or num will beyond the threshold if select current file, stop the
        // selection of current task
        if (selectedFileList.size() > 1) {
          // submit the task
          taskList.add(new ArrayList<>(selectedFileList));
        }
        // add current file in a new selected file list
        selectedFileList = new ArrayList<>();
        selectedFileList.add(currentFile);
        selectedFileSize = currentFile.getTsFileSize();
      } else {
        LOGGER.debug("Current File is {}, size is {}", currentFile, currentFile.getTsFileSize());
        selectedFileList.add(currentFile);
        selectedFileSize += currentFile.getTsFileSize();
        LOGGER.debug(
            "Add tsfile {}, current select file num is {}, size is {}",
            currentFile,
            selectedFileList.size(),
            selectedFileSize);
      }
    }

    // if the selected file size reach the condition to submit
    if (selectedFileList.size() == fileLimit) {
      taskList.add(new ArrayList<>(selectedFileList));
      selectedFileList.clear();
      selectedFileSize = 0;
    }

    // if next time partition exists
    // submit a merge task even it does not meet the requirement for file num or file size
    if (hasNextTimePartition && selectedFileList.size() > 1) {
      taskList.add(new ArrayList<>(selectedFileList));
    }
    return taskList;
  }
This method searches for all files on the given level. If there are consecutive files on the
level that meet the system preset conditions (the number exceeds 10 or the total file size
exceeds 2G), a compaction task is created for the batch of files and placed in the
taskPriorityQueue queue , and continue to search for the next batch. If at least one batch of
files to be compacted is found on this layer, it will return false (indicating that it will no
longer search for higher layers), otherwise it will return true.

@param level the level to be searched
@return return whether to continue the search to higher levels
@throws IOException if the name of tsfile is incorrect
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/SizeTieredCompactionSelector.java