public void deleteByTable(RelationalDeleteDataNode node) throws IOException {
    if (node.getDatabaseName() != null && !node.getDatabaseName().equals(databaseName)) {
      // not targeted on this database, return
      return;
    }

    if (SettleService.getINSTANCE().getFilesToBeSettledCount().get() != 0) {
      throw new IOException(
          "Delete failed. " + "Please do not delete until the old files settled.");
    }
    List<TableDeletionEntry> modEntries = node.getModEntries();

    logger.info("[Deletion] Executing table deletion {}", node);

    writeLock("delete");
    boolean hasReleasedLock = false;
    try {
      if (deleted) {
        return;
      }
      TableDeviceSchemaCache.getInstance()
          .invalidateLastCache(getDatabaseName(), modEntries.get(0).getTableName());
      List<WALFlushListener> walListeners = logDeletionInWAL(node);

      for (WALFlushListener walFlushListener : walListeners) {
        if (walFlushListener.waitForResult() == WALFlushListener.Status.FAILURE) {
          logger.error("Fail to log delete to wal.", walFlushListener.getCause());
          throw walFlushListener.getCause();
        }
      }

      List<List<TsFileResource>> sealedTsFileResourceLists = new ArrayList<>(modEntries.size());
      for (TableDeletionEntry modEntry : modEntries) {
        List<TsFileResource> sealedTsFileResource = new ArrayList<>();
        List<TsFileResource> unsealedTsFileResource = new ArrayList<>();
        getTwoKindsOfTsFiles(
            sealedTsFileResource,
            unsealedTsFileResource,
            modEntry.getStartTime(),
            modEntry.getEndTime());
        logger.debug("[Deletion] unsealed files for {}: {}", modEntry, unsealedTsFileResource);
        deleteDataInUnsealedFiles(unsealedTsFileResource, modEntry, sealedTsFileResource);
        logger.debug("[Deletion] sealed files for {}: {}", modEntry, sealedTsFileResource);
        sealedTsFileResourceLists.add(sealedTsFileResource);
      }

      // capture deleteDataNode and wait it to be persisted to DAL.
      DeletionResource deletionResource =
          PipeInsertionDataNodeListener.getInstance().listenToDeleteData(dataRegionId, node);
      // just get result. We have already waited for result in `listenToDeleteData`
      if (deletionResource != null && deletionResource.waitForResult() == Status.FAILURE) {
        throw deletionResource.getCause();
      }

      writeUnlock();
      hasReleasedLock = true;

      for (int i = 0; i < modEntries.size(); i++) {
        deleteDataInSealedFiles(sealedTsFileResourceLists.get(i), modEntries.get(i));
      }
    } catch (Exception e) {
      throw new IOException(e);
    } finally {
      if (!hasReleasedLock) {
        writeUnlock();
      }
    }
  }
Separate tsfiles in TsFileManager to sealedList and unsealedList.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java