rmetzger commented on a change in pull request #14948: URL: https://github.com/apache/flink/pull/14948#discussion_r594115925
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/StopWithSavepointOperationManagerForAdaptiveScheduler.java ########## @@ -0,0 +1,117 @@ +/* + * 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.adaptive; + +import org.apache.flink.runtime.checkpoint.CompletedCheckpoint; +import org.apache.flink.runtime.checkpoint.StopWithSavepointOperations; +import org.apache.flink.runtime.concurrent.FutureUtils; +import org.apache.flink.runtime.execution.ExecutionState; +import org.apache.flink.runtime.executiongraph.Execution; +import org.apache.flink.runtime.executiongraph.ExecutionGraph; +import org.apache.flink.runtime.scheduler.stopwithsavepoint.StopWithSavepointOperationHandler; +import org.apache.flink.runtime.scheduler.stopwithsavepoint.StopWithSavepointOperationHandlerImpl; +import org.apache.flink.util.Preconditions; + +import org.slf4j.Logger; + +import javax.annotation.Nullable; + +import java.util.Collection; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; +import java.util.stream.Collectors; + +/** + * A thin wrapper around the StopWithSavepointOperationHandler to handle global failures according + * to the needs of AdaptiveScheduler. AdaptiveScheduler currently doesn't support local failover, + * hence, any reported failure will lead to a transition to Restarting or Failing state. + */ +class StopWithSavepointOperationManagerForAdaptiveScheduler implements GlobalFailureHandler { + private final StopWithSavepointOperationHandler handler; + private final ExecutionGraph executionGraph; + private final StopWithSavepointOperations stopWithSavepointOperations; + private boolean operationFinished = false; + + StopWithSavepointOperationManagerForAdaptiveScheduler( + ExecutionGraph executionGraph, + StopWithSavepointOperations stopWithSavepointOperations, + boolean terminate, + @Nullable String targetDirectory, + Executor mainThreadExecutor, + Logger logger) { + + this.stopWithSavepointOperations = stopWithSavepointOperations; + + // do not trigger checkpoints while creating the final savepoint. We will start the + // scheduler onLeave() again. + stopWithSavepointOperations.stopCheckpointScheduler(); + + final CompletableFuture<CompletedCheckpoint> savepointFuture = + stopWithSavepointOperations.triggerSynchronousSavepoint(terminate, targetDirectory); + + this.handler = + new StopWithSavepointOperationHandlerImpl( + executionGraph.getJobID(), this, stopWithSavepointOperations, logger); + + FutureUtils.assertNoException( + savepointFuture + // the completedSavepointFuture could also be completed by + // CheckpointCanceller which doesn't run in the mainThreadExecutor Review comment: It's copy-pasted from Matthias implementation ;) ---------------------------------------------------------------- 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]
