Search in sources :

Example 11 with ExecutionPlan

use of com.hazelcast.jet.impl.execution.init.ExecutionPlan in project hazelcast by hazelcast.

the class LightMasterContext method invokeOnParticipants.

/**
 * @param completionCallback a consumer that will receive a list of
 *                           responses, one for each member, after all have
 *                           been received. The value will be either the
 *                           response (including a null response) or an
 *                           exception thrown from the operation; size will
 *                           be equal to participant count
 * @param errorCallback A callback that will be called after each a
 *                     failure of each individual operation
 */
private void invokeOnParticipants(Function<ExecutionPlan, Operation> operationCtor, @Nullable Consumer<Collection<Object>> completionCallback, @Nullable Consumer<Throwable> errorCallback) {
    ConcurrentMap<Address, Object> responses = new ConcurrentHashMap<>();
    AtomicInteger remainingCount = new AtomicInteger(executionPlanMap.size());
    for (Entry<MemberInfo, ExecutionPlan> entry : executionPlanMap.entrySet()) {
        Address address = entry.getKey().getAddress();
        Operation op = operationCtor.apply(entry.getValue());
        invokeOnParticipant(address, op, completionCallback, errorCallback, responses, remainingCount);
    }
}
Also used : ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) Address(com.hazelcast.cluster.Address) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TerminateExecutionOperation(com.hazelcast.jet.impl.operation.TerminateExecutionOperation) InitExecutionOperation(com.hazelcast.jet.impl.operation.InitExecutionOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 12 with ExecutionPlan

use of com.hazelcast.jet.impl.execution.init.ExecutionPlan in project hazelcast by hazelcast.

the class MasterSnapshotContext method onSnapshotPhase1CompleteWithStartResponses.

private void onSnapshotPhase1CompleteWithStartResponses(Collection<Entry<MemberInfo, Object>> responses, long executionId, long snapshotId, String snapshotMapName, int snapshotFlags, @Nullable CompletableFuture<Void> future, SnapshotPhase1Result mergedResult, List<CompletableFuture<Void>> missingResponses) {
    mc.coordinationService().submitToCoordinatorThread(() -> {
        mc.lock();
        boolean isSuccess;
        SnapshotStats stats;
        try {
            if (!missingResponses.isEmpty()) {
                LoggingUtil.logFine(logger, "%s all awaited responses to StartExecutionOperation received or " + "were already received", mc.jobIdString());
            }
            // Check the execution ID to check if a new execution didn't start yet.
            if (executionId != mc.executionId()) {
                LoggingUtil.logFine(logger, "%s: ignoring responses for snapshot %s phase 1: " + "the responses are from a different execution: %s. Responses: %s", mc.jobIdString(), snapshotId, idToString(executionId), responses);
                // a new execution started, ignore this response.
                return;
            }
            for (CompletableFuture<Void> response : missingResponses) {
                assert response.isDone() : "response not done";
                try {
                    response.get();
                } catch (ExecutionException e) {
                    mergedResult.merge(new SnapshotPhase1Result(0, 0, 0, e.getCause()));
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
            IMap<Object, Object> snapshotMap = mc.nodeEngine().getHazelcastInstance().getMap(snapshotMapName);
            try {
                SnapshotValidationRecord validationRecord = new SnapshotValidationRecord(snapshotId, mergedResult.getNumChunks(), mergedResult.getNumBytes(), mc.jobExecutionRecord().ongoingSnapshotStartTime(), mc.jobId(), mc.jobName(), mc.jobRecord().getDagJson());
                // The decision moment for exported snapshots: after this the snapshot is valid to be restored
                // from, however it will be not listed by JetInstance.getJobStateSnapshots unless the validation
                // record is inserted into the cache below
                Object oldValue = snapshotMap.put(SnapshotValidationRecord.KEY, validationRecord);
                if (snapshotMapName.startsWith(EXPORTED_SNAPSHOTS_PREFIX)) {
                    String snapshotName = snapshotMapName.substring(EXPORTED_SNAPSHOTS_PREFIX.length());
                    mc.jobRepository().cacheValidationRecord(snapshotName, validationRecord);
                }
                if (oldValue != null) {
                    logger.severe("SnapshotValidationRecord overwritten after writing to '" + snapshotMapName + "' for " + mc.jobIdString() + ": snapshot data might be corrupted");
                }
            } catch (Exception e) {
                mergedResult.merge(new SnapshotPhase1Result(0, 0, 0, e));
            }
            isSuccess = mergedResult.getError() == null;
            stats = mc.jobExecutionRecord().ongoingSnapshotDone(mergedResult.getNumBytes(), mergedResult.getNumKeys(), mergedResult.getNumChunks(), mergedResult.getError());
            // the decision moment for regular snapshots: after this the snapshot is ready to be restored from
            mc.writeJobExecutionRecord(false);
            if (logger.isFineEnabled()) {
                logger.fine(String.format("Snapshot %d phase 1 for %s completed with status %s in %dms, " + "%,d bytes, %,d keys in %,d chunks, stored in '%s', proceeding to phase 2", snapshotId, mc.jobIdString(), isSuccess ? "SUCCESS" : "FAILURE", stats.duration(), stats.numBytes(), stats.numKeys(), stats.numChunks(), snapshotMapName));
            }
            if (!isSuccess) {
                logger.warning(mc.jobIdString() + " snapshot " + snapshotId + " phase 1 failed on some " + "member(s), one of the failures: " + mergedResult.getError());
                try {
                    snapshotMap.clear();
                } catch (Exception e) {
                    logger.warning(mc.jobIdString() + ": failed to clear snapshot map '" + snapshotMapName + "' after a failure", e);
                }
            }
            if (!SnapshotFlags.isExport(snapshotFlags)) {
                mc.jobRepository().clearSnapshotData(mc.jobId(), mc.jobExecutionRecord().ongoingDataMapIndex());
            }
        } finally {
            mc.unlock();
        }
        // start the phase 2
        Function<ExecutionPlan, Operation> factory = plan -> new SnapshotPhase2Operation(mc.jobId(), executionId, snapshotId, isSuccess && !SnapshotFlags.isExportOnly(snapshotFlags));
        mc.invokeOnParticipants(factory, responses2 -> onSnapshotPhase2Complete(mergedResult.getError(), responses2, executionId, snapshotId, snapshotFlags, future, stats.startTime()), null, true);
    });
}
Also used : SnapshotPhase2Operation(com.hazelcast.jet.impl.operation.SnapshotPhase2Operation) LoggingUtil(com.hazelcast.jet.impl.util.LoggingUtil) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) JetException(com.hazelcast.jet.JetException) Util.jobNameAndExecutionId(com.hazelcast.jet.impl.util.Util.jobNameAndExecutionId) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) SnapshotPhase1Operation(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation) LinkedList(java.util.LinkedList) EXPORTED_SNAPSHOTS_PREFIX(com.hazelcast.jet.impl.JobRepository.EXPORTED_SNAPSHOTS_PREFIX) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Tuple3(com.hazelcast.jet.datamodel.Tuple3) SnapshotFlags(com.hazelcast.jet.impl.execution.SnapshotFlags) Collection(java.util.Collection) JobRepository.snapshotDataMapName(com.hazelcast.jet.impl.JobRepository.snapshotDataMapName) ExecutionException(java.util.concurrent.ExecutionException) JobRepository.exportedSnapshotMapName(com.hazelcast.jet.impl.JobRepository.exportedSnapshotMapName) SnapshotPhase1Result(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation.SnapshotPhase1Result) Tuple3.tuple3(com.hazelcast.jet.datamodel.Tuple3.tuple3) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString) LoggingUtil.logFine(com.hazelcast.jet.impl.util.LoggingUtil.logFine) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) Entry(java.util.Map.Entry) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) Queue(java.util.Queue) SnapshotStats(com.hazelcast.jet.impl.JobExecutionRecord.SnapshotStats) IMap(com.hazelcast.map.IMap) SnapshotStats(com.hazelcast.jet.impl.JobExecutionRecord.SnapshotStats) SnapshotPhase1Result(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation.SnapshotPhase1Result) Util.idToString(com.hazelcast.jet.Util.idToString) SnapshotPhase2Operation(com.hazelcast.jet.impl.operation.SnapshotPhase2Operation) Operation(com.hazelcast.spi.impl.operationservice.Operation) SnapshotPhase1Operation(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation) ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) JetException(com.hazelcast.jet.JetException) ExecutionException(java.util.concurrent.ExecutionException) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) SnapshotPhase2Operation(com.hazelcast.jet.impl.operation.SnapshotPhase2Operation) ExecutionException(java.util.concurrent.ExecutionException)

