@Override
  protected boolean doCompaction() {
    recoverMemoryStatus = true;
    boolean isSuccess;

    if (!tsFileManager.isAllowCompaction()) {
      return true;
    }
    if (fullyDirtyFiles.isEmpty() && filesView.sourceFilesInCompactionPerformer.isEmpty()) {
      LOGGER.info(
          "{}-{} [Compaction] Settle compaction file list is empty, end it",
          storageGroupName,
          dataRegionId);
    }
    long startTime = System.currentTimeMillis();

    LOGGER.info(
        "{}-{} [Compaction] SettleCompaction task starts with {} fully_dirty files "
            + "and {} partially_dirty files. "
            + "Fully_dirty files : {}, partially_dirty files : {} . "
            + "Fully_dirty files size is {} MB, "
            + "partially_dirty file size is {} MB. "
            + "Memory cost is {} MB.",
        storageGroupName,
        dataRegionId,
        fullyDirtyFiles.size(),
        filesView.sourceFilesInCompactionPerformer.size(),
        fullyDirtyFiles,
        filesView.sourceFilesInCompactionPerformer,
        fullyDirtyFileSize / 1024 / 1024,
        partiallyDirtyFileSize / 1024 / 1024,
        memoryCost == 0 ? 0 : (double) memoryCost / 1024 / 1024);

    List<TsFileResource> allSourceFiles = getAllSourceTsFiles();
    logFile =
        new File(
            allSourceFiles.get(0).getTsFile().getAbsolutePath()
                + CompactionLogger.SETTLE_COMPACTION_LOG_NAME_SUFFIX);
    try (SimpleCompactionLogger compactionLogger = new SimpleCompactionLogger(logFile)) {
      calculateSourceFilesAndTargetFiles();
      isHoldingWriteLock = new boolean[this.filesView.sourceFilesInLog.size()];
      Arrays.fill(isHoldingWriteLock, false);
      compactionLogger.logSourceFiles(fullyDirtyFiles);
      compactionLogger.logEmptyTargetFiles(fullyDirtyFiles);
      compactionLogger.logSourceFiles(filesView.sourceFilesInCompactionPerformer);
      compactionLogger.logTargetFiles(filesView.targetFilesInLog);
      compactionLogger.force();

      isSuccess = settleWithFullyDirtyFiles();
      // In order to prevent overlap of sequence files after settle task, partially_dirty files can
      // only be settled after fully_dirty files are settled successfully, because multiple
      // partially_dirty files will be settled into one file.
      if (isSuccess) {
        settleWithPartiallyDirtyFiles(compactionLogger);
      }

      double costTime = (System.currentTimeMillis() - startTime) / 1000.0d;
      if (isSuccess) {
        if (partiallyDirtyFileSize == 0) {
          LOGGER.info(
              "{}-{} [Compaction] SettleCompaction task finishes successfully, time cost is {} s."
                  + "Fully_dirty files num is {}.",
              storageGroupName,
              dataRegionId,
              String.format("%.2f", costTime),
              fullyDirtyFiles.size());
        } else {
          LOGGER.info(
              "{}-{} [Compaction] SettleCompaction task finishes successfully, time cost is {} s, compaction speed is {} MB/s."
                  + "Fully_dirty files num is {} and partially_dirty files num is {}.",
              storageGroupName,
              dataRegionId,
              String.format("%.2f", costTime),
              String.format("%.2f", (partiallyDirtyFileSize) / 1024.0d / 1024.0d / costTime),
              fullyDirtyFiles.size(),
              filesView.sourceFilesInCompactionPerformer.size());
        }
      } else {
        LOGGER.info(
            "{}-{} [Compaction] SettleCompaction task finishes with some error, time cost is {} s."
                + "Fully_dirty files num is {} and there are {} files fail to delete.",
            storageGroupName,
            dataRegionId,
            String.format("%.2f", costTime),
            fullyDirtyFiles.size(),
            allSourceFiles.size() - fullyDeletedSuccessNum);
      }
    } catch (Exception e) {
      isSuccess = false;
      handleException(LOGGER, e);
      recover();
    } finally {
      releaseAllLocks();
      try {
        Files.deleteIfExists(logFile.toPath());
      } catch (IOException e) {
        handleException(LOGGER, e);
      }
      // may fail to set status if the status of target resource is DELETED
      for (TsFileResource resource : filesView.targetFilesInLog) {
        resource.setStatus(TsFileResourceStatus.NORMAL);
      }
    }
    return isSuccess;
  }
This settle task contains fully_dirty files and partially_dirty files. This task will do the
following two things respectively: 1. Settle all fully_dirty files by deleting them directly. 2.
Settle partially_dirty files by cleaning them with inner space compaction task. The
partially_dirty files will be compacted into one target file.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/task/SettleCompactionTask.java