dawidwys commented on a change in pull request #16655: URL: https://github.com/apache/flink/pull/16655#discussion_r683180632
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/VertexFinishedStateChecker.java ########## @@ -0,0 +1,216 @@ +/* + * 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.checkpoint; + +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.runtime.OperatorIDPair; +import org.apache.flink.runtime.executiongraph.ExecutionJobVertex; +import org.apache.flink.runtime.executiongraph.IntermediateResult; +import org.apache.flink.runtime.jobgraph.DistributionPattern; +import org.apache.flink.runtime.jobgraph.JobEdge; +import org.apache.flink.runtime.jobgraph.JobVertexID; +import org.apache.flink.runtime.jobgraph.OperatorID; +import org.apache.flink.util.FlinkRuntimeException; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * This class encapsulates the operation that checks if there are illegal modification to the + * JobGraph when restoring from a checkpoint with partly or fully finished operator states. + * + * <p>As a whole, it ensures + * + * <ol> + * <li>All the operators inside a JobVertex have the same finished state. + * <li>The predecessors of a fully finished vertex must also be fully finished. + * <li>The processors of a partly finished vertex + * <ul> + * <li>If connected via ALL_TO_ALL edge, the predecessor must be fully finished. + * <li>If connected via POINTWISE edge, the predecessor must be partly finished or fully + * finished. + * </ul> + * </ol> + */ +public class VertexFinishedStateChecker { + + private final Set<ExecutionJobVertex> vertices; + + private final Map<OperatorID, OperatorState> operatorStates; + + public VertexFinishedStateChecker( + Set<ExecutionJobVertex> vertices, Map<OperatorID, OperatorState> operatorStates) { + this.vertices = vertices; + this.operatorStates = operatorStates; + } + + public void validateOperatorsFinishedState() { + VerticesFinishedStatusCache verticesFinishedCache = + new VerticesFinishedStatusCache(operatorStates); + for (ExecutionJobVertex vertex : vertices) { + VertexFinishedState vertexFinishedState = verticesFinishedCache.getOrUpdate(vertex); + + if (vertexFinishedState == VertexFinishedState.FULLY_FINISHED) { + checkProcessorsOfFullyFinishedVertex(vertex, verticesFinishedCache); Review comment: Could you check the naming? What does the `processors` mean? Did you mean `predecessors`? -- 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]
