Search in sources :

Example 16 with HazelcastInstanceNotActiveException

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

the class AbstractSerializationService method readObject.

@Override
public final <T> T readObject(final ObjectDataInput in) {
    try {
        final int typeId = in.readInt();
        final SerializerAdapter serializer = serializerFor(typeId);
        if (serializer == null) {
            if (active) {
                throw newHazelcastSerializationException(typeId);
            }
            throw new HazelcastInstanceNotActiveException();
        }
        Object obj = serializer.read(in);
        if (managedContext != null) {
            obj = managedContext.initialize(obj);
        }
        return (T) obj;
    } catch (Throwable e) {
        throw handleException(e);
    }
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) SerializationUtil.createSerializerAdapter(com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)

Example 17 with HazelcastInstanceNotActiveException

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

the class MapTransactionTest method testTxnOwnerDies.

@Test
@Category(NightlyTest.class)
public void testTxnOwnerDies() throws TransactionException, InterruptedException {
    Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final HazelcastInstance h3 = factory.newHazelcastInstance(config);
    final int size = 50;
    final AtomicBoolean result = new AtomicBoolean(false);
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {

                    public Boolean execute(TransactionalTaskContext context) throws TransactionException {
                        final TransactionalMap<Object, Object> txMap = context.getMap("default");
                        for (int i = 0; i < size; i++) {
                            txMap.put(i, i);
                            sleepSeconds(1);
                        }
                        return true;
                    }
                });
                result.set(b);
            } catch (HazelcastInstanceNotActiveException ignored) {
            } catch (TransactionException ignored) {
            }
        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
    sleepSeconds(1);
    h1.shutdown();
    // wait till thread finishes.
    thread.join(30 * 1000);
    assertFalse(result.get());
    final IMap map2 = h2.getMap("default");
    for (int i = 0; i < size; i++) {
        assertNull(map2.get(i));
    }
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Category(org.junit.experimental.categories.Category) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with HazelcastInstanceNotActiveException

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

the class ClientEndpointImpl method destroy.

public void destroy() throws LoginException {
    clearAllListeners();
    LoginContext lc = loginContext;
    if (lc != null) {
        lc.logout();
    }
    for (TransactionContext context : transactionContextMap.values()) {
        if (context instanceof XATransactionContextImpl) {
            continue;
        }
        try {
            context.rollbackTransaction();
        } catch (HazelcastInstanceNotActiveException e) {
            getLogger().finest(e);
        } catch (Exception e) {
            getLogger().warning(e);
        }
    }
    authenticated = false;
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) LoginContext(javax.security.auth.login.LoginContext) TransactionContext(com.hazelcast.transaction.TransactionContext) XATransactionContextImpl(com.hazelcast.transaction.impl.xa.XATransactionContextImpl) LoginException(javax.security.auth.login.LoginException) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TransactionException(com.hazelcast.transaction.TransactionException)

Example 19 with HazelcastInstanceNotActiveException

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

the class OperationRunnerImpl method checkNodeState.

private void checkNodeState(Operation op) {
    NodeState state = node.getState();
    if (state == NodeState.ACTIVE) {
        return;
    }
    Address localAddress = node.getThisAddress();
    if (state == NodeState.SHUT_DOWN) {
        throw new HazelcastInstanceNotActiveException("Member " + localAddress + " is shut down! Operation: " + op);
    }
    if (op instanceof AllowedDuringPassiveState) {
        return;
    }
    // Cluster is in passive state. There is no need to retry.
    if (nodeEngine.getClusterService().getClusterState() == ClusterState.PASSIVE) {
        throw new IllegalStateException("Cluster is in " + ClusterState.PASSIVE + " state! Operation: " + op);
    }
    // Operation will fail since node is shutting down or cluster is passive.
    if (op.getPartitionId() < 0) {
        throw new HazelcastInstanceNotActiveException("Member " + localAddress + " is currently passive! Operation: " + op);
    }
    // Since operation has a partition id, it must be retried on another node.
    throw new RetryableHazelcastException("Member " + localAddress + " is currently shutting down! Operation: " + op);
}
Also used : AllowedDuringPassiveState(com.hazelcast.spi.impl.AllowedDuringPassiveState) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) NodeState(com.hazelcast.instance.NodeState) Address(com.hazelcast.nio.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.OperationAccessor.setCallerAddress) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException)

Example 20 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException 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);
    }
    HashSet<SerializableXID> xids = new HashSet<SerializableXID>();
    xids.addAll(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) {
            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[xids.size()]);
}
Also used : Address(com.hazelcast.nio.Address) SerializableList(com.hazelcast.spi.impl.SerializableList) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NodeEngine(com.hazelcast.spi.NodeEngine) CollectRemoteTransactionsOperation(com.hazelcast.transaction.impl.xa.operations.CollectRemoteTransactionsOperation) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet) MemberLeftException(com.hazelcast.core.MemberLeftException) XAException(javax.transaction.xa.XAException) Data(com.hazelcast.nio.serialization.Data) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ClusterService(com.hazelcast.internal.cluster.ClusterService) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService)

Aggregations

HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)34 HazelcastException (com.hazelcast.core.HazelcastException)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)8 Test (org.junit.Test)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)7 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)7 OException (com.orientechnologies.common.exception.OException)7 OIOException (com.orientechnologies.common.io.OIOException)7 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)7 TransactionException (com.hazelcast.transaction.TransactionException)6 OCallable (com.orientechnologies.common.util.OCallable)6 ExecutionException (java.util.concurrent.ExecutionException)6 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)5 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)5 AssertTask (com.hazelcast.test.AssertTask)5 Callable (java.util.concurrent.Callable)5 TransactionOptions (com.hazelcast.transaction.TransactionOptions)4