Search in sources :

Example 46 with Operation

use of com.hazelcast.spi.Operation in project hazelcast-jet by hazelcast.

the class MasterContext method invokeOnParticipants.

private void invokeOnParticipants(Map<MemberInfo, InternalCompletableFuture<Object>> futures, CompletableFuture<Void> doneFuture, Function<ExecutionPlan, Operation> opCtor) {
    AtomicInteger remainingCount = new AtomicInteger(executionPlanMap.size());
    for (Entry<MemberInfo, ExecutionPlan> e : executionPlanMap.entrySet()) {
        MemberInfo member = e.getKey();
        Operation op = opCtor.apply(e.getValue());
        InternalCompletableFuture<Object> future = nodeEngine.getOperationService().createInvocationBuilder(JetService.SERVICE_NAME, op, member.getAddress()).setDoneCallback(() -> {
            if (remainingCount.decrementAndGet() == 0) {
                doneFuture.complete(null);
            }
        }).invoke();
        futures.put(member, future);
    }
}
Also used : ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Operation(com.hazelcast.spi.Operation) CancelExecutionOperation(com.hazelcast.jet.impl.operation.CancelExecutionOperation) StartExecutionOperation(com.hazelcast.jet.impl.operation.StartExecutionOperation) InitExecutionOperation(com.hazelcast.jet.impl.operation.InitExecutionOperation) CompleteExecutionOperation(com.hazelcast.jet.impl.operation.CompleteExecutionOperation) SnapshotOperation(com.hazelcast.jet.impl.operation.SnapshotOperation)

Example 47 with Operation

use of com.hazelcast.spi.Operation in project hazelcast-jet by hazelcast.

the class MasterContext method invokeStartExecution.

// If a participant leaves or the execution fails in a participant locally, executions are cancelled
// on the remaining participants and the callback is completed after all invocations return.
private void invokeStartExecution() {
    logger.fine("Executing " + jobIdString());
    long executionId = this.executionId;
    ExecutionInvocationCallback callback = new ExecutionInvocationCallback(executionId);
    cancellationToken.whenCompleted(callback::cancelInvocations);
    CompletionToken executionRestartToken = new CompletionToken(logger);
    executionRestartToken.whenCompleted(callback::cancelInvocations);
    Function<ExecutionPlan, Operation> operationCtor = plan -> new StartExecutionOperation(jobId, executionId);
    Consumer<Map<MemberInfo, Object>> completionCallback = results -> {
        this.executionRestartToken = null;
        onExecuteStepCompleted(results, executionRestartToken.isCompleted());
    };
    // We must set executionRestartToken before we call invoke() method because once all invocations
    // are done, executionRestartToken will be reset. Therefore, setting it after the invoke() call is racy.
    this.executionRestartToken = executionRestartToken;
    jobStatus.set(RUNNING);
    invoke(operationCtor, completionCallback, callback);
    if (isSnapshottingEnabled()) {
        coordinationService.scheduleSnapshot(jobId, executionId);
    }
}
Also used : NO_SNAPSHOT(com.hazelcast.jet.impl.execution.SnapshotContext.NO_SNAPSHOT) SnapshotRepository.snapshotDataMapName(com.hazelcast.jet.impl.SnapshotRepository.snapshotDataMapName) NonCompletableFuture(com.hazelcast.jet.impl.util.NonCompletableFuture) Address(com.hazelcast.nio.Address) Util.jobAndExecutionId(com.hazelcast.jet.impl.util.Util.jobAndExecutionId) Processors.mapP(com.hazelcast.jet.core.processor.Processors.mapP) SourceProcessors.readMapP(com.hazelcast.jet.core.processor.SourceProcessors.readMapP) CompletionToken(com.hazelcast.jet.impl.util.CompletionToken) Util.idToString(com.hazelcast.jet.impl.util.Util.idToString) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) STARTING(com.hazelcast.jet.core.JobStatus.STARTING) DAG(com.hazelcast.jet.core.DAG) JobStatus(com.hazelcast.jet.core.JobStatus) ExceptionUtil(com.hazelcast.jet.impl.util.ExceptionUtil) ExecutionService(com.hazelcast.spi.ExecutionService) Operation(com.hazelcast.spi.Operation) CancellationException(java.util.concurrent.CancellationException) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Util.getJetInstance(com.hazelcast.jet.impl.util.Util.getJetInstance) JobConfig(com.hazelcast.jet.config.JobConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) BroadcastKey(com.hazelcast.jet.core.BroadcastKey) List(java.util.List) ExecutionCallback(com.hazelcast.core.ExecutionCallback) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) Entry(java.util.Map.Entry) CancelExecutionOperation(com.hazelcast.jet.impl.operation.CancelExecutionOperation) TopologyChangedException(com.hazelcast.jet.core.TopologyChangedException) COMPLETED(com.hazelcast.jet.core.JobStatus.COMPLETED) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ExecutionPlanBuilder.createExecutionPlans(com.hazelcast.jet.impl.execution.init.ExecutionPlanBuilder.createExecutionPlans) Collectors.partitioningBy(java.util.stream.Collectors.partitioningBy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) StartExecutionOperation(com.hazelcast.jet.impl.operation.StartExecutionOperation) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) HashSet(java.util.HashSet) InitExecutionOperation(com.hazelcast.jet.impl.operation.InitExecutionOperation) ILogger(com.hazelcast.logging.ILogger) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) NOT_STARTED(com.hazelcast.jet.core.JobStatus.NOT_STARTED) MembersView(com.hazelcast.internal.cluster.impl.MembersView) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) Edge(com.hazelcast.jet.core.Edge) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Nullable(javax.annotation.Nullable) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RESTARTING(com.hazelcast.jet.core.JobStatus.RESTARTING) BroadcastEntry(com.hazelcast.jet.impl.execution.BroadcastEntry) ExceptionUtil.isTopologicalFailure(com.hazelcast.jet.impl.util.ExceptionUtil.isTopologicalFailure) DistributedFunctions.entryKey(com.hazelcast.jet.function.DistributedFunctions.entryKey) Consumer(java.util.function.Consumer) Vertex(com.hazelcast.jet.core.Vertex) Collectors.toList(java.util.stream.Collectors.toList) CustomClassLoadedObject.deserializeWithCustomClassLoader(com.hazelcast.jet.impl.execution.init.CustomClassLoadedObject.deserializeWithCustomClassLoader) CompleteExecutionOperation(com.hazelcast.jet.impl.operation.CompleteExecutionOperation) ExceptionUtil.peel(com.hazelcast.jet.impl.util.ExceptionUtil.peel) FAILED(com.hazelcast.jet.core.JobStatus.FAILED) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) JobRestartRequestedException(com.hazelcast.jet.impl.exception.JobRestartRequestedException) SnapshotOperation(com.hazelcast.jet.impl.operation.SnapshotOperation) Edge.between(com.hazelcast.jet.core.Edge.between) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) CompletionToken(com.hazelcast.jet.impl.util.CompletionToken) Operation(com.hazelcast.spi.Operation) CancelExecutionOperation(com.hazelcast.jet.impl.operation.CancelExecutionOperation) StartExecutionOperation(com.hazelcast.jet.impl.operation.StartExecutionOperation) InitExecutionOperation(com.hazelcast.jet.impl.operation.InitExecutionOperation) CompleteExecutionOperation(com.hazelcast.jet.impl.operation.CompleteExecutionOperation) SnapshotOperation(com.hazelcast.jet.impl.operation.SnapshotOperation) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StartExecutionOperation(com.hazelcast.jet.impl.operation.StartExecutionOperation)

