use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class SqlClientTest method when_resultClosed_then_executionContextCleanedUp.
// test for https://github.com/hazelcast/hazelcast/issues/19897
@Test
public void when_resultClosed_then_executionContextCleanedUp() {
HazelcastInstance client = factory().newHazelcastClient();
SqlService sql = client.getSql();
IMap<Integer, Integer> map = instance().getMap("map");
Map<Integer, Integer> tmpMap = new HashMap<>();
for (int i = 0; i < 100_000; i++) {
tmpMap.put(i, i);
if (i % 10_000 == 0) {
map.putAll(tmpMap);
tmpMap.clear();
}
}
createMapping("map", Integer.class, Integer.class);
for (int i = 0; i < 100; i++) {
SqlResult result = sql.execute("SELECT * FROM map");
result.close();
}
JetServiceBackend jetService = getJetServiceBackend(instance());
Collection<ExecutionContext> contexts = jetService.getJobExecutionService().getExecutionContexts();
// Assert that all ExecutionContexts are eventually cleaned up
// This assert will fail if a network packet arrives after the JobExecutionService#FAILED_EXECUTION_EXPIRY_NS
// time. Hopefully Jenkins isn't that slow.
assertTrueEventually(() -> {
String remainingContexts = contexts.stream().map(c -> idToString(c.executionId())).collect(Collectors.joining(", "));
assertEquals("remaining execIds: " + remainingContexts, 0, contexts.size());
}, 5);
// assert that failedJobs is also cleaned up
ConcurrentMap<Long, Long> failedJobs = jetService.getJobExecutionService().getFailedJobs();
assertTrueEventually(() -> assertEquals(0, failedJobs.size()));
}
use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class JobExecutionService method assertExecutionContext.
@Nonnull
public ExecutionContext assertExecutionContext(Address callerAddress, long jobId, long executionId, String callerOpName) {
Address masterAddress = nodeEngine.getMasterAddress();
if (!callerAddress.equals(masterAddress)) {
failIfNotRunning();
throw new IllegalStateException(String.format("Caller %s cannot do '%s' for %s: it is not the master, the master is %s", callerAddress, callerOpName, jobIdAndExecutionId(jobId, executionId), masterAddress));
}
failIfNotRunning();
ExecutionContext executionContext = executionContexts.get(executionId);
if (executionContext == null) {
throw new ExecutionNotFoundException(String.format("%s not found for coordinator %s for '%s'", jobIdAndExecutionId(jobId, executionId), callerAddress, callerOpName));
} else if (!(executionContext.coordinator().equals(callerAddress) && executionContext.jobId() == jobId)) {
throw new IllegalStateException(String.format("%s, originally from coordinator %s, cannot do '%s' by coordinator %s and execution %s", executionContext.jobNameAndExecutionId(), executionContext.coordinator(), callerOpName, callerAddress, idToString(executionId)));
}
return executionContext;
}
use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class JobExecutionService method cancelAllExecutions.
/**
* Cancels all ongoing executions using the given failure supplier.
*/
public void cancelAllExecutions(String reason) {
for (ExecutionContext exeCtx : executionContexts.values()) {
LoggingUtil.logFine(logger, "Completing %s locally. Reason: %s", exeCtx.jobNameAndExecutionId(), reason);
terminateExecution0(exeCtx, null, new CancellationException());
}
}
use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class JobExecutionService method addExecutionContext.
private ExecutionContext addExecutionContext(long jobId, long executionId, Address coordinator, int coordinatorMemberListVersion, Set<MemberInfo> participants) {
ExecutionContext execCtx;
ExecutionContext oldContext;
try {
assertIsMaster(jobId, executionId, coordinator);
verifyClusterInformation(jobId, executionId, coordinator, coordinatorMemberListVersion, participants);
failIfNotRunning();
synchronized (mutex) {
addExecutionContextJobId(jobId, executionId, coordinator);
execCtx = new ExecutionContext(nodeEngine, jobId, executionId, false);
oldContext = executionContexts.put(executionId, execCtx);
}
} catch (Throwable t) {
// The classloader was created in InitExecutionOperation#deserializePlan().
// If the InitExecutionOperation#doRun() fails before ExecutionContext is added
// to executionContexts, then classloader must be removed in order to not have leaks.
jobClassloaderService.tryRemoveClassloadersForJob(jobId, EXECUTION);
throw t;
}
if (oldContext != null) {
throw new RuntimeException("Duplicate ExecutionContext for execution " + Util.idToString(executionId));
}
return execCtx;
}
use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class JobExecutionService method beginExecution.
public CompletableFuture<RawJobMetrics> beginExecution(Address coordinator, long jobId, long executionId, boolean collectMetrics) {
ExecutionContext execCtx = assertExecutionContext(coordinator, jobId, executionId, "StartExecutionOperation");
assert !execCtx.isLightJob() : "StartExecutionOperation received for a light job " + idToString(jobId);
logger.info("Start execution of " + execCtx.jobNameAndExecutionId() + " from coordinator " + coordinator);
return beginExecution0(execCtx, collectMetrics);
}
Aggregations