Search in sources :

Example 6 with ConsumerVertexGroup

use of org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup in project flink by apache.

the class SchedulingPipelinedRegionComputeUtil method buildOutEdgesDesc.

private static List<List<Integer>> buildOutEdgesDesc(final Map<SchedulingExecutionVertex, Set<SchedulingExecutionVertex>> vertexToRegion, final List<Set<SchedulingExecutionVertex>> regionList, final Function<ExecutionVertexID, ? extends SchedulingExecutionVertex> executionVertexRetriever) {
    final Map<Set<SchedulingExecutionVertex>, Integer> regionIndices = new IdentityHashMap<>();
    for (int i = 0; i < regionList.size(); i++) {
        regionIndices.put(regionList.get(i), i);
    }
    final List<List<Integer>> outEdges = new ArrayList<>(regionList.size());
    for (Set<SchedulingExecutionVertex> currentRegion : regionList) {
        final List<Integer> currentRegionOutEdges = new ArrayList<>();
        for (SchedulingExecutionVertex vertex : currentRegion) {
            for (SchedulingResultPartition producedResult : vertex.getProducedResults()) {
                if (!producedResult.getResultType().isReconnectable()) {
                    continue;
                }
                final Optional<ConsumerVertexGroup> consumerVertexGroup = producedResult.getConsumerVertexGroup();
                if (!consumerVertexGroup.isPresent()) {
                    continue;
                }
                for (ExecutionVertexID consumerVertexId : consumerVertexGroup.get()) {
                    SchedulingExecutionVertex consumerVertex = executionVertexRetriever.apply(consumerVertexId);
                    // regions and cannot be merged
                    if (!vertexToRegion.containsKey(consumerVertex)) {
                        break;
                    }
                    if (!currentRegion.contains(consumerVertex)) {
                        currentRegionOutEdges.add(regionIndices.get(vertexToRegion.get(consumerVertex)));
                    }
                }
            }
        }
        outEdges.add(currentRegionOutEdges);
    }
    return outEdges;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) ConsumerVertexGroup(org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup) SchedulingExecutionVertex(org.apache.flink.runtime.scheduler.strategy.SchedulingExecutionVertex) SchedulingResultPartition(org.apache.flink.runtime.scheduler.strategy.SchedulingResultPartition) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with ConsumerVertexGroup

use of org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup in project flink by apache.

the class IntermediateResultPartition method computeNumberOfSubpartitions.

private int computeNumberOfSubpartitions() {
    if (!getProducer().getExecutionGraphAccessor().isDynamic()) {
        ConsumerVertexGroup consumerVertexGroup = getConsumerVertexGroup();
        checkState(consumerVertexGroup.size() > 0);
        // consuming sub task.
        return consumerVertexGroup.size();
    } else {
        if (totalResult.isBroadcast()) {
            // and all the downstream vertices should consume this subpartition.
            return 1;
        } else {
            return computeNumberOfMaxPossiblePartitionConsumers();
        }
    }
}
Also used : ConsumerVertexGroup(org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup)

Example 8 with ConsumerVertexGroup

use of org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup in project flink by apache.

the class DefaultExecutionTopologyTest method assertPartitionsEquals.

private static void assertPartitionsEquals(Iterable<IntermediateResultPartition> originalResultPartitions, Iterable<DefaultResultPartition> adaptedResultPartitions) {
    assertEquals(Iterables.size(originalResultPartitions), Iterables.size(adaptedResultPartitions));
    for (IntermediateResultPartition originalPartition : originalResultPartitions) {
        DefaultResultPartition adaptedPartition = IterableUtils.toStream(adaptedResultPartitions).filter(adapted -> adapted.getId().equals(originalPartition.getPartitionId())).findAny().orElseThrow(() -> new AssertionError("Could not find matching adapted partition for " + originalPartition));
        assertPartitionEquals(originalPartition, adaptedPartition);
        ConsumerVertexGroup consumerVertexGroup = originalPartition.getConsumerVertexGroup();
        Optional<ConsumerVertexGroup> adaptedConsumers = adaptedPartition.getConsumerVertexGroup();
        assertTrue(adaptedConsumers.isPresent());
        for (ExecutionVertexID originalId : consumerVertexGroup) {
            // it is sufficient to verify that some vertex exists with the correct ID here,
            // since deep equality is verified later in the main loop
            // this DOES rely on an implicit assumption that the vertices objects returned by
            // the topology are
            // identical to those stored in the partition
            assertTrue(IterableUtils.toStream(adaptedConsumers.get()).anyMatch(adaptedConsumer -> adaptedConsumer.equals(originalId)));
        }
    }
}
Also used : IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) TestingDefaultExecutionGraphBuilder(org.apache.flink.runtime.executiongraph.TestingDefaultExecutionGraphBuilder) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) ConsumerVertexGroup(org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) SchedulingPipelinedRegion(org.apache.flink.runtime.scheduler.strategy.SchedulingPipelinedRegion) PIPELINED(org.apache.flink.runtime.io.network.partition.ResultPartitionType.PIPELINED) TestCase.assertSame(junit.framework.TestCase.assertSame) ArrayList(java.util.ArrayList) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ResultPartitionState(org.apache.flink.runtime.scheduler.strategy.ResultPartitionState) BLOCKING(org.apache.flink.runtime.io.network.partition.ResultPartitionType.BLOCKING) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) Is.is(org.hamcrest.core.Is.is) Assert.fail(org.junit.Assert.fail) Iterables(org.apache.flink.shaded.guava30.com.google.common.collect.Iterables) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) ExecutionGraphTestUtils.createSimpleTestGraph(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createSimpleTestGraph) Iterator(java.util.Iterator) Sets(org.apache.flink.shaded.guava30.com.google.common.collect.Sets) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) ALL_TO_ALL(org.apache.flink.runtime.jobgraph.DistributionPattern.ALL_TO_ALL) IterableUtils(org.apache.flink.util.IterableUtils) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) List(java.util.List) JobID(org.apache.flink.api.common.JobID) ConsumedPartitionGroup(org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup) IntermediateResultPartition(org.apache.flink.runtime.executiongraph.IntermediateResultPartition) TestCase.assertTrue(junit.framework.TestCase.assertTrue) ExecutionGraphTestUtils.createNoOpVertex(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createNoOpVertex) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) DefaultExecutionGraph(org.apache.flink.runtime.executiongraph.DefaultExecutionGraph) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) IntermediateResultPartition(org.apache.flink.runtime.executiongraph.IntermediateResultPartition) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) ConsumerVertexGroup(org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup)

