Search in sources :

Example 1 with ExecutionContext

use of com.hazelcast.jet.impl.execution.ExecutionContext 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);
    }));
}
Also used : ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) JetService(com.hazelcast.jet.impl.JetService) CancellationException(java.util.concurrent.CancellationException) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) Address(com.hazelcast.nio.Address) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) IOException(java.io.IOException) Util.jobAndExecutionId(com.hazelcast.jet.impl.util.Util.jobAndExecutionId) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) JetInitDataSerializerHook(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) Address(com.hazelcast.nio.Address) CancellationException(java.util.concurrent.CancellationException)

Example 2 with ExecutionContext

use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast-jet by hazelcast.

the class Networking method createFlowControlPacket.

private byte[] createFlowControlPacket(Address member) throws IOException {
    try (BufferObjectDataOutput out = createObjectDataOutput(nodeEngine)) {
        final boolean[] hasData = { false };
        Map<Long, ExecutionContext> executionContexts = jobExecutionService.getExecutionContextsFor(member);
        out.writeInt(executionContexts.size());
        executionContexts.forEach((execId, exeCtx) -> uncheckRun(() -> {
            out.writeLong(execId);
            out.writeInt(exeCtx.receiverMap().values().stream().mapToInt(Map::size).sum());
            exeCtx.receiverMap().forEach((vertexId, ordinalToSenderToTasklet) -> ordinalToSenderToTasklet.forEach((ordinal, senderToTasklet) -> uncheckRun(() -> {
                out.writeInt(vertexId);
                out.writeInt(ordinal);
                out.writeInt(senderToTasklet.get(member).updateAndGetSendSeqLimitCompressed());
                hasData[0] = true;
            })));
        }));
        return hasData[0] ? out.toByteArray() : EMPTY_BYTES;
    }
}
Also used : Util.createObjectDataOutput(com.hazelcast.jet.impl.util.Util.createObjectDataOutput) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Util.getMemberConnection(com.hazelcast.jet.impl.util.Util.getMemberConnection) ScheduledFuture(java.util.concurrent.ScheduledFuture) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) Util.createObjectDataInput(com.hazelcast.jet.impl.util.Util.createObjectDataInput) Util.getRemoteMembers(com.hazelcast.jet.impl.util.Util.getRemoteMembers) Util.uncheckRun(com.hazelcast.jet.impl.util.Util.uncheckRun) FLAG_JET_FLOW_CONTROL(com.hazelcast.nio.Packet.FLAG_JET_FLOW_CONTROL) Address(com.hazelcast.nio.Address) SenderTasklet(com.hazelcast.jet.impl.execution.SenderTasklet) IOException(java.io.IOException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) NodeEngine(com.hazelcast.spi.NodeEngine) ExceptionUtil.sneakyThrow(com.hazelcast.jet.impl.util.ExceptionUtil.sneakyThrow) Util.idToString(com.hazelcast.jet.impl.util.Util.idToString) Connection(com.hazelcast.nio.Connection) ILogger(com.hazelcast.logging.ILogger) Map(java.util.Map) FLAG_URGENT(com.hazelcast.nio.Packet.FLAG_URGENT) BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) Optional(java.util.Optional) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) Packet(com.hazelcast.nio.Packet) BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext)

Example 3 with ExecutionContext

use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast-jet by hazelcast.

the class JobExecutionService method assertExecutionContext.

public ExecutionContext assertExecutionContext(Address coordinator, long jobId, long executionId, Operation callerOp) {
    Address masterAddress = nodeEngine.getMasterAddress();
    if (!coordinator.equals(masterAddress)) {
        failIfNotRunning();
        throw new IllegalStateException(String.format("Coordinator %s cannot do '%s' for %s: it is not the master, the master is %s", coordinator, callerOp.getClass().getSimpleName(), jobAndExecutionId(jobId, executionId), masterAddress));
    }
    failIfNotRunning();
    ExecutionContext executionContext = executionContexts.get(executionId);
    if (executionContext == null) {
        throw new TopologyChangedException(String.format("%s not found for coordinator %s for '%s'", jobAndExecutionId(jobId, executionId), coordinator, callerOp.getClass().getSimpleName()));
    } else if (!(executionContext.coordinator().equals(coordinator) && executionContext.jobId() == jobId)) {
        throw new IllegalStateException(String.format("%s, originally from coordinator %s, cannot do '%s' by coordinator %s and execution %s", jobAndExecutionId(jobId, executionContext.executionId()), executionContext.coordinator(), callerOp.getClass().getSimpleName(), coordinator, idToString(executionId)));
    }
    return executionContext;
}
Also used : ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) Address(com.hazelcast.nio.Address) TopologyChangedException(com.hazelcast.jet.core.TopologyChangedException)

