Search in sources :

Example 1 with Transaction

use of com.hazelcast.transaction.impl.Transaction 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 Transaction

use of com.hazelcast.transaction.impl.Transaction 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 Transaction

use of com.hazelcast.transaction.impl.Transaction in project hazelcast by hazelcast.

the class XAResourceImpl method commit.

@Override
public void commit(Xid xid, boolean onePhase) throws XAException {
    List<TransactionContext> contexts = xidContextMap.remove(xid);
    if (contexts == null && onePhase) {
        throw new XAException("There is no TransactionContexts for the given xid: " + xid);
    }
    if (contexts == null) {
        finalizeTransactionRemotely(xid, true);
        return;
    }
    for (TransactionContext context : contexts) {
        Transaction transaction = getTransaction(context);
        if (onePhase) {
            transaction.prepare();
        }
        transaction.commit();
    }
    clearRemoteTransactions(xid);
}
Also used : XAException(javax.transaction.xa.XAException) Transaction(com.hazelcast.transaction.impl.Transaction) TransactionContext(com.hazelcast.transaction.TransactionContext)

Example 4 with Transaction

use of com.hazelcast.transaction.impl.Transaction in project hazelcast by hazelcast.

the class XATransactionRollbackMessageTask method call.

@Override
protected Object call() throws Exception {
    UUID transactionId = parameters;
    TransactionContext transactionContext = endpoint.getTransactionContext(transactionId);
    if (transactionContext == null) {
        throw new TransactionException("No transaction context with given transactionId: " + transactionId);
    }
    Transaction transaction = TransactionAccessor.getTransaction(transactionContext);
    transaction.rollback();
    endpoint.removeTransactionContext(transactionId);
    return null;
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) Transaction(com.hazelcast.transaction.impl.Transaction) TransactionContext(com.hazelcast.transaction.TransactionContext) UUID(java.util.UUID)

Example 5 with Transaction

use of com.hazelcast.transaction.impl.Transaction in project hazelcast by hazelcast.

the class XATransactionPrepareMessageTask method call.

@Override
protected Object call() throws Exception {
    UUID transactionId = parameters;
    TransactionContext transactionContext = endpoint.getTransactionContext(transactionId);
    if (transactionContext == null) {
        throw new TransactionException("No transaction context with given transactionId: " + transactionId);
    }
    Transaction transaction = TransactionAccessor.getTransaction(transactionContext);
    transaction.prepare();
    return null;
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) Transaction(com.hazelcast.transaction.impl.Transaction) TransactionContext(com.hazelcast.transaction.TransactionContext) UUID(java.util.UUID)

Aggregations

Transaction (com.hazelcast.transaction.impl.Transaction)10 TransactionContext (com.hazelcast.transaction.TransactionContext)5 UUID (java.util.UUID)5 TransactionException (com.hazelcast.transaction.TransactionException)4 TransactionManagerServiceImpl (com.hazelcast.transaction.impl.TransactionManagerServiceImpl)4 TransactionLogRecord (com.hazelcast.transaction.impl.TransactionLogRecord)3 XAException (javax.transaction.xa.XAException)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 MemberLeftException (com.hazelcast.core.MemberLeftException)2 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 SlowTest (com.hazelcast.test.annotation.SlowTest)2 TransactionOptions (com.hazelcast.transaction.TransactionOptions)2 Test (org.junit.Test)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ClusterState (com.hazelcast.cluster.ClusterState)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 IPartitionService (com.hazelcast.internal.partition.IPartitionService)1