Search in sources :

Example 21 with EndOfData

use of org.apache.flink.runtime.io.network.api.EndOfData in project flink by apache.

the class SingleInputGate method transformEvent.

private BufferOrEvent transformEvent(Buffer buffer, boolean moreAvailable, InputChannel currentChannel, boolean morePriorityEvents) throws IOException, InterruptedException {
    final AbstractEvent event;
    try {
        event = EventSerializer.fromBuffer(buffer, getClass().getClassLoader());
    } finally {
        buffer.recycleBuffer();
    }
    if (event.getClass() == EndOfPartitionEvent.class) {
        synchronized (inputChannelsWithData) {
            checkState(!channelsWithEndOfPartitionEvents.get(currentChannel.getChannelIndex()));
            channelsWithEndOfPartitionEvents.set(currentChannel.getChannelIndex());
            hasReceivedAllEndOfPartitionEvents = channelsWithEndOfPartitionEvents.cardinality() == numberOfInputChannels;
            enqueuedInputChannelsWithData.clear(currentChannel.getChannelIndex());
            if (inputChannelsWithData.contains(currentChannel)) {
                inputChannelsWithData.getAndRemove(channel -> channel == currentChannel);
            }
        }
        if (hasReceivedAllEndOfPartitionEvents) {
            // Because of race condition between:
            // 1. releasing inputChannelsWithData lock in this method and reaching this place
            // 2. empty data notification that re-enqueues a channel we can end up with
            // moreAvailable flag set to true, while we expect no more data.
            checkState(!moreAvailable || !pollNext().isPresent());
            moreAvailable = false;
            markAvailable();
        }
        currentChannel.releaseAllResources();
    } else if (event.getClass() == EndOfData.class) {
        synchronized (inputChannelsWithData) {
            checkState(!channelsWithEndOfUserRecords.get(currentChannel.getChannelIndex()));
            channelsWithEndOfUserRecords.set(currentChannel.getChannelIndex());
            hasReceivedEndOfData = channelsWithEndOfUserRecords.cardinality() == numberOfInputChannels;
            shouldDrainOnEndOfData &= ((EndOfData) event).getStopMode() == StopMode.DRAIN;
        }
    }
    return new BufferOrEvent(event, buffer.getDataType().hasPriority(), currentChannel.getChannelInfo(), moreAvailable, buffer.getSize(), morePriorityEvents);
}
Also used : EndOfData(org.apache.flink.runtime.io.network.api.EndOfData) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent)

Aggregations

EndOfData (org.apache.flink.runtime.io.network.api.EndOfData)21 Test (org.junit.Test)12 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)6 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)6 ResultPartitionWriter (org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter)6 ResultPartition (org.apache.flink.runtime.io.network.partition.ResultPartition)6 CompletingCheckpointResponder (org.apache.flink.streaming.util.CompletingCheckpointResponder)6 ArrayList (java.util.ArrayList)5 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)5 SourceOperatorFactory (org.apache.flink.streaming.api.operators.SourceOperatorFactory)5 IOException (java.io.IOException)4 EndOfPartitionEvent (org.apache.flink.runtime.io.network.api.EndOfPartitionEvent)4 StopMode (org.apache.flink.runtime.io.network.api.StopMode)4 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)4 Duration (java.time.Duration)3 ArrayDeque (java.util.ArrayDeque)3 Collections (java.util.Collections)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 JobID (org.apache.flink.api.common.JobID)3 BasicTypeInfo (org.apache.flink.api.common.typeinfo.BasicTypeInfo)3