public void writeToDataRegion(DataRegion dataRegion, LoadTsFilePieceNode pieceNode, String uuid)
      throws IOException {
    if (!uuid2WriterManager.containsKey(uuid)) {
      synchronized (uuid2CleanupTask) {
        final CleanupTask cleanupTask =
            new CleanupTask(uuid, CONFIG.getLoadCleanupTaskExecutionDelayTimeSeconds() * 1000);
        uuid2CleanupTask.put(uuid, cleanupTask);
        cleanupTaskQueue.add(cleanupTask);
      }
    }

    final Optional<CleanupTask> cleanupTask = Optional.of(uuid2CleanupTask.get(uuid));
    cleanupTask.ifPresent(CleanupTask::markLoadTaskRunning);
    try {
      final AtomicReference<Exception> exception = new AtomicReference<>();
      final TsFileWriterManager writerManager =
          uuid2WriterManager.computeIfAbsent(
              uuid,
              o -> {
                try {
                  return new TsFileWriterManager(new File(getNextFolder(), uuid));
                } catch (DiskSpaceInsufficientException e) {
                  exception.set(e);
                  return null;
                }
              });
      if (exception.get() != null || writerManager == null) {
        throw new IOException(
            "Failed to create TsFileWriterManager for uuid "
                + uuid
                + " because of insufficient disk space.",
            exception.get());
      }

      for (TsFileData tsFileData : pieceNode.getAllTsFileData()) {
        switch (tsFileData.getType()) {
          case CHUNK:
            ChunkData chunkData = (ChunkData) tsFileData;
            writerManager.write(
                new DataPartitionInfo(dataRegion, chunkData.getTimePartitionSlot()), chunkData);
            break;
          case DELETION:
            writerManager.writeDeletion(dataRegion, (DeletionData) tsFileData);
            break;
          default:
            throw new IOException("Unsupported TsFileData type: " + tsFileData.getType());
        }
      }
    } finally {
      cleanupTask.ifPresent(CleanupTask::markLoadTaskNotRunning);
    }
  }
{@link LoadTsFileManager} is used for dealing with {@link LoadTsFilePieceNode} and {@link
LoadCommand}. This class turn the content of a piece of loading TsFile into a new TsFile. When
DataNode finish transfer pieces, this class will flush all TsFile and load them into IoTDB, or
delete all.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/LoadTsFileManager.java