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

    https://github.com/apache/flink/pull/2805#discussion_r91306180
  
    --- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/api/writer/RecordWriter.java
 ---
    @@ -131,35 +132,30 @@ private void sendToTarget(T record, int 
targetChannel) throws IOException, Inter
        }
     
        public void broadcastEvent(AbstractEvent event) throws IOException, 
InterruptedException {
    -           for (int targetChannel = 0; targetChannel < numChannels; 
targetChannel++) {
    -                   RecordSerializer<T> serializer = 
serializers[targetChannel];
    -
    -                   synchronized (serializer) {
    -                           Buffer buffer = serializer.getCurrentBuffer();
    -                           if (buffer != null) {
    -                                   writeAndClearBuffer(buffer, 
targetChannel, serializer);
    -                           } else if (serializer.hasData()) {
    -                                   throw new IllegalStateException("No 
buffer, but serializer has buffered data.");
    -                           }
    -
    -                           targetPartition.writeEvent(event, 
targetChannel);
    -                   }
    -           }
    -   }
    +           final Buffer eventBuffer = EventSerializer.toBuffer(event);
    +           try {
    +                   for (int targetChannel = 0; targetChannel < 
numChannels; targetChannel++) {
    +                           RecordSerializer<T> serializer = 
serializers[targetChannel];
     
    -   public void sendEndOfSuperstep() throws IOException, 
InterruptedException {
    -           for (int targetChannel = 0; targetChannel < numChannels; 
targetChannel++) {
    -                   RecordSerializer<T> serializer = 
serializers[targetChannel];
    +                           synchronized (serializer) {
    +                                   Buffer buffer = 
serializer.getCurrentBuffer();
    +                                   if (buffer != null) {
    +                                           writeAndClearBuffer(buffer, 
targetChannel, serializer);
    +                                   } else if (serializer.hasData()) {
    +                                           // sanity check
    +                                           throw new 
IllegalStateException("No buffer, but serializer has buffered data.");
    +                                   }
     
    -                   synchronized (serializer) {
    -                           Buffer buffer = serializer.getCurrentBuffer();
    -                           if (buffer != null) {
    -                                   writeAndClearBuffer(buffer, 
targetChannel, serializer);
    +                                   // retain the buffer so that it can be 
recycled by each channel of targetPartition
    +                                   eventBuffer.retain();
    --- End diff --
    
    done, thanks
    
    I opened [FLINK-5277] for the ResultPartition#add test: 
https://issues.apache.org/jira/browse/FLINK-5277


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to