GJL commented on a change in pull request #9268: [FLINK-13452] Ensure to fail 
global when exception happens during reseting tasks of regions
URL: https://github.com/apache/flink/pull/9268#discussion_r310546715
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/restart/FailureMultiTimesRestartStrategy.java
 ##########
 @@ -0,0 +1,92 @@
+/*
+ * 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.executiongraph.restart;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.concurrent.FutureUtils;
+import org.apache.flink.runtime.concurrent.ScheduledExecutor;
+import org.apache.flink.util.FlinkRuntimeException;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Supplier;
+
+/**
+ * A restart strategy which would failed for multi times.
+ */
+public class FailureMultiTimesRestartStrategy implements RestartStrategy {
+
+       public static final String FAILURE_MULTI_TIMES = 
"restart-strategy.failure-multi-times.failures";
+
+       private final int failureMultiTimes;
+       private final AtomicInteger restartedTimes;
+
+       public FailureMultiTimesRestartStrategy(int failureMultiTimes) {
+               this.failureMultiTimes = failureMultiTimes;
+               this.restartedTimes = new AtomicInteger(0);
+       }
+
+       @Override
+       public boolean canRestart() {
+               return true;
+       }
+
+       @Override
+       public CompletableFuture<Void> restart(RestartCallback restarter, 
ScheduledExecutor executor) {
+               if (restartedTimes.incrementAndGet() <= failureMultiTimes) {
+                       CompletableFuture<Void> exceptionFuture = new 
CompletableFuture<>();
+                       exceptionFuture.completeExceptionally(new 
FlinkRuntimeException("Fail to restart for " + restartedTimes.get() + " 
time(s)."));
+                       return exceptionFuture;
+               } else {
+                       Supplier<Void> restartSupplier = () -> {
+                               restarter.triggerFullRecovery();
+                               return null;
+                       };
+                       return FutureUtils.scheduleAsync(restartSupplier, 
Time.milliseconds(0L), executor);
+               }
+       }
+
+       /**
+        * Creates a FixedDelayRestartStrategy from the given Configuration.
+        *
+        * @param configuration Configuration containing the parameter values 
for the restart strategy
+        * @return Initialized instance of FixedDelayRestartStrategy
+        * @throws Exception
 
 Review comment:
   
![image](https://user-images.githubusercontent.com/1681921/62459526-e4457e80-b77f-11e9-8b71-95a7172c7ad2.png)

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to