Example 9 with ConsumerVertexGroup

use of org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup in project flink by apache.

the class EdgeManagerBuildUtil method connectPointwise.

private static void connectPointwise(ExecutionVertex[] taskVertices, IntermediateResult intermediateResult) {
    final int sourceCount = intermediateResult.getPartitions().length;
    final int targetCount = taskVertices.length;
    if (sourceCount == targetCount) {
        for (int i = 0; i < sourceCount; i++) {
            ExecutionVertex executionVertex = taskVertices[i];
            IntermediateResultPartition partition = intermediateResult.getPartitions()[i];
            ConsumerVertexGroup consumerVertexGroup = ConsumerVertexGroup.fromSingleVertex(executionVertex.getID());
            partition.addConsumers(consumerVertexGroup);
            ConsumedPartitionGroup consumedPartitionGroup = createAndRegisterConsumedPartitionGroupToEdgeManager(partition.getPartitionId(), intermediateResult);
            executionVertex.addConsumedPartitionGroup(consumedPartitionGroup);
        }
    } else if (sourceCount > targetCount) {
        for (int index = 0; index < targetCount; index++) {
            ExecutionVertex executionVertex = taskVertices[index];
            ConsumerVertexGroup consumerVertexGroup = ConsumerVertexGroup.fromSingleVertex(executionVertex.getID());
            int start = index * sourceCount / targetCount;
            int end = (index + 1) * sourceCount / targetCount;
            List<IntermediateResultPartitionID> consumedPartitions = new ArrayList<>(end - start);
            for (int i = start; i < end; i++) {
                IntermediateResultPartition partition = intermediateResult.getPartitions()[i];
                partition.addConsumers(consumerVertexGroup);
                consumedPartitions.add(partition.getPartitionId());
            }
            ConsumedPartitionGroup consumedPartitionGroup = createAndRegisterConsumedPartitionGroupToEdgeManager(consumedPartitions, intermediateResult);
            executionVertex.addConsumedPartitionGroup(consumedPartitionGroup);
        }
    } else {
        for (int partitionNum = 0; partitionNum < sourceCount; partitionNum++) {
            IntermediateResultPartition partition = intermediateResult.getPartitions()[partitionNum];
            ConsumedPartitionGroup consumedPartitionGroup = createAndRegisterConsumedPartitionGroupToEdgeManager(partition.getPartitionId(), intermediateResult);
            int start = (partitionNum * targetCount + sourceCount - 1) / sourceCount;
            int end = ((partitionNum + 1) * targetCount + sourceCount - 1) / sourceCount;
            List<ExecutionVertexID> consumers = new ArrayList<>(end - start);
            for (int i = start; i < end; i++) {
                ExecutionVertex executionVertex = taskVertices[i];
                executionVertex.addConsumedPartitionGroup(consumedPartitionGroup);
                consumers.add(executionVertex.getID());
            }
            ConsumerVertexGroup consumerVertexGroup = ConsumerVertexGroup.fromMultipleVertices(consumers);
            partition.addConsumers(consumerVertexGroup);
        }
    }
}
Also used : ConsumedPartitionGroup(org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup) List(java.util.List) ArrayList(java.util.ArrayList) ConsumerVertexGroup(org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup)

Aggregations

ConsumerVertexGroup (org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup)9 ExecutionVertexID (org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID)5 ArrayList (java.util.ArrayList)4 ConsumedPartitionGroup (org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup)4 List (java.util.List)3 IntermediateResultPartitionID (org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)3 SchedulingResultPartition (org.apache.flink.runtime.scheduler.strategy.SchedulingResultPartition)3 Set (java.util.Set)2 SchedulingExecutionVertex (org.apache.flink.runtime.scheduler.strategy.SchedulingExecutionVertex)2 SchedulingPipelinedRegion (org.apache.flink.runtime.scheduler.strategy.SchedulingPipelinedRegion)2 ArrayDeque (java.util.ArrayDeque)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Optional (java.util.Optional)1 TestCase.assertSame (junit.framework.TestCase.assertSame)1 TestCase.assertTrue (junit.framework.TestCase.assertTrue)1