use of java.util.concurrent.CancellationException in project hazelcast-jet by hazelcast.
the class StartExecutionOperation method doRun.
@Override
protected void doRun() throws Exception {
ExecutionContext execCtx = getExecutionCtx();
Address coordinator = getCallerAddress();
getLogger().info("Start execution of " + jobAndExecutionId(jobId(), executionId) + " from coordinator " + coordinator);
execCtx.beginExecution().whenComplete(withTryCatch(getLogger(), (i, e) -> {
if (e instanceof CancellationException) {
getLogger().fine("Execution of " + jobAndExecutionId(jobId(), executionId) + " was cancelled");
} else if (e != null) {
getLogger().fine("Execution of " + jobAndExecutionId(jobId(), executionId) + " completed with failure", e);
} else {
getLogger().fine("Execution of " + jobAndExecutionId(jobId(), executionId) + " completed");
}
doSendResponse(e);
}));
}
use of java.util.concurrent.CancellationException in project hazelcast-jet by hazelcast.
the class MasterContext method getExecuteResult.
/**
* <ul>
* <li>Returns null if there is no failure.
* <li>Returns CancellationException if the job is cancelled.
* <li>Returns JobRestartRequestedException if the current execution is cancelled
* <li>If there is at least one non-restartable failure, such as an exception in user code, then returns that failure.
* <li>Otherwise, the failure is because a job participant has left the cluster.
* In that case, {@code TopologyChangeException} is returned so that the job will be restarted.
* </ul>
*/
private Throwable getExecuteResult(Map<MemberInfo, Object> responses, boolean isRestartRequested) {
if (cancellationToken.isCompleted()) {
logger.fine(jobIdString() + " to be cancelled after execute");
return new CancellationException();
} else if (isRestartRequested) {
return new JobRestartRequestedException();
}
Map<Boolean, List<Entry<MemberInfo, Object>>> grouped = groupResponses(responses);
Collection<MemberInfo> successfulMembers = grouped.get(false).stream().map(Entry::getKey).collect(toList());
if (successfulMembers.size() == executionPlanMap.size()) {
logger.fine("Execute of " + jobIdString() + " is successful.");
return null;
}
List<Entry<MemberInfo, Object>> failures = grouped.get(true);
logger.fine("Execute of " + jobIdString() + " has failures: " + failures);
// In that case, all remaining participants return a CancellationException.
return failures.stream().map(e -> (Throwable) e.getValue()).filter(t -> !(t instanceof CancellationException || isTopologicalFailure(t))).findFirst().map(ExceptionUtil::peel).orElse(new TopologyChangedException());
}
use of java.util.concurrent.CancellationException in project hazelcast-jet by hazelcast.
the class ExecutionLifecycleTest method when_executionCancelled_then_jobCompletedWithCancellationException.
@Test
public void when_executionCancelled_then_jobCompletedWithCancellationException() throws Throwable {
// Given
DAG dag = new DAG().vertex(new Vertex("test", new MockPMS(() -> new MockPS(StuckProcessor::new, NODE_COUNT))));
// When
Job job = instance.newJob(dag);
try {
StuckProcessor.executionStarted.await();
job.cancel();
job.join();
fail("Job execution should fail");
} catch (CancellationException ignored) {
}
assertTrueEventually(() -> {
assertJobFailed(job, new CancellationException());
assertPsClosedWithError(new CancellationException());
assertPmsClosedWithError(new CancellationException());
});
}
use of java.util.concurrent.CancellationException in project hazelcast-jet by hazelcast.
the class ExecutionLifecycleTest method assertJobFailed.
private void assertJobFailed(Job job, Throwable e) {
JobResult jobResult = getJobResult(job);
assertFalse("jobResult.isSuccessful", jobResult.isSuccessful());
assertExceptionInCauses(e, jobResult.getFailure());
JobStatus expectedStatus = e instanceof CancellationException ? JobStatus.COMPLETED : JobStatus.FAILED;
assertEquals("jobStatus", expectedStatus, job.getStatus());
}
use of java.util.concurrent.CancellationException in project hazelcast-jet by hazelcast.
the class SplitBrainTest method when_quorumIsLostOnMinority_then_jobRestartsUntilMerge.
@Test
public void when_quorumIsLostOnMinority_then_jobRestartsUntilMerge() {
int firstSubClusterSize = 3;
int secondSubClusterSize = 2;
int clusterSize = firstSubClusterSize + secondSubClusterSize;
StuckProcessor.executionStarted = new CountDownLatch(clusterSize * PARALLELISM);
Job[] jobRef = new Job[1];
Consumer<JetInstance[]> beforeSplit = instances -> {
MockPS processorSupplier = new MockPS(StuckProcessor::new, clusterSize);
DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
jobRef[0] = instances[0].newJob(dag, new JobConfig().setSplitBrainProtection(true));
assertOpenEventually(StuckProcessor.executionStarted);
};
Future[] minorityJobFutureRef = new Future[1];
BiConsumer<JetInstance[], JetInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
StuckProcessor.proceedLatch.countDown();
assertTrueEventually(() -> assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get()));
long jobId = jobRef[0].getId();
assertTrueEventually(() -> {
JetService service = getJetService(firstSubCluster[0]);
assertEquals(COMPLETED, service.getJobCoordinationService().getJobStatus(jobId));
});
JetService service2 = getJetService(secondSubCluster[0]);
assertTrueEventually(() -> {
assertEquals(STARTING, service2.getJobCoordinationService().getJobStatus(jobId));
});
MasterContext masterContext = service2.getJobCoordinationService().getMasterContext(jobId);
assertNotNull(masterContext);
minorityJobFutureRef[0] = masterContext.completionFuture();
assertTrueAllTheTime(() -> {
assertEquals(STARTING, service2.getJobCoordinationService().getJobStatus(jobId));
}, 20);
};
Consumer<JetInstance[]> afterMerge = instances -> {
assertTrueEventually(() -> {
assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get());
assertEquals(clusterSize + firstSubClusterSize, MockPS.closeCount.get());
});
assertEquals(clusterSize, MockPS.receivedCloseErrors.size());
MockPS.receivedCloseErrors.forEach(t -> assertTrue(t instanceof TopologyChangedException));
try {
minorityJobFutureRef[0].get();
fail();
} catch (CancellationException ignored) {
} catch (Exception e) {
throw new AssertionError(e);
}
};
testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, onSplit, afterMerge);
}
Aggregations