zhuzhurk commented on a change in pull request #18126: URL: https://github.com/apache/flink/pull/18126#discussion_r781817552
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/strategy/StagewiseSchedulingStrategy.java ########## @@ -0,0 +1,156 @@ +/* + * 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.HashSet; +import java.util.List; +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 stage. Note that this Review comment: I think the granularity is actually vertex instead of stage, because vertices are scheduled on by one. But there is constraint that vertex can be scheduled only if all the inputs of vertices in the same stage are consumable. ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/strategy/StagewiseSchedulingStrategy.java ########## @@ -0,0 +1,156 @@ +/* + * 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.HashSet; +import java.util.List; +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 stage. Note that this + * strategy only supports ALL_EDGES_BLOCKING batch jobs. + */ +public class StagewiseSchedulingStrategy implements SchedulingStrategy, SchedulingTopologyListener { + + private final SchedulerOperations schedulerOperations; + + private final SchedulingTopology schedulingTopology; + + private final DeploymentOption deploymentOption = new DeploymentOption(false); + + private final Set<SchedulingExecutionVertex> pendingVertices = new HashSet<>(); + + public StagewiseSchedulingStrategy( + final SchedulerOperations schedulerOperations, + final SchedulingTopology schedulingTopology) { + + this.schedulerOperations = checkNotNull(schedulerOperations); + this.schedulingTopology = checkNotNull(schedulingTopology); + schedulingTopology.registerSchedulingTopologyListener(this); + } + + @Override + public void startScheduling() { + Set<SchedulingExecutionVertex> sourceVertices = + IterableUtils.toStream(schedulingTopology.getVertices()) + .filter(vertex -> vertex.getConsumedPartitionGroups().isEmpty()) + .collect(Collectors.toSet()); + + maybeScheduleVerticesOneByOne(sourceVertices); + } + + @Override + public void restartTasks(Set<ExecutionVertexID> verticesToRestart) { + maybeScheduleVerticesOneByOne( + SchedulingStrategyUtils.getVerticesFromIds(schedulingTopology, verticesToRestart)); + } + + @Override + public void onExecutionStateChange( + ExecutionVertexID executionVertexId, ExecutionState executionState) { + if (executionState == ExecutionState.FINISHED) { + SchedulingExecutionVertex executionVertex = Review comment: The complexity is O(N^2) per invocation. Maybe we can reduce the complexity by checking in ahead that the corresponding ConsumedPartitionGroup has fully finished. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
