Search in sources :

Example 1 with TargetNotMemberException

use of com.hazelcast.spi.exception.TargetNotMemberException in project hazelcast by hazelcast.

the class ClusterStateManager method changeClusterState.

void changeClusterState(ClusterStateChange newState, Collection<Member> members, TransactionOptions options, int partitionStateVersion, boolean isTransient) {
    checkParameters(newState, options);
    if (isCurrentStateEqualToRequestedOne(newState)) {
        return;
    }
    NodeEngineImpl nodeEngine = node.getNodeEngine();
    TransactionManagerServiceImpl txManagerService = (TransactionManagerServiceImpl) nodeEngine.getTransactionManagerService();
    Transaction tx = txManagerService.newAllowedDuringPassiveStateTransaction(options);
    tx.begin();
    try {
        String txnId = tx.getTxnId();
        addTransactionRecords(newState, tx, members, partitionStateVersion, isTransient);
        lockClusterStateOnAllMembers(newState, nodeEngine, options.getTimeoutMillis(), txnId, members, partitionStateVersion);
        checkMemberListChange(members);
        tx.prepare();
    } catch (Throwable e) {
        tx.rollback();
        throw ExceptionUtil.rethrow(e);
    }
    try {
        tx.commit();
    } catch (Throwable e) {
        if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
            // if new state is passive or frozen. They will be able to rejoin later.
            return;
        }
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) Transaction(com.hazelcast.transaction.impl.Transaction) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 2 with TargetNotMemberException

use of com.hazelcast.spi.exception.TargetNotMemberException in project hazelcast by hazelcast.

the class ClusterStateManager method changeClusterState.

void changeClusterState(@Nonnull ClusterStateChange stateChange, @Nonnull MemberMap memberMap, @Nonnull TransactionOptions options, long partitionStateStamp, boolean isTransient) {
    checkParameters(stateChange, options);
    if (isCurrentStateEqualToRequestedOne(stateChange)) {
        return;
    }
    ClusterState oldState = getState();
    ClusterState requestedState = stateChange.getClusterStateOrNull();
    NodeEngineImpl nodeEngine = node.getNodeEngine();
    TransactionManagerServiceImpl txManagerService = (TransactionManagerServiceImpl) nodeEngine.getTransactionManagerService();
    Transaction tx = txManagerService.newAllowedDuringPassiveStateTransaction(options);
    notifyBeforeStateChange(oldState, requestedState, isTransient);
    tx.begin();
    try {
        UUID txnId = tx.getTxnId();
        Collection<MemberImpl> members = memberMap.getMembers();
        int memberListVersion = memberMap.getVersion();
        addTransactionRecords(stateChange, tx, members, memberListVersion, partitionStateStamp, isTransient);
        lockClusterStateOnAllMembers(stateChange, nodeEngine, options.getTimeoutMillis(), txnId, members, memberListVersion, partitionStateStamp);
        checkMemberListChange(memberListVersion);
        tx.prepare();
    } catch (Throwable e) {
        tx.rollback();
        notifyAfterStateChange(oldState, requestedState, isTransient);
        if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
            throw new IllegalStateException("Cluster members changed during state change!", e);
        }
        throw ExceptionUtil.rethrow(e);
    }
    try {
        tx.commit();
    } catch (Throwable e) {
        if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
            // if new state is passive or frozen. They will be able to rejoin later.
            return;
        }
        throw ExceptionUtil.rethrow(e);
    } finally {
        notifyAfterStateChange(oldState, requestedState, isTransient);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ClusterState(com.hazelcast.cluster.ClusterState) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) Transaction(com.hazelcast.transaction.impl.Transaction) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) UUID(java.util.UUID) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 3 with TargetNotMemberException

use of com.hazelcast.spi.exception.TargetNotMemberException in project hazelcast by hazelcast.

the class BaseMigrationOperation method verifyExistingDestination.

/**
 * Verifies that the destination is a cluster member.
 */
final void verifyExistingDestination() {
    PartitionReplica destination = migrationInfo.getDestination();
    Member target = getNodeEngine().getClusterService().getMember(destination.address(), destination.uuid());
    if (target == null) {
        throw new TargetNotMemberException("Destination of migration could not be found! => " + toString());
    }
}
Also used : TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Member(com.hazelcast.cluster.Member)

Example 4 with TargetNotMemberException

use of com.hazelcast.spi.exception.TargetNotMemberException 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 5 with TargetNotMemberException

use of com.hazelcast.spi.exception.TargetNotMemberException in project hazelcast by hazelcast.

the class JetInstanceImpl method getJobsInt.

@Override
public Map<Address, GetJobIdsResult> getJobsInt(String onlyName, Long onlyJobId) {
    Map<Address, CompletableFuture<GetJobIdsResult>> futures = new HashMap<>();
    Address masterAddress = null;
    // if onlyName != null, only send the operation to master. Light jobs cannot have a name
    Collection<Member> targetMembers = onlyName == null ? nodeEngine.getClusterService().getMembers(DATA_MEMBER_SELECTOR) : singleton(nodeEngine.getClusterService().getMembers().iterator().next());
    for (Member member : targetMembers) {
        if (masterAddress == null) {
            masterAddress = member.getAddress();
        }
        GetJobIdsOperation operation = new GetJobIdsOperation(onlyName, onlyJobId);
        InvocationFuture<GetJobIdsResult> future = nodeEngine.getOperationService().createInvocationBuilder(JetServiceBackend.SERVICE_NAME, operation, member.getAddress()).invoke();
        futures.put(member.getAddress(), future);
    }
    Map<Address, GetJobIdsResult> res = new HashMap<>(futures.size());
    for (Entry<Address, CompletableFuture<GetJobIdsResult>> en : futures.entrySet()) {
        GetJobIdsResult result;
        try {
            result = en.getValue().get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            result = GetJobIdsResult.EMPTY;
        } catch (ExecutionException e) {
            // important. If we don't get response from the master, we report it to the user.
            if (!en.getKey().equals(masterAddress) && (e.getCause() instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException)) {
                result = GetJobIdsResult.EMPTY;
            } else {
                throw new RuntimeException("Error when getting job IDs: " + e, e);
            }
        }
        res.put(en.getKey(), result);
    }
    return res;
}
Also used : Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) GetJobIdsOperation(com.hazelcast.jet.impl.operation.GetJobIdsOperation) CompletableFuture(java.util.concurrent.CompletableFuture) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.cluster.Member) GetJobIdsResult(com.hazelcast.jet.impl.operation.GetJobIdsOperation.GetJobIdsResult) MemberLeftException(com.hazelcast.core.MemberLeftException)

Aggregations

TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)14 MemberLeftException (com.hazelcast.core.MemberLeftException)8 Member (com.hazelcast.cluster.Member)5 Address (com.hazelcast.cluster.Address)4 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)2 Transaction (com.hazelcast.transaction.impl.Transaction)2 TransactionManagerServiceImpl (com.hazelcast.transaction.impl.TransactionManagerServiceImpl)2 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)1 ClusterState (com.hazelcast.cluster.ClusterState)1 Config (com.hazelcast.config.Config)1 StaticMemberNodeContext (com.hazelcast.instance.StaticMemberNodeContext)1