You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/01/23 14:39:41 UTC

[GitHub] [flink] zhuzhurk commented on a change in pull request #18126: [FLINK-25036][runtime] Introduce vertex wise scheduling strategy

zhuzhurk commented on a change in pull request #18126:
URL: https://github.com/apache/flink/pull/18126#discussion_r790285074



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/strategy/VertexwiseSchedulingStrategy.java
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.strategy;
+
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID;
+import org.apache.flink.runtime.scheduler.DeploymentOption;
+import org.apache.flink.runtime.scheduler.ExecutionVertexDeploymentOption;
+import org.apache.flink.runtime.scheduler.SchedulerOperations;
+import org.apache.flink.runtime.scheduler.SchedulingTopologyListener;
+import org.apache.flink.util.IterableUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * {@link SchedulingStrategy} instance which schedules tasks in granularity of vertex (which
+ * indicates this strategy only supports ALL_EDGES_BLOCKING batch jobs). Note that this strategy
+ * implements {@link SchedulingTopologyListener}, so it can handle the updates of scheduling
+ * topology.
+ */
+public class VertexwiseSchedulingStrategy
+        implements SchedulingStrategy, SchedulingTopologyListener {
+
+    private final SchedulerOperations schedulerOperations;
+
+    private final SchedulingTopology schedulingTopology;
+
+    private final DeploymentOption deploymentOption = new DeploymentOption(false);
+
+    private final Set<ExecutionVertexID> newVertices = new HashSet<>();
+
+    public VertexwiseSchedulingStrategy(
+            final SchedulerOperations schedulerOperations,
+            final SchedulingTopology schedulingTopology) {
+
+        this.schedulerOperations = checkNotNull(schedulerOperations);
+        this.schedulingTopology = checkNotNull(schedulingTopology);
+        schedulingTopology.registerSchedulingTopologyListener(this);
+    }
+
+    @Override
+    public void startScheduling() {
+        Set<ExecutionVertexID> sourceVertices =
+                IterableUtils.toStream(schedulingTopology.getVertices())
+                        .filter(vertex -> vertex.getConsumedPartitionGroups().isEmpty())
+                        .map(SchedulingExecutionVertex::getId)
+                        .collect(Collectors.toSet());
+
+        maybeScheduleVertices(sourceVertices);
+    }
+
+    @Override
+    public void restartTasks(Set<ExecutionVertexID> verticesToRestart) {
+        maybeScheduleVertices(verticesToRestart);
+    }
+
+    @Override
+    public void onExecutionStateChange(
+            ExecutionVertexID executionVertexId, ExecutionState executionState) {
+        if (executionState == ExecutionState.FINISHED) {
+            SchedulingExecutionVertex executionVertex =
+                    schedulingTopology.getVertex(executionVertexId);
+
+            Set<ExecutionVertexID> consumerVertices =
+                    IterableUtils.toStream(executionVertex.getProducedResults())
+                            .map(SchedulingResultPartition::getConsumerVertexGroup)
+                            .filter(Optional::isPresent)
+                            .flatMap(
+                                    consumerVertexGroup ->
+                                            IterableUtils.toStream(consumerVertexGroup.get()))
+                            .collect(Collectors.toSet());
+
+            maybeScheduleVertices(consumerVertices);
+        }
+    }
+
+    @Override
+    public void onPartitionConsumable(IntermediateResultPartitionID resultPartitionId) {}
+
+    @Override
+    public void notifySchedulingTopologyUpdated(
+            SchedulingTopology schedulingTopology, List<ExecutionVertexID> newExecutionVertices) {
+        checkState(schedulingTopology == this.schedulingTopology);
+        newVertices.addAll(newExecutionVertices);
+    }
+
+    private void maybeScheduleVertices(final Set<ExecutionVertexID> vertices) {
+
+        final Map<ConsumedPartitionGroup, Boolean> consumableStatusCache = new HashMap<>();
+
+        Set<ExecutionVertexID> allCandidates;
+        if (newVertices.isEmpty()) {
+            allCandidates = vertices;
+        } else {
+            allCandidates = new HashSet<>(vertices);
+            allCandidates.addAll(newVertices);
+            newVertices.clear();
+        }
+
+        final Set<ExecutionVertexID> verticesToDeploy =
+                allCandidates.stream()
+                        .filter(
+                                vertexId -> {
+                                    SchedulingExecutionVertex vertex =
+                                            schedulingTopology.getVertex(vertexId);
+                                    checkState(vertex.getState() == ExecutionState.CREATED);
+                                    return areVertexInputsAllConsumable(
+                                            vertex, consumableStatusCache);
+                                })
+                        .collect(Collectors.toSet());
+
+        if (!verticesToDeploy.isEmpty()) {

Review comment:
       maybe put the if check into `scheduleVerticesOneByOne`?

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/strategy/VertexwiseSchedulingStrategy.java
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.strategy;
+
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID;
+import org.apache.flink.runtime.scheduler.DeploymentOption;
+import org.apache.flink.runtime.scheduler.ExecutionVertexDeploymentOption;
+import org.apache.flink.runtime.scheduler.SchedulerOperations;
+import org.apache.flink.runtime.scheduler.SchedulingTopologyListener;
+import org.apache.flink.util.IterableUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * {@link SchedulingStrategy} instance which schedules tasks in granularity of vertex (which
+ * indicates this strategy only supports ALL_EDGES_BLOCKING batch jobs). Note that this strategy
+ * implements {@link SchedulingTopologyListener}, so it can handle the updates of scheduling
+ * topology.
+ */
+public class VertexwiseSchedulingStrategy
+        implements SchedulingStrategy, SchedulingTopologyListener {
+
+    private final SchedulerOperations schedulerOperations;
+
+    private final SchedulingTopology schedulingTopology;
+
+    private final DeploymentOption deploymentOption = new DeploymentOption(false);
+
+    private final Set<ExecutionVertexID> newVertices = new HashSet<>();
+
+    public VertexwiseSchedulingStrategy(
+            final SchedulerOperations schedulerOperations,
+            final SchedulingTopology schedulingTopology) {
+
+        this.schedulerOperations = checkNotNull(schedulerOperations);
+        this.schedulingTopology = checkNotNull(schedulingTopology);
+        schedulingTopology.registerSchedulingTopologyListener(this);
+    }
+
+    @Override
+    public void startScheduling() {
+        Set<ExecutionVertexID> sourceVertices =
+                IterableUtils.toStream(schedulingTopology.getVertices())
+                        .filter(vertex -> vertex.getConsumedPartitionGroups().isEmpty())
+                        .map(SchedulingExecutionVertex::getId)
+                        .collect(Collectors.toSet());
+
+        maybeScheduleVertices(sourceVertices);
+    }
+
+    @Override
+    public void restartTasks(Set<ExecutionVertexID> verticesToRestart) {
+        maybeScheduleVertices(verticesToRestart);
+    }
+
+    @Override
+    public void onExecutionStateChange(
+            ExecutionVertexID executionVertexId, ExecutionState executionState) {
+        if (executionState == ExecutionState.FINISHED) {
+            SchedulingExecutionVertex executionVertex =
+                    schedulingTopology.getVertex(executionVertexId);
+
+            Set<ExecutionVertexID> consumerVertices =
+                    IterableUtils.toStream(executionVertex.getProducedResults())
+                            .map(SchedulingResultPartition::getConsumerVertexGroup)
+                            .filter(Optional::isPresent)
+                            .flatMap(
+                                    consumerVertexGroup ->
+                                            IterableUtils.toStream(consumerVertexGroup.get()))
+                            .collect(Collectors.toSet());
+
+            maybeScheduleVertices(consumerVertices);
+        }
+    }
+
+    @Override
+    public void onPartitionConsumable(IntermediateResultPartitionID resultPartitionId) {}
+
+    @Override
+    public void notifySchedulingTopologyUpdated(
+            SchedulingTopology schedulingTopology, List<ExecutionVertexID> newExecutionVertices) {
+        checkState(schedulingTopology == this.schedulingTopology);
+        newVertices.addAll(newExecutionVertices);
+    }
+
+    private void maybeScheduleVertices(final Set<ExecutionVertexID> vertices) {
+

Review comment:
       I would remove this empty line.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org