|
63 | 63 | import org.apache.ignite.internal.util.typedef.internal.U; |
64 | 64 | import org.apache.ignite.internal.util.worker.GridWorker; |
65 | 65 | import org.apache.ignite.lang.IgniteBiTuple; |
66 | | -import org.apache.ignite.lang.IgniteRunnable; |
67 | 66 | import org.apache.ignite.lang.IgniteUuid; |
68 | 67 | import org.apache.ignite.marshaller.Marshaller; |
69 | 68 | import org.jetbrains.annotations.Nullable; |
@@ -734,39 +733,33 @@ else if (isNodeStopping && X.hasCause(e, InterruptedException.class, IgniteInter |
734 | 733 | * @param sys System flag. |
735 | 734 | */ |
736 | 735 | 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); |
742 | 738 |
|
743 | | - isCancelledBySystem = sys; |
| 739 | + boolean firstCancel = isCancelled.compareAndSet(false, true); |
744 | 740 |
|
745 | | - status = CANCELLED; |
| 741 | + isCancelledBySystem = sys; |
746 | 742 |
|
747 | | - final ComputeJob job0 = job; |
| 743 | + status = CANCELLED; |
748 | 744 |
|
749 | | - U.wrapThreadLoader(dep.classLoader(), (IgniteRunnable)() -> { |
750 | | - try (Scope ignored = ctx.security().withContext(secCtx)) { |
751 | | - job0.cancel(); |
752 | | - } |
753 | | - }); |
| 745 | + final ComputeJob job0 = job; |
754 | 746 |
|
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); |
761 | 749 | } |
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. |
764 | 751 | U.error(log, "Failed to cancel job due to undeclared user exception [jobId=" + ses.getJobId() + |
765 | 752 | ", ses=" + ses + ']', e); |
766 | 753 |
|
767 | 754 | if (e instanceof Error) |
768 | 755 | throw e; |
769 | 756 | } |
| 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 | + } |
770 | 763 | } |
771 | 764 |
|
772 | 765 | /** |
|
0 commit comments