Search in sources :

Example 1 with RecoveredInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RecoveredInputChannel in project flink by apache.

the class ResultSubpartitionRecoveredStateHandler method calculateMapping.

private List<RecoveredInputChannel> calculateMapping(InputChannelInfo info) {
    final RescaleMappings oldToNewMapping = oldToNewMappings.computeIfAbsent(info.getGateIdx(), idx -> channelMapping.getChannelMapping(idx).invert());
    final List<RecoveredInputChannel> channels = Arrays.stream(oldToNewMapping.getMappedIndexes(info.getInputChannelIdx())).mapToObj(newChannelIndex -> getChannel(info.getGateIdx(), newChannelIndex)).collect(Collectors.toList());
    if (channels.isEmpty()) {
        throw new IllegalStateException("Recovered a buffer from old " + info + " that has no mapping in " + channelMapping.getChannelMapping(info.getGateIdx()));
    }
    return channels;
}
Also used : RescaleMappings(org.apache.flink.runtime.checkpoint.RescaleMappings) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) Arrays(java.util.Arrays) EventSerializer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer) CheckpointedResultPartition(org.apache.flink.runtime.io.network.partition.CheckpointedResultPartition) SubtaskConnectionDescriptor(org.apache.flink.runtime.io.network.api.SubtaskConnectionDescriptor) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) CheckpointedResultSubpartition(org.apache.flink.runtime.io.network.partition.CheckpointedResultSubpartition) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) RecoveredInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RecoveredInputChannel) ChannelStateByteBuffer.wrap(org.apache.flink.runtime.checkpoint.channel.ChannelStateByteBuffer.wrap) InflightDataRescalingDescriptor(org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptor) RescaleMappings(org.apache.flink.runtime.checkpoint.RescaleMappings) List(java.util.List) BufferBuilder(org.apache.flink.runtime.io.network.buffer.BufferBuilder) InputChannel(org.apache.flink.runtime.io.network.partition.consumer.InputChannel) Map(java.util.Map) RecoveredInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RecoveredInputChannel)

Example 2 with RecoveredInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RecoveredInputChannel in project flink by apache.

the class ResultSubpartitionRecoveredStateHandler method getBuffer.

@Override
public BufferWithContext<Buffer> getBuffer(InputChannelInfo channelInfo) throws IOException, InterruptedException {
    // request the buffer from any mapped channel as they all will receive the same buffer
    RecoveredInputChannel channel = getMappedChannels(channelInfo).get(0);
    Buffer buffer = channel.requestBufferBlocking();
    return new BufferWithContext<>(wrap(buffer), buffer);
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) RecoveredInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RecoveredInputChannel)

Example 3 with RecoveredInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RecoveredInputChannel in project flink by apache.

the class ResultSubpartitionRecoveredStateHandler method recover.

@Override
public void recover(InputChannelInfo channelInfo, int oldSubtaskIndex, BufferWithContext<Buffer> bufferWithContext) throws IOException {
    Buffer buffer = bufferWithContext.context;
    try {
        if (buffer.readableBytes() > 0) {
            for (final RecoveredInputChannel channel : getMappedChannels(channelInfo)) {
                channel.onRecoveredStateBuffer(EventSerializer.toBuffer(new SubtaskConnectionDescriptor(oldSubtaskIndex, channelInfo.getInputChannelIdx()), false));
                channel.onRecoveredStateBuffer(buffer.retainBuffer());
            }
        }
    } finally {
        buffer.recycleBuffer();
    }
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) RecoveredInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RecoveredInputChannel) SubtaskConnectionDescriptor(org.apache.flink.runtime.io.network.api.SubtaskConnectionDescriptor)

Aggregations

Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)3 RecoveredInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RecoveredInputChannel)3 SubtaskConnectionDescriptor (org.apache.flink.runtime.io.network.api.SubtaskConnectionDescriptor)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 InflightDataRescalingDescriptor (org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptor)1 RescaleMappings (org.apache.flink.runtime.checkpoint.RescaleMappings)1 ChannelStateByteBuffer.wrap (org.apache.flink.runtime.checkpoint.channel.ChannelStateByteBuffer.wrap)1 EventSerializer (org.apache.flink.runtime.io.network.api.serialization.EventSerializer)1 ResultPartitionWriter (org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter)1 BufferBuilder (org.apache.flink.runtime.io.network.buffer.BufferBuilder)1 BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)1 CheckpointedResultPartition (org.apache.flink.runtime.io.network.partition.CheckpointedResultPartition)1 CheckpointedResultSubpartition (org.apache.flink.runtime.io.network.partition.CheckpointedResultSubpartition)1 InputChannel (org.apache.flink.runtime.io.network.partition.consumer.InputChannel)1 InputGate (org.apache.flink.runtime.io.network.partition.consumer.InputGate)1