Skip to content

Commit 7605187

Browse files
committed
1 parent 8b76370 commit 7605187

1 file changed

Lines changed: 15 additions & 22 deletions

File tree

modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import org.apache.ignite.internal.util.typedef.internal.U;
6464
import org.apache.ignite.internal.util.worker.GridWorker;
6565
import org.apache.ignite.lang.IgniteBiTuple;
66-
import org.apache.ignite.lang.IgniteRunnable;
6766
import org.apache.ignite.lang.IgniteUuid;
6867
import org.apache.ignite.marshaller.Marshaller;
6968
import org.jetbrains.annotations.Nullable;
@@ -734,39 +733,33 @@ else if (isNodeStopping && X.hasCause(e, InterruptedException.class, IgniteInter
734733
* @param sys System flag.
735734
*/
736735
public void cancel(boolean sys) {
737-
try {
738-
if (log.isDebugEnabled())
739-
log.debug("Cancelling job: " + ses);
740-
741-
boolean firstCancel = isCancelled.compareAndSet(false, true);
736+
if (log.isDebugEnabled())
737+
log.debug("Cancelling job: " + ses);
742738

743-
isCancelledBySystem = sys;
739+
boolean firstCancel = isCancelled.compareAndSet(false, true);
744740

745-
status = CANCELLED;
741+
isCancelledBySystem = sys;
746742

747-
final ComputeJob job0 = job;
743+
status = CANCELLED;
748744

749-
U.wrapThreadLoader(dep.classLoader(), (IgniteRunnable)() -> {
750-
try (Scope ignored = ctx.security().withContext(secCtx)) {
751-
job0.cancel();
752-
}
753-
});
745+
final ComputeJob job0 = job;
754746

755-
// Interrupting only when all 'cancelled' flags are set.
756-
// This allows the 'job' to determine it's a cancellation.
757-
onCancel(firstCancel);
758-
759-
if (!internal && ctx.event().isRecordable(EVT_JOB_CANCELLED))
760-
recordEvent(EVT_JOB_CANCELLED, "Job was cancelled: " + job0);
747+
try (Scope ignored = ctx.security().withContext(secCtx)) {
748+
U.wrapThreadLoader(dep.classLoader(), job0::cancel);
761749
}
762-
// Catch throwable to protect against bad user code.
763-
catch (Throwable e) {
750+
catch (Throwable e) { // Catch throwable to protect against bad user code.
764751
U.error(log, "Failed to cancel job due to undeclared user exception [jobId=" + ses.getJobId() +
765752
", ses=" + ses + ']', e);
766753

767754
if (e instanceof Error)
768755
throw e;
769756
}
757+
finally {
758+
onCancel(firstCancel);
759+
760+
if (!internal && ctx.event().isRecordable(EVT_JOB_CANCELLED))
761+
recordEvent(EVT_JOB_CANCELLED, "Job was cancelled: " + job0);
762+
}
770763
}
771764

772765
/**

0 commit comments

Comments
 (0)