Search in sources :

Example 6 with ExecutionContext

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

the class JobRestartWithSnapshotTest method getSnapshotContext.

private SnapshotContext getSnapshotContext(Job job) {
    IMapJet<Long, Long> randomIdsMap = instance1.getMap(JobRepository.RANDOM_IDS_MAP_NAME);
    long executionId = randomIdsMap.entrySet().stream().filter(e -> e.getValue().equals(job.getId()) && !e.getValue().equals(e.getKey())).mapToLong(Entry::getKey).findAny().orElseThrow(() -> new AssertionError("ExecutionId not found"));
    ExecutionContext executionContext = null;
    // spin until the executionContext is available on the worker
    while (executionContext == null) {
        executionContext = getJetService(instance2).getJobExecutionService().getExecutionContext(executionId);
    }
    return executionContext.snapshotContext();
}
Also used : AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Traverser(com.hazelcast.jet.Traverser) Arrays(java.util.Arrays) WatermarkPolicies.limitingLag(com.hazelcast.jet.core.WatermarkPolicies.limitingLag) SnapshotContext(com.hazelcast.jet.impl.execution.SnapshotContext) PacketFiltersUtil.delayOperationsFrom(com.hazelcast.test.PacketFiltersUtil.delayOperationsFrom) IMapJet(com.hazelcast.jet.IMapJet) Address(com.hazelcast.nio.Address) Processors.mapP(com.hazelcast.jet.core.processor.Processors.mapP) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) WatermarkGenerationParams.wmGenParams(com.hazelcast.jet.core.WatermarkGenerationParams.wmGenParams) WatermarkEmissionPolicy.emitByFrame(com.hazelcast.jet.core.WatermarkEmissionPolicy.emitByFrame) SnapshotRepository(com.hazelcast.jet.impl.SnapshotRepository) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) JobConfig(com.hazelcast.jet.config.JobConfig) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) BroadcastKey.broadcastKey(com.hazelcast.jet.core.BroadcastKey.broadcastKey) TestSupport(com.hazelcast.jet.core.test.TestSupport) Assert.assertFalse(org.junit.Assert.assertFalse) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) Entry(java.util.Map.Entry) Util.arrayIndexOf(com.hazelcast.jet.impl.util.Util.arrayIndexOf) IntStream(java.util.stream.IntStream) JetInstance(com.hazelcast.jet.JetInstance) SnapshotRecord(com.hazelcast.jet.impl.execution.SnapshotRecord) RunWith(org.junit.runner.RunWith) Processors(com.hazelcast.jet.core.processor.Processors) HashMap(java.util.HashMap) JetInitDataSerializerHook(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook) Function(java.util.function.Function) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) TestUtil.throttle(com.hazelcast.jet.core.TestUtil.throttle) Util.entry(com.hazelcast.jet.Util.entry) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) Processors.combineToSlidingWindowP(com.hazelcast.jet.core.processor.Processors.combineToSlidingWindowP) Comparator.comparing(java.util.Comparator.comparing) ExpectedException(org.junit.rules.ExpectedException) Nonnull(javax.annotation.Nonnull) TestProcessorMetaSupplierContext(com.hazelcast.jet.core.test.TestProcessorMetaSupplierContext) Processors.insertWatermarksP(com.hazelcast.jet.core.processor.Processors.insertWatermarksP) Job(com.hazelcast.jet.Job) Before(org.junit.Before) DistributedFunction.identity(com.hazelcast.jet.function.DistributedFunction.identity) JobRepository(com.hazelcast.jet.impl.JobRepository) JetConfig(com.hazelcast.jet.config.JetConfig) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AggregateOperation1(com.hazelcast.jet.aggregate.AggregateOperation1) Traversers(com.hazelcast.jet.Traversers) DistributedFunctions.entryKey(com.hazelcast.jet.function.DistributedFunctions.entryKey) Collectors.toList(java.util.stream.Collectors.toList) IMap(com.hazelcast.core.IMap) Rule(org.junit.Rule) Ignore(org.junit.Ignore) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Processors.noopP(com.hazelcast.jet.core.processor.Processors.noopP) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Assert.assertEquals(org.junit.Assert.assertEquals) TimestampedEntry(com.hazelcast.jet.datamodel.TimestampedEntry) Edge.between(com.hazelcast.jet.core.Edge.between) SinkProcessors.writeListP(com.hazelcast.jet.core.processor.SinkProcessors.writeListP) Entry(java.util.Map.Entry) TimestampedEntry(com.hazelcast.jet.datamodel.TimestampedEntry) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext)

