zhuzhurk commented on code in PR #24771:
URL: https://github.com/apache/flink/pull/24771#discussion_r1609784148
##########
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptivebatch/AdaptiveBatchScheduler.java:
##########
@@ -224,18 +250,153 @@ private SpeculativeExecutionHandler
createSpeculativeExecutionHandler(
protected void startSchedulingInternal() {
speculativeExecutionHandler.init(
getExecutionGraph(), getMainThreadExecutor(),
jobManagerJobMetricGroup);
+ jobRecoveryHandler.initialize(
+ log,
+ getExecutionGraph(),
+ shuffleMaster,
+ getMainThreadExecutor(),
+ failoverStrategy,
+ this::failJob,
+ this::resetVerticesInRecovering,
+ this::updateResultPartitionBytesMetrics,
+ this::initializeJobVertex,
+ this::updateTopology);
+
+ if (jobRecoveryHandler.needRecover()) {
+ getMainThreadExecutor()
+ .schedule(
+ () ->
+ jobRecoveryHandler.startRecovering(
+ this::onRecoveringFinished,
this::onRecoveringFailed),
+ previousWorkerRecoveryTimeout.toMillis(),
+ TimeUnit.MILLISECONDS);
+ } else {
+ tryComputeSourceParallelismThenRunAsync(
+ (Void value, Throwable throwable) -> {
+ if (getExecutionGraph().getState() ==
JobStatus.CREATED) {
+ initializeVerticesIfPossible();
+ super.startSchedulingInternal();
+ }
+ });
+ }
+ }
+
+ @Override
+ protected void maybeRestartTasks(final FailureHandlingResult
failureHandlingResult) {
+ FailureHandlingResult wrappedResult = failureHandlingResult;
+ if (failureHandlingResult.canRestart()) {
+ Set<ExecutionVertexID> originalNeedToRestartVertices =
+ failureHandlingResult.getVerticesToRestart();
+
+ Set<JobVertexID> extraNeedToRestartJobVertices =
+ originalNeedToRestartVertices.stream()
+ .map(ExecutionVertexID::getJobVertexId)
+ .filter(requiredRestartJobVertices::contains)
+ .collect(Collectors.toSet());
+
+
requiredRestartJobVertices.removeAll(extraNeedToRestartJobVertices);
+
+ Set<ExecutionVertexID> needToRestartVertices =
+ extraNeedToRestartJobVertices.stream()
+ .flatMap(
+ jobVertexId -> {
+ ExecutionJobVertex jobVertex =
+
getExecutionJobVertex(jobVertexId);
+ return
Arrays.stream(jobVertex.getTaskVertices())
+ .map(ExecutionVertex::getID);
+ })
+ .collect(Collectors.toSet());
+ needToRestartVertices.addAll(originalNeedToRestartVertices);
+
+ wrappedResult =
+ FailureHandlingResult.restartable(
+
failureHandlingResult.getFailedExecution().orElse(null),
+ failureHandlingResult.getError(),
+ failureHandlingResult.getTimestamp(),
+ failureHandlingResult.getFailureLabels(),
+ needToRestartVertices,
+ failureHandlingResult.getRestartDelayMS(),
+ failureHandlingResult.isGlobalFailure(),
+ failureHandlingResult.isRootCause());
+ }
+
+ super.maybeRestartTasks(wrappedResult);
+ }
+
+ @VisibleForTesting
+ boolean isRecovering() {
+ return jobRecoveryHandler.isRecovering();
+ }
+
+ @Override
+ public boolean updateTaskExecutionState(final TaskExecutionStateTransition
taskExecutionState) {
+ boolean success = super.updateTaskExecutionState(taskExecutionState);
+
+ if (success
+ && taskExecutionState.getExecutionState() ==
ExecutionState.FINISHED
+ && !isRecovering()) {
+ final ExecutionVertexID executionVertexId =
+ taskExecutionState.getID().getExecutionVertexId();
+ jobRecoveryHandler.notifyExecutionFinished(executionVertexId,
taskExecutionState);
+ }
+ return success;
+ }
+
+ @Override
+ protected void resetForNewExecutions(Collection<ExecutionVertexID>
vertices) {
+ super.resetForNewExecutions(vertices);
+ if (!isRecovering()) {
+ jobRecoveryHandler.notifyExecutionVertexReset(vertices);
+ }
+ }
+
+ private void initializeJobVertex(
+ ExecutionJobVertex jobVertex,
+ int parallelism,
+ Map<IntermediateDataSetID, JobVertexInputInfo> jobVertexInputInfos,
+ long createTimestamp)
+ throws JobException {
+ if (!jobVertex.isParallelismDecided()) {
+ changeJobVertexParallelism(jobVertex, parallelism);
+ } else {
+ checkState(parallelism == jobVertex.getParallelism());
+ }
+ checkState(canInitialize(jobVertex));
+ getExecutionGraph().initializeJobVertex(jobVertex, createTimestamp,
jobVertexInputInfos);
+ if (!isRecovering()) {
+ jobRecoveryHandler.notifyExecutionJobVertexInitialization(
+ jobVertex.getJobVertex().getID(), parallelism,
jobVertexInputInfos);
+ }
+ }
+
+ private void resetVerticesInRecovering(Set<ExecutionVertexID>
verticesToReset)
+ throws Exception {
+ for (ExecutionVertexID executionVertexID : verticesToReset) {
+ notifyCoordinatorsAboutTaskFailure(
+
getExecutionVertex(executionVertexID).getCurrentExecutionAttempt(), null);
+ }
+ resetForNewExecutions(verticesToReset);
+ restoreState(verticesToReset, false);
+ }
+ private void onRecoveringFinished(Set<JobVertexID>
requiredRestartJobVertices) {
Review Comment:
Is is possible to avoid depending on the handler to offer this
`requiredRestartJobVertices`, but instead continue the scheduling with the
current topology status?
--
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]