public void spillSortedData(List<SortKey> sortedData) throws IoTDBException {
    List<TsBlock> tsBlocks = new ArrayList<>();
    TsBlockBuilder tsBlockBuilder = new TsBlockBuilder(dataTypeList);
    ColumnBuilder[] columnBuilders = tsBlockBuilder.getValueColumnBuilders();
    ColumnBuilder timeColumnBuilder = tsBlockBuilder.getTimeColumnBuilder();

    for (SortKey sortKey : sortedData) {
      writeSortKey(sortKey, columnBuilders, timeColumnBuilder);
      tsBlockBuilder.declarePosition();
      if (tsBlockBuilder.isFull()) {
        tsBlocks.add(buildSortedTsBlock(tsBlockBuilder));
        tsBlockBuilder.reset();
        timeColumnBuilder = tsBlockBuilder.getTimeColumnBuilder();
      }
    }

    if (!tsBlockBuilder.isEmpty()) {
      tsBlocks.add(buildSortedTsBlock(tsBlockBuilder));
    }

    try {
      spill(tsBlocks);
    } catch (IOException e) {
      throw new IoTDBException(
          "Create file error: " + filePrefix + (fileIndex - 1) + FILE_SUFFIX,
          e,
          TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
    }
  }
todo: directly serialize the sorted line instead of copy into a new tsBlock.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/sort/DiskSpiller.java