use of com.hazelcast.jet.impl.TerminationMode.ActionAfterTerminate in project hazelcast by hazelcast.
the class MasterJobContext method finalizeJob.
void finalizeJob(@Nullable Throwable failure) {
mc.coordinationService().submitToCoordinatorThread(() -> {
final Runnable nonSynchronizedAction;
mc.lock();
try {
JobStatus status = mc.jobStatus();
if (status == COMPLETED || status == FAILED) {
logIgnoredCompletion(failure, status);
return;
}
completeVertices(failure);
mc.getJetServiceBackend().getJobClassLoaderService().tryRemoveClassloadersForJob(mc.jobId(), COORDINATOR);
ActionAfterTerminate terminationModeAction = failure instanceof JobTerminateRequestedException ? ((JobTerminateRequestedException) failure).mode().actionAfterTerminate() : null;
mc.snapshotContext().onExecutionTerminated();
// if restart was requested, restart immediately
if (terminationModeAction == RESTART) {
mc.setJobStatus(NOT_RUNNING);
nonSynchronizedAction = () -> mc.coordinationService().restartJob(mc.jobId());
} else if (!isCancelled() && isRestartableException(failure) && mc.jobConfig().isAutoScaling()) {
// if restart is due to a failure, schedule a restart after a delay
scheduleRestart();
nonSynchronizedAction = NO_OP;
} else if (terminationModeAction == SUSPEND || isRestartableException(failure) && !isCancelled() && !mc.jobConfig().isAutoScaling() && mc.jobConfig().getProcessingGuarantee() != NONE) {
mc.setJobStatus(SUSPENDED);
mc.jobExecutionRecord().setSuspended(null);
nonSynchronizedAction = () -> mc.writeJobExecutionRecord(false);
} else if (failure != null && !isCancelled() && mc.jobConfig().isSuspendOnFailure()) {
mc.setJobStatus(SUSPENDED);
mc.jobExecutionRecord().setSuspended("Execution failure:\n" + ExceptionUtil.stackTraceToString(failure));
nonSynchronizedAction = () -> mc.writeJobExecutionRecord(false);
} else {
long completionTime = System.currentTimeMillis();
boolean isSuccess = logExecutionSummary(failure, completionTime);
mc.setJobStatus(isSuccess ? COMPLETED : FAILED);
if (failure instanceof LocalMemberResetException) {
logger.fine("Cancelling job " + mc.jobIdString() + " locally: member (local or remote) reset. " + "We don't delete job metadata: job will restart on majority cluster");
setFinalResult(new CancellationException());
} else {
mc.coordinationService().completeJob(mc, failure, completionTime).whenComplete(withTryCatch(logger, (r, f) -> {
if (f != null) {
logger.warning("Completion of " + mc.jobIdString() + " failed", f);
} else {
setFinalResult(failure);
}
}));
}
nonSynchronizedAction = NO_OP;
}
// reset the state for the next execution
requestedTerminationMode = null;
executionFailureCallback = null;
} finally {
mc.unlock();
}
executionCompletionFuture.complete(null);
nonSynchronizedAction.run();
});
}
Aggregations