AHeise commented on a change in pull request #11751: [FLINK-16587][network] 
Provide the method for getting unconsumed buffer from RecordDeserializer
URL: https://github.com/apache/flink/pull/11751#discussion_r408821337
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/api/serialization/SpillingAdaptiveSpanningRecordDeserializer.java
 ##########
 @@ -579,27 +584,36 @@ private void addNextChunkFromMemorySegment(MemorySegment 
segment, int offset, in
                        }
                }
 
-               @Nullable
-               MemorySegment copyToTargetSegment() {
+               Optional<MemorySegment> getUnconsumedSegment() throws 
IOException {
                        // for the case of only partial length, no data
                        final int position = lengthBuffer.position();
                        if (position > 0) {
-                               MemorySegment segment = 
MemorySegmentFactory.allocateUnpooledSegment(lengthBuffer.remaining());
-                               segment.put(0, lengthBuffer, 
lengthBuffer.remaining());
-                               lengthBuffer.position(position);
-                               return segment;
+                               MemorySegment segment = 
MemorySegmentFactory.allocateUnpooledSegment(position);
+                               lengthBuffer.position(0);
+                               segment.put(0, lengthBuffer, position);
+                               return Optional.of(segment);
                        }
 
                        // for the case of full length, partial data in buffer
                        if (recordLength > THRESHOLD_FOR_SPILLING) {
                                throw new 
UnsupportedOperationException("Unaligned checkpoint currently do not support 
spilled " +
                                        "records.");
                        } else if (recordLength != -1) {
-                               return MemorySegmentFactory.wrap(buffer);
+                               int leftOverSize = leftOverLimit - 
leftOverStart;
+                               int unconsumedSize = Integer.BYTES + 
accumulatedRecordBytes + leftOverSize;
+                               DataOutputSerializer serializer = new 
DataOutputSerializer(unconsumedSize);
+                               serializer.writeInt(recordLength);
+                               serializer.write(buffer, 0, 
accumulatedRecordBytes);
+                               if (leftOverSize > 0) {
+                                       
serializer.write(checkNotNull(leftOverData), leftOverStart, leftOverSize);
 
 Review comment:
   nit: `checkNotNull` is not doing anything. The same NPE will be thrown by 
`serializer#write`. Either leave out or replace by `checkState` with a 
descriptive messsage.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to