Example 48 with Operation

use of com.hazelcast.spi.Operation 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 49 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class AbstractAddressMessageTask method processMessage.

@Override
public final void processMessage() {
    beforeProcess();
    Operation op = prepareOperation();
    op.setCallerUuid(endpoint.getUuid());
    ICompletableFuture f = nodeEngine.getOperationService().createInvocationBuilder(getServiceName(), op, getAddress()).setResultDeserialized(false).invoke();
    f.andThen(this, this);
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture) Operation(com.hazelcast.spi.Operation)

Example 50 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class AbstractPartitionMessageTask method processMessage.

@Override
public final void processMessage() {
    beforeProcess();
    Operation op = prepareOperation();
    op.setCallerUuid(endpoint.getUuid());
    ICompletableFuture f = nodeEngine.getOperationService().createInvocationBuilder(getServiceName(), op, getPartitionId()).setResultDeserialized(false).invoke();
    f.andThen(this, this);
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture) Operation(com.hazelcast.spi.Operation)

Aggregations

Operation (com.hazelcast.spi.Operation)94 OperationService (com.hazelcast.spi.OperationService)14 Member (com.hazelcast.core.Member)13 Address (com.hazelcast.nio.Address)11 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)8 ArrayList (java.util.ArrayList)8 ILogger (com.hazelcast.logging.ILogger)7 UrgentSystemOperation (com.hazelcast.spi.UrgentSystemOperation)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 AcquireOperation (com.hazelcast.concurrent.semaphore.operations.AcquireOperation)6 AvailableOperation (com.hazelcast.concurrent.semaphore.operations.AvailableOperation)6 DrainOperation (com.hazelcast.concurrent.semaphore.operations.DrainOperation)6 InitOperation (com.hazelcast.concurrent.semaphore.operations.InitOperation)6 ReduceOperation (com.hazelcast.concurrent.semaphore.operations.ReduceOperation)6 ReleaseOperation (com.hazelcast.concurrent.semaphore.operations.ReleaseOperation)6 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)6 NodeEngine (com.hazelcast.spi.NodeEngine)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)6