Example 13 with ExecutionPlan

use of com.hazelcast.jet.impl.execution.init.ExecutionPlan in project hazelcast by hazelcast.

the class InitExecutionOperation method doRun.

@Override
protected CompletableFuture<?> doRun() {
    ILogger logger = getLogger();
    if (!getNodeEngine().getLocalMember().getVersion().asVersion().equals(coordinatorVersion)) {
        // the same address.
        throw new JetException("Mismatch between coordinator and participant version");
    }
    JetServiceBackend service = getJetServiceBackend();
    Address caller = getCallerAddress();
    LoggingUtil.logFine(logger, "Initializing execution plan for %s from %s", jobIdAndExecutionId(jobId(), executionId), caller);
    ExecutionPlan plan = deserializePlan(serializedPlan);
    if (isLightJob) {
        return service.getJobExecutionService().runLightJob(jobId(), executionId, caller, coordinatorMemberListVersion, participants, plan);
    } else {
        service.getJobExecutionService().initExecution(jobId(), executionId, caller, coordinatorMemberListVersion, participants, plan);
        return CompletableFuture.completedFuture(null);
    }
}
Also used : ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) Address(com.hazelcast.cluster.Address) ILogger(com.hazelcast.logging.ILogger) JetException(com.hazelcast.jet.JetException) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend)

