Search in sources :

Example 11 with MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class JobExecutionService method onMemberRemoved.

/**
 * Cancels executions that contain the leaving address as the coordinator or a
 * job participant
 */
void onMemberRemoved(Member member) {
    Address address = member.getAddress();
    executionContexts.values().stream().filter(exeCtx -> exeCtx.coordinator() != null && (exeCtx.coordinator().equals(address) || exeCtx.hasParticipant(address))).forEach(exeCtx -> {
        LoggingUtil.logFine(logger, "Completing %s locally. Reason: Member %s left the cluster", exeCtx.jobNameAndExecutionId(), address);
        terminateExecution0(exeCtx, null, new MemberLeftException(member));
    });
}
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) Address(com.hazelcast.cluster.Address) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 12 with MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class Invocation method initInvocationTarget.

/**
 * Initializes the invocation target.
 *
 * @throws Exception if the initialization was a failure
 */
final void initInvocationTarget() throws Exception {
    Member previousTargetMember = targetMember;
    T target = getInvocationTarget();
    if (target == null) {
        throw newTargetNullException();
    }
    targetMember = toTargetMember(target);
    if (targetMember != null) {
        targetAddress = targetMember.getAddress();
    } else {
        targetAddress = toTargetAddress(target);
    }
    memberListVersion = context.clusterService.getMemberListVersion();
    if (targetMember == null) {
        if (previousTargetMember != null) {
            // then it means a member left.
            throw new MemberLeftException(previousTargetMember);
        }
        if (!(isJoinOperation(op) || isWanReplicationOperation(op))) {
            throw new TargetNotMemberException(target, op.getPartitionId(), op.getClass().getName(), op.getServiceName());
        }
    }
    if (op instanceof TargetAware) {
        ((TargetAware) op).setTarget(targetAddress);
    }
}
Also used : TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TIMEOUT(com.hazelcast.spi.impl.operationservice.impl.Invocation.HeartbeatTimeout.TIMEOUT) HEARTBEAT_TIMEOUT(com.hazelcast.spi.impl.operationservice.impl.InvocationConstant.HEARTBEAT_TIMEOUT) CALL_TIMEOUT(com.hazelcast.spi.impl.operationservice.impl.InvocationConstant.CALL_TIMEOUT) FINEST(java.util.logging.Level.FINEST) TargetAware(com.hazelcast.spi.impl.operationservice.TargetAware) Member(com.hazelcast.cluster.Member) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 13 with MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class XAResourceImpl method recover.

@Override
public Xid[] recover(int flag) throws XAException {
    NodeEngine nodeEngine = getNodeEngine();
    XAService xaService = getService();
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    Collection<Member> memberList = clusterService.getMembers();
    List<Future<SerializableList>> futureList = new ArrayList<Future<SerializableList>>();
    for (Member member : memberList) {
        if (member.localMember()) {
            continue;
        }
        CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation();
        Address address = member.getAddress();
        InternalCompletableFuture<SerializableList> future = operationService.invokeOnTarget(SERVICE_NAME, op, address);
        futureList.add(future);
    }
    Set<SerializableXID> xids = new HashSet<SerializableXID>(xaService.getPreparedXids());
    for (Future<SerializableList> future : futureList) {
        try {
            SerializableList xidSet = future.get();
            for (Data xidData : xidSet) {
                SerializableXID xid = nodeEngine.toObject(xidData);
                xids.add(xid);
            }
        } catch (InterruptedException e) {
            currentThread().interrupt();
            throw new XAException(XAException.XAER_RMERR);
        } catch (MemberLeftException e) {
            logger.warning("Member left while recovering", e);
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof HazelcastInstanceNotActiveException || cause instanceof TargetNotMemberException) {
                logger.warning("Member left while recovering", e);
            } else {
                throw new XAException(XAException.XAER_RMERR);
            }
        }
    }
    return xids.toArray(new SerializableXID[0]);
}
Also used : Address(com.hazelcast.cluster.Address) SerializableList(com.hazelcast.spi.impl.SerializableList) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NodeEngine(com.hazelcast.spi.impl.NodeEngine) CollectRemoteTransactionsOperation(com.hazelcast.transaction.impl.xa.operations.CollectRemoteTransactionsOperation) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.cluster.Member) HashSet(java.util.HashSet) MemberLeftException(com.hazelcast.core.MemberLeftException) XAException(javax.transaction.xa.XAException) Data(com.hazelcast.internal.serialization.Data) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ClusterService(com.hazelcast.internal.cluster.ClusterService) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 14 with MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class XACollectTransactionsMessageTask method reduce.

@Override
protected Object reduce(Map<Member, Object> map) throws Throwable {
    List<Data> list = new ArrayList<>();
    for (Object o : map.values()) {
        if (o instanceof Throwable) {
            if (o instanceof MemberLeftException) {
                continue;
            }
            throw (Throwable) o;
        }
        SerializableList xidSet = (SerializableList) o;
        list.addAll(xidSet.getCollection());
    }
    List<Xid> xidList = new ArrayList<>(list.size());
    list.forEach(xidData -> xidList.add(serializationService.toObject(xidData)));
    return xidList;
}
Also used : Xid(javax.transaction.xa.Xid) SerializableList(com.hazelcast.spi.impl.SerializableList) ArrayList(java.util.ArrayList) Data(com.hazelcast.internal.serialization.Data) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 15 with MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class PromoteLiteMemberTest method promotion_shouldFail_whenMasterLeaves_duringPromotion.

@Test
public void promotion_shouldFail_whenMasterLeaves_duringPromotion() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz1 = factory.newHazelcastInstance(new Config());
    HazelcastInstance hz2 = factory.newHazelcastInstance(new Config());
    HazelcastInstance hz3 = factory.newHazelcastInstance(new Config().setLiteMember(true));
    assertClusterSizeEventually(3, hz2);
    dropOperationsBetween(hz3, hz1, F_ID, singletonList(PROMOTE_LITE_MEMBER));
    Cluster cluster = hz3.getCluster();
    Future<Exception> future = spawn(() -> {
        try {
            cluster.promoteLocalLiteMember();
        } catch (Exception e) {
            return e;
        }
        return null;
    });
    assertPromotionInvocationStarted(hz3);
    hz1.getLifecycleService().terminate();
    assertClusterSizeEventually(2, hz2, hz3);
    Exception exception = future.get();
    // MemberLeftException is wrapped by HazelcastException
    assertInstanceOf(MemberLeftException.class, exception.getCause());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) Cluster(com.hazelcast.cluster.Cluster) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) CompletionException(java.util.concurrent.CompletionException) ExpectedException(org.junit.rules.ExpectedException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MemberLeftException (com.hazelcast.core.MemberLeftException)17 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)8 Member (com.hazelcast.cluster.Member)4 ExecutionException (java.util.concurrent.ExecutionException)4 Test (org.junit.Test)4 Address (com.hazelcast.cluster.Address)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 ArrayList (java.util.ArrayList)3 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)2 Config (com.hazelcast.config.Config)2 Member (com.hazelcast.core.Member)2 SimpleMemberImpl (com.hazelcast.instance.SimpleMemberImpl)2 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)2 Data (com.hazelcast.internal.serialization.Data)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 SerializableList (com.hazelcast.spi.impl.SerializableList)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 AssertTask (com.hazelcast.test.AssertTask)2