curcur commented on a change in pull request #13501: URL: https://github.com/apache/flink/pull/13501#discussion_r498890005
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/BufferBuilder.java ########## @@ -86,11 +94,34 @@ public int append(ByteBuffer source) { int available = getMaxCapacity() - positionMarker.getCached(); int toCopy = Math.min(needed, available); + // Each Data BufferBuilder starts with a 4-byte integer header + // Since length can only be 0 or positive numbers, the first bit of the integer + // is used to identify whether the first record is partial (1) or not (0) + // The remaining 31 bits stands for the length of the record remaining. + // The data written is not made visible to reader until {@link #commit()}, so the BufferBuilder + // ends either with a complete record or full buffer after append(); + if (isEmptyBufferBuilder()) { + available = available - BUFFER_BUILDER_HEADER_SIZE; + toCopy = Math.min(needed, available); + int header = Header.headerEncode(isPartialRecord(source), toCopy); + memorySegment.putIntBigEndian(positionMarker.getCached(), header); + positionMarker.move(BUFFER_BUILDER_HEADER_SIZE); + } + Review comment: 1. `ByteBuffer source` contains the header length of a record, we use that length to decide where a record ends; `Partial record` needs to address the problem that if a record spanning over multiple buffers and the first buffer is sent but lost due to failure. They are trying to address different problems. 2. The second question is more complicated. I will write my concerns a bit later, together with Stephan's question. ---------------------------------------------------------------- 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