[ 
https://issues.apache.org/jira/browse/FLINK-7515?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16233816#comment-16233816
 ] 

ASF GitHub Bot commented on FLINK-7515:
---------------------------------------

Github user NicoK commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4592#discussion_r148212023
  
    --- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyMessage.java
 ---
    @@ -64,12 +65,53 @@
     
        // 
------------------------------------------------------------------------
     
    +   /**
    +    * Allocates a new (header and contents) buffer and adds some header 
information for the frame
    +    * decoder.
    +    *
    +    * <p>Before sending the buffer, you must write the actual length after 
adding the contents as
    +    * an integer to position <tt>0</tt>!
    +    *
    +    * @param allocator
    +    *              byte buffer allocator to use
    +    * @param id
    +    *              {@link NettyMessage} subclass ID
    +    *
    +    * @return a newly allocated direct buffer with header data written for 
{@link
    +    * NettyMessageDecoder}
    +    */
        private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte 
id) {
    -           return allocateBuffer(allocator, id, 0);
    +           return allocateBuffer(allocator, id, -1);
        }
     
    +   /**
    +    * Allocates a new (header and contents) buffer and adds some header 
information for the frame
    +    * decoder.
    +    *
    +    * <p>If the <tt>length</tt> is unknown, you must write the actual 
length after adding the
    +    * contents as an integer to position <tt>0</tt>!
    +    *
    +    * @param allocator
    +    *              byte buffer allocator to use
    +    * @param id
    +    *              {@link NettyMessage} subclass ID
    +    * @param length
    +    *              content length (or <tt>-1</tt> if unknown)
    +    *
    +    * @return a newly allocated direct buffer with header data written for 
{@link
    +    * NettyMessageDecoder}
    +    */
        private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte 
id, int length) {
    -           final ByteBuf buffer = length != 0 ? 
allocator.directBuffer(HEADER_LENGTH + length) : allocator.directBuffer();
    +           Preconditions.checkArgument(length <= Integer.MAX_VALUE - 
HEADER_LENGTH);
    --- End diff --
    
    why not...


> allow actual 0-length content in NettyMessage#allocateBuffer()
> --------------------------------------------------------------
>
>                 Key: FLINK-7515
>                 URL: https://issues.apache.org/jira/browse/FLINK-7515
>             Project: Flink
>          Issue Type: Sub-task
>          Components: Network
>    Affects Versions: 1.4.0
>            Reporter: Nico Kruber
>            Assignee: Nico Kruber
>            Priority: Minor
>
> Previously, length {{0}} meant "unknown content length" but there are cases 
> where the actual length is 0 and we do not need a larger buffer. Let's use 
> {{-1}} for tagging the special case instead.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to