Example 7 with ExecutionContext

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

the class JobExecutionService method completeExecution.

/**
 * Completes and cleans up execution of the given job
 */
public void completeExecution(@Nonnull ExecutionContext executionContext, Throwable error) {
    ExecutionContext removed = executionContexts.remove(executionContext.executionId());
    if (removed != null) {
        if (error != null) {
            failedJobs.put(executionContext.executionId(), System.nanoTime() + FAILED_EXECUTION_EXPIRY_NS);
        }
        JetDelegatingClassLoader jobClassLoader = jobClassloaderService.getClassLoader(executionContext.jobId());
        try {
            doWithClassLoader(jobClassLoader, () -> executionContext.completeExecution(error));
        } finally {
            if (!executionContext.isLightJob()) {
                jobClassloaderService.tryRemoveClassloadersForJob(executionContext.jobId(), EXECUTION);
            }
            executionCompleted.inc();
            executionContextJobIds.remove(executionContext.jobId());
            logger.fine("Completed execution of " + executionContext.jobNameAndExecutionId());
        }
    }
}
Also used : JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext)

Example 8 with ExecutionContext

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

the class JobExecutionService method checkExecutions.

/**
 * See also javadoc at {@link CheckLightJobsOperation}.
 */
private void checkExecutions() {
    try {
        long now = System.nanoTime();
        long uninitializedContextThreshold = now - UNINITIALIZED_CONTEXT_MAX_AGE_NS;
        Map<Address, List<Long>> executionsPerMember = new HashMap<>();
        for (ExecutionContext ctx : executionContexts.values()) {
            if (!ctx.isLightJob()) {
                continue;
            }
            Address coordinator = ctx.coordinator();
            if (coordinator != null) {
                // if coordinator is known, add execution to the list to check
                executionsPerMember.computeIfAbsent(coordinator, k -> new ArrayList<>()).add(ctx.executionId());
            } else {
                // if coordinator is not known, remove execution if it's not known for too long
                if (ctx.getCreatedOn() <= uninitializedContextThreshold) {
                    LoggingUtil.logFine(logger, "Terminating light job %s because it wasn't initialized during %d seconds", idToString(ctx.executionId()), NANOSECONDS.toSeconds(UNINITIALIZED_CONTEXT_MAX_AGE_NS));
                    terminateExecution0(ctx, TerminationMode.CANCEL_FORCEFUL, new CancellationException());
                }
            }
        }
        // submit the query to the coordinator
        for (Entry<Address, List<Long>> en : executionsPerMember.entrySet()) {
            long[] executionIds = en.getValue().stream().mapToLong(Long::longValue).toArray();
            Operation op = new CheckLightJobsOperation(executionIds);
            InvocationFuture<long[]> future = nodeEngine.getOperationService().createInvocationBuilder(JetServiceBackend.SERVICE_NAME, op, en.getKey()).invoke();
            future.whenComplete((r, t) -> {
                if (t instanceof TargetNotMemberException) {
                    // if the target isn't a member, then all executions are unknown
                    r = executionIds;
                } else if (t != null) {
                    logger.warning("Failed to check light job state with coordinator " + en.getKey() + ": " + t, t);
                    return;
                }
                assert r != null;
                for (long executionId : r) {
                    ExecutionContext execCtx = executionContexts.get(executionId);
                    if (execCtx != null) {
                        logger.fine("Terminating light job " + idToString(executionId) + " because the coordinator doesn't know it");
                        terminateExecution0(execCtx, TerminationMode.CANCEL_FORCEFUL, new CancellationException());
                    }
                }
            });
        }
        // clean up failedJobs
        failedJobs.values().removeIf(expiryTime -> expiryTime < now);
    } catch (Throwable e) {
        logger.severe("Failed to query live light executions: " + e, e);
    }
}
Also used : Address(com.hazelcast.cluster.Address) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) ScheduledFuture(java.util.concurrent.ScheduledFuture) Member(com.hazelcast.cluster.Member) UnaryOperator(java.util.function.UnaryOperator) JobTerminateRequestedException(com.hazelcast.jet.impl.exception.JobTerminateRequestedException) JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) MwCounter(com.hazelcast.internal.util.counters.MwCounter) Map(java.util.Map) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) Counter(com.hazelcast.internal.util.counters.Counter) Collectors.toSet(java.util.stream.Collectors.toSet) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) CancellationException(java.util.concurrent.CancellationException) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) Objects(java.util.Objects) SenderReceiverKey(com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) MetricNames(com.hazelcast.jet.core.metrics.MetricNames) Entry(java.util.Map.Entry) TopologyChangedException(com.hazelcast.jet.core.TopologyChangedException) LoggingUtil(com.hazelcast.jet.impl.util.LoggingUtil) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) MembershipManager(com.hazelcast.internal.cluster.impl.MembershipManager) MetricsCompressor(com.hazelcast.internal.metrics.impl.MetricsCompressor) Util.doWithClassLoader(com.hazelcast.jet.impl.util.Util.doWithClassLoader) SenderTasklet(com.hazelcast.jet.impl.execution.SenderTasklet) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Function(java.util.function.Function) ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) EXECUTION(com.hazelcast.jet.impl.JobClassLoaderService.JobPhase.EXECUTION) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) Collections.newSetFromMap(java.util.Collections.newSetFromMap) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) TaskletExecutionService(com.hazelcast.jet.impl.execution.TaskletExecutionService) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Nonnull(javax.annotation.Nonnull) CheckLightJobsOperation(com.hazelcast.jet.impl.operation.CheckLightJobsOperation) Nullable(javax.annotation.Nullable) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MemberLeftException(com.hazelcast.core.MemberLeftException) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) RawJobMetrics(com.hazelcast.jet.impl.metrics.RawJobMetrics) MetricTags(com.hazelcast.jet.core.metrics.MetricTags) TriggerMemberListPublishOp(com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp) ExceptionUtil.peel(com.hazelcast.jet.impl.util.ExceptionUtil.peel) Util.jobIdAndExecutionId(com.hazelcast.jet.impl.util.Util.jobIdAndExecutionId) Util(com.hazelcast.jet.Util) SECONDS(java.util.concurrent.TimeUnit.SECONDS) CheckLightJobsOperation(com.hazelcast.jet.impl.operation.CheckLightJobsOperation) Address(com.hazelcast.cluster.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Operation(com.hazelcast.spi.impl.operationservice.Operation) CheckLightJobsOperation(com.hazelcast.jet.impl.operation.CheckLightJobsOperation) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) CancellationException(java.util.concurrent.CancellationException) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with ExecutionContext

