Search in sources :

Example 21 with AbstractEvent

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);
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) EventAnnouncement(org.apache.flink.runtime.io.network.api.EventAnnouncement) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent)

Example 22 with AbstractEvent

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);
}
Also used : EndOfData(org.apache.flink.runtime.io.network.api.EndOfData) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent)

Example 23 with AbstractEvent

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();
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) EventAnnouncement(org.apache.flink.runtime.io.network.api.EventAnnouncement) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent)

Example 24 with AbstractEvent

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;
    }
}
Also used : AbstractEvent(org.apache.flink.runtime.event.AbstractEvent) Nullable(javax.annotation.Nullable)

Aggregations

AbstractEvent (org.apache.flink.runtime.event.AbstractEvent)24 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)6 IOException (java.io.IOException)5 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)5 Test (org.junit.Test)5 EventAnnouncement (org.apache.flink.runtime.io.network.api.EventAnnouncement)4 BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)4 ByteBuffer (java.nio.ByteBuffer)3 EndOfData (org.apache.flink.runtime.io.network.api.EndOfData)3 BufferOrEvent (org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)3 StreamElement (org.apache.flink.streaming.runtime.streamrecord.StreamElement)3 ByteOrder (java.nio.ByteOrder)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Nullable (javax.annotation.Nullable)2 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)2 CheckpointMetricsBuilder (org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder)2 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)2 CancelCheckpointMarker (org.apache.flink.runtime.io.network.api.CancelCheckpointMarker)2 EndOfPartitionEvent (org.apache.flink.runtime.io.network.api.EndOfPartitionEvent)2 DeserializationResult (org.apache.flink.runtime.io.network.api.serialization.RecordDeserializer.DeserializationResult)2