Search in sources :

Example 1 with CheckpointBarrier

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

the class PipelinedSubpartition method processPriorityBuffer.

private boolean processPriorityBuffer(BufferConsumer bufferConsumer, int partialRecordLength) {
    buffers.addPriorityElement(new BufferConsumerWithPartialRecordLength(bufferConsumer, partialRecordLength));
    final int numPriorityElements = buffers.getNumPriorityElements();
    CheckpointBarrier barrier = parseCheckpointBarrier(bufferConsumer);
    if (barrier != null) {
        checkState(barrier.getCheckpointOptions().isUnalignedCheckpoint(), "Only unaligned checkpoints should be priority events");
        final Iterator<BufferConsumerWithPartialRecordLength> iterator = buffers.iterator();
        Iterators.advance(iterator, numPriorityElements);
        List<Buffer> inflightBuffers = new ArrayList<>();
        while (iterator.hasNext()) {
            BufferConsumer buffer = iterator.next().getBufferConsumer();
            if (buffer.isBuffer()) {
                try (BufferConsumer bc = buffer.copy()) {
                    inflightBuffers.add(bc.build());
                }
            }
        }
        if (!inflightBuffers.isEmpty()) {
            channelStateWriter.addOutputData(barrier.getId(), subpartitionInfo, ChannelStateWriter.SEQUENCE_NUMBER_UNKNOWN, inflightBuffers.toArray(new Buffer[0]));
        }
    }
    return numPriorityElements == 1 && // if subpartition is blocked then downstream doesn't expect any
    !isBlocked;
// notifications
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) ArrayList(java.util.ArrayList) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) BufferConsumerWithPartialRecordLength(org.apache.flink.runtime.io.network.buffer.BufferConsumerWithPartialRecordLength)

Example 2 with CheckpointBarrier

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

the class PipelinedSubpartition method parseCheckpointBarrier.

@Nullable
private CheckpointBarrier parseCheckpointBarrier(BufferConsumer bufferConsumer) {
    CheckpointBarrier barrier;
    try (BufferConsumer bc = bufferConsumer.copy()) {
        Buffer buffer = bc.build();
        try {
            final AbstractEvent event = EventSerializer.fromBuffer(buffer, getClass().getClassLoader());
            barrier = event instanceof CheckpointBarrier ? (CheckpointBarrier) event : null;
        } catch (IOException e) {
            throw new IllegalStateException("Should always be able to deserialize in-memory event", e);
        } finally {
            buffer.recycleBuffer();
        }
    }
    return barrier;
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 3 with CheckpointBarrier

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

the class EventSerializer method deserializeCheckpointBarrier.

private static CheckpointBarrier deserializeCheckpointBarrier(ByteBuffer buffer) throws IOException {
    final long id = buffer.getLong();
    final long timestamp = buffer.getLong();
    final byte checkpointTypeCode = buffer.get();
    final SnapshotType snapshotType;
    if (checkpointTypeCode == CHECKPOINT_TYPE_CHECKPOINT) {
        snapshotType = CheckpointType.CHECKPOINT;
    } else if (checkpointTypeCode == CHECKPOINT_TYPE_FULL_CHECKPOINT) {
        snapshotType = CheckpointType.FULL_CHECKPOINT;
    } else if (checkpointTypeCode == CHECKPOINT_TYPE_SAVEPOINT || checkpointTypeCode == CHECKPOINT_TYPE_SAVEPOINT_SUSPEND || checkpointTypeCode == CHECKPOINT_TYPE_SAVEPOINT_TERMINATE) {
        snapshotType = decodeSavepointType(checkpointTypeCode, buffer);
    } else {
        throw new IOException("Unknown checkpoint type code: " + checkpointTypeCode);
    }
    final CheckpointStorageLocationReference locationRef;
    final int locationRefLen = buffer.getInt();
    if (locationRefLen == -1) {
        locationRef = CheckpointStorageLocationReference.getDefault();
    } else {
        byte[] bytes = new byte[locationRefLen];
        buffer.get(bytes);
        locationRef = new CheckpointStorageLocationReference(bytes);
    }
    final CheckpointOptions.AlignmentType alignmentType = CheckpointOptions.AlignmentType.values()[buffer.get()];
    final long alignmentTimeout = buffer.getLong();
    return new CheckpointBarrier(id, timestamp, new CheckpointOptions(snapshotType, locationRef, alignmentType, alignmentTimeout));
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) SnapshotType(org.apache.flink.runtime.checkpoint.SnapshotType) IOException(java.io.IOException) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference)

