private synchronized void removeDeletionResource(DeletionResource deletionResource) {
    // Clean memory
    deleteNode2ResourcesMap.remove(deletionResource.getDeleteDataNode());
    // Clean disk
    ProgressIndex currentProgressIndex =
        ReplicateProgressDataNodeManager.extractLocalSimpleProgressIndex(
            deletionResource.getProgressIndex());

    try (Stream<Path> pathStream = Files.walk(Paths.get(storageDir.getPath()), 1)) {
      Path[] deletionPaths =
          pathStream
              .filter(Files::isRegularFile)
              .filter(path -> path.getFileName().toString().matches(DELETION_FILE_NAME_PATTERN))
              .filter(
                  path ->
                      isFileProgressCoveredByGivenProgress(
                          path.getFileName().toString(), currentProgressIndex))
              .sorted(this::compareFileProgressIndex)
              .toArray(Path[]::new);
      // File name represents the max progressIndex in its previous file. If currentProgressIndex is
      // larger than a fileName's progressIndex, it means that the file before this file has been
      // fully synchronized and can be deleted.
      // So here we cannot guarantee that the last file can be deleted, we can only guarantee that
      // the first n-1 files can be deleted (if the length of deletionPaths is n)
      for (int i = 0; i < deletionPaths.length - 1; i++) {
        File fileToDelete = deletionPaths[i].toFile();
        FileUtils.deleteFileOrDirectory(fileToDelete);
        LOGGER.info(
            "DeletionManager-{} delete deletion file in {} dir...", dataRegionId, fileToDelete);
      }
    } catch (IOException e) {
      LOGGER.warn(
          "DeletionManager-{} failed to delete file in {} dir, please manually check!",
          dataRegionId,
          storageDir);
    }
  }
This is a hook function, which will be automatically invoked when deletionResource's reference
count returns to 0.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/consensus/deletion/DeletionResourceManager.java