Search in sources :

Example 21 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class ChannelStatePersisterTest method testLateBarrierTriggeringCheckpoint.

@Test(expected = CheckpointException.class)
public void testLateBarrierTriggeringCheckpoint() throws Exception {
    ChannelStatePersister persister = new ChannelStatePersister(ChannelStateWriter.NO_OP, new InputChannelInfo(0, 0));
    long lateCheckpointId = 1L;
    long checkpointId = 2L;
    persister.checkForBarrier(barrier(checkpointId));
    persister.startPersisting(lateCheckpointId, Collections.emptyList());
}
Also used : InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) Test(org.junit.Test)

Example 22 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class ChannelStatePersisterTest method testNewBarrierNotOverwrittenByStopPersisting.

@Test
public void testNewBarrierNotOverwrittenByStopPersisting() throws Exception {
    RecordingChannelStateWriter channelStateWriter = new RecordingChannelStateWriter();
    InputChannelInfo channelInfo = new InputChannelInfo(0, 0);
    ChannelStatePersister persister = new ChannelStatePersister(channelStateWriter, channelInfo);
    long checkpointId = 1L;
    channelStateWriter.start(checkpointId, CheckpointOptions.unaligned(CheckpointType.CHECKPOINT, getDefault()));
    persister.checkForBarrier(barrier(checkpointId));
    persister.startPersisting(checkpointId, Arrays.asList(buildSomeBuffer()));
    assertEquals(1, channelStateWriter.getAddedInput().get(channelInfo).size());
    persister.maybePersist(buildSomeBuffer());
    assertEquals(1, channelStateWriter.getAddedInput().get(channelInfo).size());
    // meanwhile, checkpoint coordinator timed out the 1st checkpoint and started the 2nd
    // now task thread is picking up the barrier and aborts the 1st:
    persister.checkForBarrier(barrier(checkpointId + 1));
    persister.maybePersist(buildSomeBuffer());
    persister.stopPersisting(checkpointId);
    persister.maybePersist(buildSomeBuffer());
    assertEquals(1, channelStateWriter.getAddedInput().get(channelInfo).size());
    assertTrue(persister.hasBarrierReceived());
}
Also used : InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) RecordingChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter) Test(org.junit.Test)

Example 23 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class ChannelState method prioritizeAllAnnouncements.

public void prioritizeAllAnnouncements() throws IOException {
    for (Map.Entry<InputChannelInfo, Integer> announcedNumberInChannel : sequenceNumberInAnnouncedChannels.entrySet()) {
        InputChannelInfo channelInfo = announcedNumberInChannel.getKey();
        inputs[channelInfo.getGateIdx()].convertToPriorityEvent(channelInfo.getInputChannelIdx(), announcedNumberInChannel.getValue());
    }
    sequenceNumberInAnnouncedChannels.clear();
}
Also used : InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class ChannelPersistenceITCase method testReadWritten.

@Test
public void testReadWritten() throws Exception {
    byte[] inputChannelInfoData = randomBytes(1024);
    byte[] resultSubpartitionInfoData = randomBytes(1024);
    int partitionIndex = 0;
    SequentialChannelStateReader reader = new SequentialChannelStateReaderImpl(toTaskStateSnapshot(write(1L, singletonMap(new InputChannelInfo(0, 0), inputChannelInfoData), singletonMap(new ResultSubpartitionInfo(partitionIndex, 0), resultSubpartitionInfoData))));
    NetworkBufferPool networkBufferPool = new NetworkBufferPool(4, 1024);
    try {
        int numChannels = 1;
        InputGate gate = buildGate(networkBufferPool, numChannels);
        reader.readInputData(new InputGate[] { gate });
        assertArrayEquals(inputChannelInfoData, collectBytes(gate::pollNext, BufferOrEvent::getBuffer));
        BufferWritingResultPartition resultPartition = buildResultPartition(networkBufferPool, ResultPartitionType.PIPELINED, partitionIndex, numChannels);
        reader.readOutputData(new BufferWritingResultPartition[] { resultPartition }, false);
        ResultSubpartitionView view = resultPartition.createSubpartitionView(0, new NoOpBufferAvailablityListener());
        assertArrayEquals(resultSubpartitionInfoData, collectBytes(() -> Optional.ofNullable(view.getNextBuffer()), BufferAndBacklog::buffer));
    } finally {
        networkBufferPool.destroy();
    }
}
Also used : InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) SequentialChannelStateReaderImpl(org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReaderImpl) ResultSubpartitionInfo(org.apache.flink.runtime.checkpoint.channel.ResultSubpartitionInfo) SequentialChannelStateReader(org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReader) NoOpBufferAvailablityListener(org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) Test(org.junit.Test)

Example 25 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class ChannelPersistenceITCase method write.

private ChannelStateWriteResult write(long checkpointId, Map<InputChannelInfo, byte[]> icMap, Map<ResultSubpartitionInfo, byte[]> rsMap) throws Exception {
    int maxStateSize = sizeOfBytes(icMap) + sizeOfBytes(rsMap) + Long.BYTES * 2;
    Map<InputChannelInfo, Buffer> icBuffers = wrapWithBuffers(icMap);
    Map<ResultSubpartitionInfo, Buffer> rsBuffers = wrapWithBuffers(rsMap);
    try (ChannelStateWriterImpl writer = new ChannelStateWriterImpl("test", 0, getStreamFactoryFactory(maxStateSize))) {
        writer.open();
        writer.start(checkpointId, new CheckpointOptions(CHECKPOINT, new CheckpointStorageLocationReference("poly".getBytes())));
        for (Map.Entry<InputChannelInfo, Buffer> e : icBuffers.entrySet()) {
            writer.addInputData(checkpointId, e.getKey(), SEQUENCE_NUMBER_UNKNOWN, ofElements(Buffer::recycleBuffer, e.getValue()));
        }
        writer.finishInput(checkpointId);
        for (Map.Entry<ResultSubpartitionInfo, Buffer> e : rsBuffers.entrySet()) {
            writer.addOutputData(checkpointId, e.getKey(), SEQUENCE_NUMBER_UNKNOWN, e.getValue());
        }
        writer.finishOutput(checkpointId);
        ChannelStateWriteResult result = writer.getAndRemoveWriteResult(checkpointId);
        // prevent abnormal complete in close
        result.getResultSubpartitionStateHandles().join();
        return result;
    }
}
Also used : NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) ByteBuffer(java.nio.ByteBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) ChannelStateWriterImpl(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriterImpl) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) ResultSubpartitionInfo(org.apache.flink.runtime.checkpoint.channel.ResultSubpartitionInfo) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Aggregations

InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)30 Test (org.junit.Test)21 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)9 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)8 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)8 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)5 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)5 BufferBuilder (org.apache.flink.runtime.io.network.buffer.BufferBuilder)4 MemorySegment (org.apache.flink.core.memory.MemorySegment)3 ResultSubpartitionInfo (org.apache.flink.runtime.checkpoint.channel.ResultSubpartitionInfo)3 CancelCheckpointMarker (org.apache.flink.runtime.io.network.api.CancelCheckpointMarker)3 SubtaskConnectionDescriptor (org.apache.flink.runtime.io.network.api.SubtaskConnectionDescriptor)3 BufferBuilderTestUtils.createBufferBuilder (org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createBufferBuilder)3 BufferOrEvent (org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)3 TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LongSerializer (org.apache.flink.api.common.typeutils.base.LongSerializer)2 RecordingChannelStateWriter (org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter)2 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)2