Example 4 with CheckpointBarrier

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

the class AlternatingCollectingBarriers method alignmentTimeout.

@Override
public BarrierHandlerState alignmentTimeout(Controller controller, CheckpointBarrier checkpointBarrier) throws IOException, CheckpointException {
    state.prioritizeAllAnnouncements();
    CheckpointBarrier unalignedBarrier = checkpointBarrier.asUnaligned();
    controller.initInputsCheckpoint(unalignedBarrier);
    for (CheckpointableInput input : state.getInputs()) {
        input.checkpointStarted(unalignedBarrier);
    }
    controller.triggerGlobalCheckpoint(unalignedBarrier);
    return new AlternatingCollectingBarriersUnaligned(true, state);
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) CheckpointableInput(org.apache.flink.runtime.io.network.partition.consumer.CheckpointableInput)

Example 5 with CheckpointBarrier

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

the class CheckpointedInputGate method handleEvent.

private Optional<BufferOrEvent> handleEvent(BufferOrEvent bufferOrEvent) throws IOException {
    Class<? extends AbstractEvent> eventClass = bufferOrEvent.getEvent().getClass();
    if (eventClass == CheckpointBarrier.class) {
        CheckpointBarrier checkpointBarrier = (CheckpointBarrier) bufferOrEvent.getEvent();
        barrierHandler.processBarrier(checkpointBarrier, bufferOrEvent.getChannelInfo(), false);
    } else if (eventClass == CancelCheckpointMarker.class) {
        barrierHandler.processCancellationBarrier((CancelCheckpointMarker) bufferOrEvent.getEvent(), bufferOrEvent.getChannelInfo());
    } else if (eventClass == EndOfData.class) {
        inputGate.acknowledgeAllRecordsProcessed(bufferOrEvent.getChannelInfo());
    } else if (eventClass == EndOfPartitionEvent.class) {
        barrierHandler.processEndOfPartition(bufferOrEvent.getChannelInfo());
    } else if (eventClass == EventAnnouncement.class) {
        EventAnnouncement eventAnnouncement = (EventAnnouncement) bufferOrEvent.getEvent();
        AbstractEvent announcedEvent = eventAnnouncement.getAnnouncedEvent();
        checkState(announcedEvent instanceof CheckpointBarrier, "Only CheckpointBarrier announcement are currently supported, but found [%s]", announcedEvent);
        CheckpointBarrier announcedBarrier = (CheckpointBarrier) announcedEvent;
        barrierHandler.processBarrierAnnouncement(announcedBarrier, eventAnnouncement.getSequenceNumber(), bufferOrEvent.getChannelInfo());
    } else if (bufferOrEvent.getEvent().getClass() == EndOfChannelStateEvent.class) {
        upstreamRecoveryTracker.handleEndOfRecovery(bufferOrEvent.getChannelInfo());
    }
    return Optional.of(bufferOrEvent);
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) EndOfChannelStateEvent(org.apache.flink.runtime.io.network.partition.consumer.EndOfChannelStateEvent) EndOfPartitionEvent(org.apache.flink.runtime.io.network.api.EndOfPartitionEvent) EventAnnouncement(org.apache.flink.runtime.io.network.api.EventAnnouncement) CancelCheckpointMarker(org.apache.flink.runtime.io.network.api.CancelCheckpointMarker) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent)

Aggregations

CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)62 Test (org.junit.Test)43 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)14 ArrayDeque (java.util.ArrayDeque)8 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)8 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)8 ArrayList (java.util.ArrayList)7 CancelCheckpointMarker (org.apache.flink.runtime.io.network.api.CancelCheckpointMarker)7 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)7 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)7 IOException (java.io.IOException)6 AbstractEvent (org.apache.flink.runtime.event.AbstractEvent)6 BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)6 CheckpointStorageLocationReference (org.apache.flink.runtime.state.CheckpointStorageLocationReference)6 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)5 EventAnnouncement (org.apache.flink.runtime.io.network.api.EventAnnouncement)5 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)5 TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)5 ByteBuffer (java.nio.ByteBuffer)4 RecordingChannelStateWriter (org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter)4