Search in sources :

Example 11 with TargetNotMemberException

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

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

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

the class TopologyChangeTest method when_coordinatorLeaves_AutoScalingOff_then_jobFailsOrSuspends.

private void when_coordinatorLeaves_AutoScalingOff_then_jobFailsOrSuspends(boolean snapshotted) throws Throwable {
    // Given
    HazelcastInstance client = createHazelcastClient();
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, nodeCount)));
    JobConfig config = new JobConfig();
    config.setAutoScaling(false);
    config.setProcessingGuarantee(snapshotted ? EXACTLY_ONCE : NONE);
    // When
    Job job = client.getJet().newJob(dag, config);
    NoOutputSourceP.executionStarted.await();
    instances[0].getLifecycleService().terminate();
    NoOutputSourceP.proceedLatch.countDown();
    assertTrueEventually(() -> {
        JobStatus status = null;
        while (status == null) {
            try {
                status = job.getStatus();
            } catch (TargetNotMemberException ignored) {
            }
        }
        assertEquals(snapshotted ? SUSPENDED : FAILED, status);
    }, 10);
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 14 with TargetNotMemberException

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

the class OperationServiceImpl_invokeOnTargetTest method whenNonExistingTarget.

@Test
public void whenNonExistingTarget() {
    Address remoteAddress = getAddress(remote);
    remote.shutdown();
    // ensure local instance observes remote shutdown
    assertClusterSizeEventually(1, local);
    String expected = "foobar";
    DummyOperation operation = new DummyOperation(expected) {

        @Override
        public ExceptionAction onInvocationException(Throwable throwable) {
            // when TargetNotMemberException is get, invocation may fail with MemberLeftException too.
            if (throwable instanceof TargetNotMemberException) {
                return ExceptionAction.THROW_EXCEPTION;
            }
            return super.onInvocationException(throwable);
        }
    };
    InternalCompletableFuture<String> invocation = operationService.invokeOnTarget(null, operation, remoteAddress);
    try {
        invocation.joinInternal();
        fail();
    } catch (TargetNotMemberException e) {
    }
}
Also used : TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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