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);
}
Aggregations