Example 4 with ExecutionContext

use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast-jet by hazelcast.

the class JobExecutionService method initExecution.

/**
 * Initiates the given execution if the local node accepts the coordinator
 * as its master, and has an up-to-date member list information.
 * <ul><li>
 *   If the local node has a stale member list, it retries the init operation
 *   until it receives the new member list from the master.
 * </li><li>
 *     If the local node detects that the member list changed after the init
 *     operation is sent but before executed, then it sends a graceful failure
 *     so that the job init will be retried properly.
 * </li><li>
 *     If there is an already ongoing execution for the given job, then the
 *     init execution is retried.
 * </li></ul>
 */
public void initExecution(long jobId, long executionId, Address coordinator, int coordinatorMemberListVersion, Set<MemberInfo> participants, ExecutionPlan plan) {
    verifyClusterInformation(jobId, executionId, coordinator, coordinatorMemberListVersion, participants);
    failIfNotRunning();
    if (!executionContextJobIds.add(jobId)) {
        ExecutionContext current = executionContexts.get(executionId);
        if (current != null) {
            throw new IllegalStateException(String.format("Execution context for %s for coordinator %s already exists for coordinator %s", jobAndExecutionId(jobId, executionId), coordinator, current.coordinator()));
        }
        executionContexts.values().stream().filter(e -> e.jobId() == jobId).forEach(e -> logger.fine(String.format("Execution context for %s for coordinator %s already exists" + " with local execution %s for coordinator %s", jobAndExecutionId(jobId, executionId), coordinator, idToString(e.jobId()), e.coordinator())));
        throw new RetryableHazelcastException();
    }
    Set<Address> addresses = participants.stream().map(MemberInfo::getAddress).collect(toSet());
    ExecutionContext created = new ExecutionContext(nodeEngine, taskletExecutionService, jobId, executionId, coordinator, addresses);
    try {
        created.initialize(plan);
    } finally {
        executionContexts.put(executionId, created);
    }
    logger.info("Execution plan for " + jobAndExecutionId(jobId, executionId) + " initialized");
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) DistributedFunctions.entryValue(com.hazelcast.jet.function.DistributedFunctions.entryValue) MembershipManager(com.hazelcast.internal.cluster.impl.MembershipManager) Address(com.hazelcast.nio.Address) SenderTasklet(com.hazelcast.jet.impl.execution.SenderTasklet) Util.jobAndExecutionId(com.hazelcast.jet.impl.util.Util.jobAndExecutionId) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) Util.idToString(com.hazelcast.jet.impl.util.Util.idToString) Collections.newSetFromMap(java.util.Collections.newSetFromMap) Collectors.toMap(java.util.stream.Collectors.toMap) ILogger(com.hazelcast.logging.ILogger) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) TaskletExecutionService(com.hazelcast.jet.impl.execution.TaskletExecutionService) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Collectors.toSet(java.util.stream.Collectors.toSet) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) Operation(com.hazelcast.spi.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PrivilegedAction(java.security.PrivilegedAction) DistributedFunctions.entryKey(com.hazelcast.jet.function.DistributedFunctions.entryKey) TriggerMemberListPublishOp(com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) JetClassLoader(com.hazelcast.jet.impl.deployment.JetClassLoader) TopologyChangedException(com.hazelcast.jet.core.TopologyChangedException) AccessController(java.security.AccessController) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) Address(com.hazelcast.nio.Address)

Example 5 with ExecutionContext

use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast-jet by hazelcast.

the class JobExecutionService method completeExecution.

/**
 * Completes and cleans up execution of the given job
 */
public void completeExecution(long executionId, Throwable error) {
    ExecutionContext executionContext = executionContexts.remove(executionId);
    if (executionContext != null) {
        try {
            executionContext.completeExecution(error);
        } finally {
            classLoaders.remove(executionContext.jobId());
            executionContextJobIds.remove(executionContext.jobId());
            logger.fine("Completed execution of " + jobAndExecutionId(executionContext.jobId(), executionId));
        }
    } else {
        logger.fine("Execution " + idToString(executionId) + " not found for completion");
    }
}
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