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_r282443479
 
 

 ##########
 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:
   After thinking deeply, I agree with you. Following the checkpoint's sequence 
is a better choice. Accept.

----------------------------------------------------------------
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

Reply via email to