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

    https://github.com/apache/spark/pull/9619#discussion_r44986915
  
    --- Diff: 
network/common/src/main/java/org/apache/spark/network/util/TransportFrameDecoder.java
 ---
    @@ -56,32 +56,43 @@ public void channelRead(ChannelHandlerContext ctx, 
Object data) throws Exception
           buffer = in.alloc().compositeBuffer();
         }
     
    -    buffer.writeBytes(in);
    +    buffer.addComponent(in).writerIndex(buffer.writerIndex() + 
in.readableBytes());
     
         while (buffer.isReadable()) {
    -      feedInterceptor();
    -      if (interceptor != null) {
    -        continue;
    -      }
    +      discardReadBytes();
    +      if (!feedInterceptor()) {
    +        ByteBuf frame = decodeNext();
    +        if (frame == null) {
    +          break;
    +        }
     
    -      ByteBuf frame = decodeNext();
    -      if (frame != null) {
             ctx.fireChannelRead(frame);
    -      } else {
    -        break;
           }
         }
     
    -    // We can't discard read sub-buffers if there are other references to 
the buffer (e.g.
    -    // through slices used for framing). This assumes that code that 
retains references
    -    // will call retain() from the thread that called "fireChannelRead()" 
above, otherwise
    -    // ref counting will go awry.
    -    if (buffer != null && buffer.refCnt() == 1) {
    +    discardReadBytes();
    +  }
    +
    +  private void discardReadBytes() {
    +    // If the buffer's been retained by downstream code, then make a copy 
of the remaining
    +    // bytes into a new buffer. Otherwise, just discard stale components.
    +    if (buffer.refCnt() > 1) {
    --- End diff --
    
    @vanzin could you give a real case? Or this is just for correctness, even 
if downstream in Spark doesn't use `retain`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to