use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.
the class RemoteInputChannel method announce.
private SequenceBuffer announce(SequenceBuffer sequenceBuffer) throws IOException {
checkState(!sequenceBuffer.buffer.isBuffer(), "Only a CheckpointBarrier can be announced but found %s", sequenceBuffer.buffer);
checkAnnouncedOnlyOnce(sequenceBuffer);
AbstractEvent event = EventSerializer.fromBuffer(sequenceBuffer.buffer, getClass().getClassLoader());
checkState(event instanceof CheckpointBarrier, "Only a CheckpointBarrier can be announced but found %s", sequenceBuffer.buffer);
CheckpointBarrier barrier = (CheckpointBarrier) event;
return new SequenceBuffer(EventSerializer.toBuffer(new EventAnnouncement(barrier, sequenceBuffer.sequenceNumber), true), sequenceBuffer.sequenceNumber);
}
use of org.apache.flink.runtime.event.AbstractEvent 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);
}
use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.
the class ChannelStatePersister method checkForBarrier.
protected OptionalLong checkForBarrier(Buffer buffer) throws IOException {
AbstractEvent event = parseEvent(buffer);
if (event instanceof CheckpointBarrier) {
long barrierId = ((CheckpointBarrier) event).getId();
long expectedBarrierId = checkpointStatus == CheckpointStatus.COMPLETED ? lastSeenBarrier + 1 : lastSeenBarrier;
if (barrierId >= expectedBarrierId) {
logEvent("found barrier", barrierId);
checkpointStatus = CheckpointStatus.BARRIER_RECEIVED;
lastSeenBarrier = barrierId;
return OptionalLong.of(lastSeenBarrier);
} else {
logEvent("ignoring barrier", barrierId);
}
}
if (event instanceof EventAnnouncement) {
// NOTE: only remote channels
EventAnnouncement announcement = (EventAnnouncement) event;
if (announcement.getAnnouncedEvent() instanceof CheckpointBarrier) {
long barrierId = ((CheckpointBarrier) announcement.getAnnouncedEvent()).getId();
logEvent("found announcement for barrier", barrierId);
return OptionalLong.of(barrierId);
}
}
return OptionalLong.empty();
}
use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.
the class ChannelStatePersister method parseEvent.
/**
* Parses the buffer as an event and returns the {@link CheckpointBarrier} if the event is
* indeed a barrier or returns null in all other cases.
*/
@Nullable
protected AbstractEvent parseEvent(Buffer buffer) throws IOException {
if (buffer.isBuffer()) {
return null;
} else {
AbstractEvent event = EventSerializer.fromBuffer(buffer, getClass().getClassLoader());
// reset the buffer because it would be deserialized again in SingleInputGate while
// getting next buffer.
// we can further improve to avoid double deserialization in the future.
buffer.setReaderIndex(0);
return event;
}
}
Aggregations