curcur commented on a change in pull request #13614: URL: https://github.com/apache/flink/pull/13614#discussion_r505277251
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/BufferWritingResultPartition.java ########## @@ -128,26 +128,40 @@ protected void flushAllSubpartitions(boolean finishProducers) { @Override public void emitRecord(ByteBuffer record, int targetSubpartition) throws IOException { - do { - final BufferBuilder bufferBuilder = getSubpartitionBufferBuilder(targetSubpartition); - bufferBuilder.appendAndCommit(record); + BufferBuilder buffer = subpartitionBufferBuilders[targetSubpartition]; - if (bufferBuilder.isFull()) { - finishSubpartitionBufferBuilder(targetSubpartition); - } - } while (record.hasRemaining()); + if (buffer == null) { + buffer = getNewEmptySubpartitionBufferBuilderForNewRecord(targetSubpartition); + } + buffer.appendAndCommit(record); + + while (record.hasRemaining()) { + finishSubpartitionBufferBuilder(targetSubpartition); + buffer = getNewEmptySubpartitionBufferBuilderForRecordContinuation(record, targetSubpartition); Review comment: I've rewritten the first commit. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org