Search in sources :

Example 1 with CheckpointedResultSubpartition

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

the class ResultSubpartitionRecoveredStateHandler method recover.

@Override
public void recover(ResultSubpartitionInfo subpartitionInfo, int oldSubtaskIndex, BufferWithContext<BufferBuilder> bufferWithContext) throws IOException {
    try (BufferBuilder bufferBuilder = bufferWithContext.context) {
        try (BufferConsumer bufferConsumer = bufferBuilder.createBufferConsumerFromBeginning()) {
            bufferBuilder.finish();
            if (bufferConsumer.isDataAvailable()) {
                final List<CheckpointedResultSubpartition> channels = getMappedChannels(subpartitionInfo);
                for (final CheckpointedResultSubpartition channel : channels) {
                    // channel selector is created from the downstream's point of view: the
                    // subtask of downstream = subpartition index of recovered buffer
                    final SubtaskConnectionDescriptor channelSelector = new SubtaskConnectionDescriptor(subpartitionInfo.getSubPartitionIdx(), oldSubtaskIndex);
                    channel.addRecovered(EventSerializer.toBufferConsumer(channelSelector, false));
                    channel.addRecovered(bufferConsumer.copy());
                }
            }
        }
    }
}
Also used : BufferBuilder(org.apache.flink.runtime.io.network.buffer.BufferBuilder) SubtaskConnectionDescriptor(org.apache.flink.runtime.io.network.api.SubtaskConnectionDescriptor) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) CheckpointedResultSubpartition(org.apache.flink.runtime.io.network.partition.CheckpointedResultSubpartition)

Example 2 with CheckpointedResultSubpartition

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

the class ResultSubpartitionRecoveredStateHandler method getBuffer.

@Override
public BufferWithContext<BufferBuilder> getBuffer(ResultSubpartitionInfo subpartitionInfo) throws IOException, InterruptedException {
    // request the buffer from any mapped subpartition as they all will receive the same buffer
    final List<CheckpointedResultSubpartition> channels = getMappedChannels(subpartitionInfo);
    BufferBuilder bufferBuilder = channels.get(0).requestBufferBuilderBlocking();
    return new BufferWithContext<>(wrap(bufferBuilder), bufferBuilder);
}
Also used : BufferBuilder(org.apache.flink.runtime.io.network.buffer.BufferBuilder) CheckpointedResultSubpartition(org.apache.flink.runtime.io.network.partition.CheckpointedResultSubpartition)

Example 3 with CheckpointedResultSubpartition

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

the class ResultSubpartitionRecoveredStateHandler method calculateMapping.

private List<CheckpointedResultSubpartition> calculateMapping(ResultSubpartitionInfo info) {
    final RescaleMappings oldToNewMapping = oldToNewMappings.computeIfAbsent(info.getPartitionIdx(), idx -> channelMapping.getChannelMapping(idx).invert());
    final List<CheckpointedResultSubpartition> subpartitions = Arrays.stream(oldToNewMapping.getMappedIndexes(info.getSubPartitionIdx())).mapToObj(newIndexes -> getSubpartition(info.getPartitionIdx(), newIndexes)).collect(Collectors.toList());
    if (subpartitions.isEmpty()) {
        throw new IllegalStateException("Recovered a buffer from old " + info + " that has no mapping in " + channelMapping.getChannelMapping(info.getPartitionIdx()));
    }
    return subpartitions;
}
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) CheckpointedResultSubpartition(org.apache.flink.runtime.io.network.partition.CheckpointedResultSubpartition)

Aggregations

BufferBuilder (org.apache.flink.runtime.io.network.buffer.BufferBuilder)3 CheckpointedResultSubpartition (org.apache.flink.runtime.io.network.partition.CheckpointedResultSubpartition)3 SubtaskConnectionDescriptor (org.apache.flink.runtime.io.network.api.SubtaskConnectionDescriptor)2 BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)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 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)1 CheckpointedResultPartition (org.apache.flink.runtime.io.network.partition.CheckpointedResultPartition)1 InputChannel (org.apache.flink.runtime.io.network.partition.consumer.InputChannel)1 InputGate (org.apache.flink.runtime.io.network.partition.consumer.InputGate)1 RecoveredInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RecoveredInputChannel)1