Search in sources :

Example 16 with ExecutionContext

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()));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlService(com.hazelcast.sql.SqlService) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) BeforeClass(org.junit.BeforeClass) Collection(java.util.Collection) Test(org.junit.Test) HashMap(java.util.HashMap) TestBatchSqlConnector(com.hazelcast.jet.sql.impl.connector.test.TestBatchSqlConnector) Collectors(java.util.stream.Collectors) ConcurrentMap(java.util.concurrent.ConcurrentMap) TestFailingSqlConnector(com.hazelcast.jet.sql.impl.connector.test.TestFailingSqlConnector) Util.idToString(com.hazelcast.jet.Util.idToString) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) SqlResult(com.hazelcast.sql.SqlResult) FAILED(com.hazelcast.jet.core.JobStatus.FAILED) BitSet(java.util.BitSet) SqlRow(com.hazelcast.sql.SqlRow) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) IMap(com.hazelcast.map.IMap) SqlResult(com.hazelcast.sql.SqlResult) HashMap(java.util.HashMap) Util.idToString(com.hazelcast.jet.Util.idToString) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) SqlService(com.hazelcast.sql.SqlService) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) Test(org.junit.Test)

Example 17 with ExecutionContext

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;
}
Also used : ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) Address(com.hazelcast.cluster.Address) Nonnull(javax.annotation.Nonnull)

Example 18 with 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());
    }
}
Also used : ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) CancellationException(java.util.concurrent.CancellationException)

Example 19 with ExecutionContext

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;
}
Also used : ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext)

Example 20 with ExecutionContext

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);
}
Also used : ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext)

Aggregations

ExecutionContext (com.hazelcast.jet.impl.execution.ExecutionContext)29 Address (com.hazelcast.cluster.Address)7 Address (com.hazelcast.nio.Address)7 Map (java.util.Map)7 JetServiceBackend (com.hazelcast.jet.impl.JetServiceBackend)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)6 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)5 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)5 TopologyChangedException (com.hazelcast.jet.core.TopologyChangedException)5 ExecutionNotFoundException (com.hazelcast.jet.impl.exception.ExecutionNotFoundException)5 ExecutionPlan (com.hazelcast.jet.impl.execution.init.ExecutionPlan)5 HashMap (java.util.HashMap)5 CancellationException (java.util.concurrent.CancellationException)5 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)4 JetInitDataSerializerHook (com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook)4 RetryableHazelcastException (com.hazelcast.spi.exception.RetryableHazelcastException)4 IOException (java.io.IOException)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 MembershipManager (com.hazelcast.internal.cluster.impl.MembershipManager)3 TriggerMemberListPublishOp (com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp)3