Github user pnowojski commented on a diff in the pull request:
https://github.com/apache/flink/pull/5570#discussion_r170911325
--- Diff:
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyMessage.java
---
@@ -188,58 +186,83 @@ public void write(ChannelHandlerContext ctx, Object
msg, ChannelPromise promise)
ctx.write(msg, promise);
}
}
-
- // Create the frame length decoder here as it depends on the
encoder
- //
- //
+------------------+------------------+--------++----------------+
- // | FRAME LENGTH (4) | MAGIC NUMBER (4) | ID (1) || CUSTOM
MESSAGE |
- //
+------------------+------------------+--------++----------------+
- static LengthFieldBasedFrameDecoder createFrameLengthDecoder() {
- return new
LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, -4, 4);
- }
}
- @ChannelHandler.Sharable
- static class NettyMessageDecoder extends
MessageToMessageDecoder<ByteBuf> {
+ /**
+ * Message decoder based on netty's {@link
LengthFieldBasedFrameDecoder} but avoiding the
+ * additional memory copy inside {@link
#extractFrame(ChannelHandlerContext, ByteBuf, int, int)}
+ * since we completely decode the {@link ByteBuf} inside {@link
#decode(ChannelHandlerContext,
+ * ByteBuf)} and will not re-use it afterwards.
+ *
+ * <p>The frame-length encoder will be based on this transmission
scheme created by {@link NettyMessage#allocateBuffer(ByteBufAllocator, byte,
int)}:
+ * <pre>
+ * +------------------+------------------+--------++----------------+
+ * | FRAME LENGTH (4) | MAGIC NUMBER (4) | ID (1) || CUSTOM MESSAGE |
+ * +------------------+------------------+--------++----------------+
+ * </pre>
+ */
+ static class NettyMessageDecoder extends LengthFieldBasedFrameDecoder {
+ private final boolean restoreOldNettyBehaviour;
--- End diff --
drop the unused field?
---