yanghua commented on a change in pull request #8322: [FLINK-12364] Introduce a CheckpointFailureManager to centralized manage checkpoint failure URL: https://github.com/apache/flink/pull/8322#discussion_r282047625
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/CheckpointFailureManager.java ########## @@ -0,0 +1,95 @@ +/* + * 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.util.Preconditions; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * The checkpoint failure manager which centralized manage checkpoint failure processing logic. + */ +public class CheckpointFailureManager { + + private final AtomicInteger continuousFailureCounter; + private final int tolerableCpFailureNumber; + + public CheckpointFailureManager(int tolerableCpFailureNumber) { + Preconditions.checkArgument(tolerableCpFailureNumber > 0, + "The tolerable checkpoint failure number must be larger than 0."); + this.tolerableCpFailureNumber = tolerableCpFailureNumber; + this.continuousFailureCounter = new AtomicInteger(0); + } + + /** + * Handle checkpoint exception with a handler callback. + * + * @param exception the checkpoint exception. + * @param callback the handler callback which defines the process logic. + */ + public void handleCheckpointException(CheckpointException exception, FailureHandlerCallback callback) { + CheckpointFailureReason reason = exception.getCheckpointFailureReason(); + switch (reason) { + case PERIODIC_SCHEDULER_SHUTDOWN: + case ALREADY_QUEUED: + case TOO_MANY_CONCURRENT_CHECKPOINTS: + case MINIMUM_TIME_BETWEEN_CHECKPOINTS: + case NOT_ALL_REQUIRED_TASKS_RUNNING: + case CHECKPOINT_SUBSUMED: + case CHECKPOINT_COORDINATOR_SUSPEND: + case CHECKPOINT_COORDINATOR_SHUTDOWN: + case JOB_FAILURE: + case JOB_FAILOVER_REGION: + //ignore + break; + + case EXCEPTION: + case CHECKPOINT_EXPIRED: + case CHECKPOINT_DECLINED: + case TASK_CHECKPOINT_FAILURE: + case TRIGGER_CHECKPOINT_FAILURE: + case FINALIZE_CHECKPOINT_FAILURE: + continuousFailureCounter.incrementAndGet(); + break; + + default: + throw new RuntimeException("Unknown checkpoint failure reason : " + reason.name()); + } + + if (continuousFailureCounter.get() > tolerableCpFailureNumber) { + callback.process(); + } + } + + /** + * Handle checkpoint success. + */ + public void handleCheckpointSuccess() { + continuousFailureCounter.set(0); Review comment: Good question. Actually, I think our focus is different. Just like I referenced the variable name `continuousFailureCounter`. I'm more concerned about “continuous” in the parallel scene. I think you are more concerned about "failure counter" based on checkpoint sequence(trigger order). To tolerate successive checkpoint failures, there are usually two purposes: * Users don't want successful checkpoints to be too far away from the current time (if they can't succeed from now on); * In many cases, continuous failures are caused by third-party system exceptions when interacting with third-party systems. If it is short-term exceptions, then we are not inclined to restart job. If it is long-term exceptions, then we are willing to restart Job. The first one is more likely to agree with you, while the second one is more likely to be related to the behavior at the time of execution. In your example, if the old checkpoint succeeds (possibly indicating that the third-party system is back to normal), it is also acceptable to reset the counter to reduce the risk of restart. My point is that the cost and risk of Job restart is very high, and judging by runtime continuity will make us less radical. What do you think about my opinion? But I admit that it's easier for users to understand that from your point of view. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services