curcur commented on a change in pull request #13456:
URL: https://github.com/apache/flink/pull/13456#discussion_r494377293



##########
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);

Review comment:
       > Can `available` be less than `BUFFER_BUILDER_HEADER_SIZE`?
   > Then `toCopy` can be negative.
   
   the `if` clause check makes sure the builder is empty; buffer size minimal 
be 4096 bytes, so no.




----------------------------------------------------------------
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:
[email protected]


Reply via email to