Example 14 with ExecutionPlan

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

the class InitExecutionOperation method run.

@Override
public void run() {
    ILogger logger = getLogger();
    JetService service = getService();
    Address caller = getCallerAddress();
    logger.fine("Initializing execution plan for " + jobAndExecutionId(jobId(), executionId) + " from " + caller);
    ExecutionPlan plan = deserializePlan(serializedPlan);
    service.getJobExecutionService().initExecution(jobId(), executionId, caller, coordinatorMemberListVersion, participants, plan);
}
Also used : JetService(com.hazelcast.jet.impl.JetService) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) Address(com.hazelcast.nio.Address) ILogger(com.hazelcast.logging.ILogger)

Example 15 with ExecutionPlan

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

the class ExecutionLifecycleTest method when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute.

@Test
public void when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute() {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(instance.getHazelcastInstance());
    Address localAddress = nodeEngineImpl.getThisAddress();
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngineImpl.getClusterService();
    MembersView membersView = clusterService.getMembershipManager().getMembersView();
    int memberListVersion = membersView.getVersion();
    JetService jetService = getJetService(instance);
    final Map<MemberInfo, ExecutionPlan> executionPlans = ExecutionPlanBuilder.createExecutionPlans(nodeEngineImpl, membersView, dag, new JobConfig(), NO_SNAPSHOT);
    ExecutionPlan executionPlan = executionPlans.get(membersView.getMember(localAddress));
    long jobId = 0;
    long executionId = 1;
    Set<MemberInfo> participants = new HashSet<>(membersView.getMembers());
    jetService.getJobExecutionService().initExecution(jobId, executionId, localAddress, memberListVersion, participants, executionPlan);
    ExecutionContext executionContext = jetService.getJobExecutionService().getExecutionContext(executionId);
    executionContext.cancelExecution();
    // When
    CompletableFuture<Void> future = executionContext.beginExecution();
    // Then
    expectedException.expect(CancellationException.class);
    future.join();
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) JetService(com.hazelcast.jet.impl.JetService) Address(com.hazelcast.nio.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) MembersView(com.hazelcast.internal.cluster.impl.MembersView) JobConfig(com.hazelcast.jet.config.JobConfig) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ExecutionPlan (com.hazelcast.jet.impl.execution.init.ExecutionPlan)15 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)13 ILogger (com.hazelcast.logging.ILogger)10 ExceptionUtil.withTryCatch (com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch)8 Map (java.util.Map)8 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)7 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)7 Collection (java.util.Collection)7 List (java.util.List)7 Entry (java.util.Map.Entry)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Function (java.util.function.Function)7 Nullable (javax.annotation.Nullable)7 MembersView (com.hazelcast.internal.cluster.impl.MembersView)6 StartExecutionOperation (com.hazelcast.jet.impl.operation.StartExecutionOperation)6 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)5 TopologyChangedException (com.hazelcast.jet.core.TopologyChangedException)5 InitExecutionOperation (com.hazelcast.jet.impl.operation.InitExecutionOperation)5 Operation (com.hazelcast.spi.Operation)5