use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast 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) {
    ExecutionContext execCtx = addExecutionContext(jobId, executionId, coordinator, coordinatorMemberListVersion, participants);
    try {
        jobClassloaderService.prepareProcessorClassLoaders(jobId);
        Set<Address> addresses = participants.stream().map(MemberInfo::getAddress).collect(toSet());
        ClassLoader jobCl = jobClassloaderService.getClassLoader(jobId);
        doWithClassLoader(jobCl, () -> execCtx.initialize(coordinator, addresses, plan));
    } finally {
        jobClassloaderService.clearProcessorClassLoaders();
    }
    // initial log entry with all of jobId, jobName, executionId
    logger.info("Execution plan for jobId=" + idToString(jobId) + ", jobName=" + (execCtx.jobName() != null ? '\'' + execCtx.jobName() + '\'' : "null") + ", executionId=" + idToString(executionId) + " initialized");
}
Also used : ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) Address(com.hazelcast.cluster.Address) JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) Util.doWithClassLoader(com.hazelcast.jet.impl.util.Util.doWithClassLoader)

Example 10 with ExecutionContext

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

the class Networking method handleStreamPacket.

private void handleStreamPacket(Packet packet) {
    byte[] payload = packet.toByteArray();
    long executionId = memoryReader.readLong(payload, 0);
    int vertexId = memoryReader.readInt(payload, Long.BYTES);
    int ordinal = memoryReader.readInt(payload, Long.BYTES + Integer.BYTES);
    ExecutionContext executionContext = jobExecutionService.getOrCreateExecutionContext(executionId);
    if (executionContext != null) {
        executionContext.handlePacket(vertexId, ordinal, packet.getConn().getRemoteAddress(), payload);
    }
}
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