Search in sources :

Example 16 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class RecoveryManagerImpl method registerInDoubtTransaction.

public void registerInDoubtTransaction(RecoveryAwareRemoteTransaction remoteTransaction) {
    XidImpl xid = remoteTransaction.getGlobalTransaction().getXid();
    RecoveryAwareTransaction previous = inDoubtTransactions.put(new RecoveryInfoKey(xid, cacheName), remoteTransaction);
    if (previous != null) {
        log.preparedTxAlreadyExists(previous, remoteTransaction);
        throw new IllegalStateException("Are there two different transactions having same Xid in the cluster?");
    }
}
Also used : XidImpl(org.infinispan.commons.tx.XidImpl)

Example 17 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class RecoveryManagerImpl method getPreparedTransactionsFromCluster.

@Override
public RecoveryIterator getPreparedTransactionsFromCluster() {
    PreparedTxIterator iterator = new PreparedTxIterator();
    // 1. get local transactions first
    // add the locally prepared transactions. The list of prepared transactions (even if they are not in-doubt)
    // is mandated by the recovery process according to the JTA spec: "The transaction manager calls this [i.e. recover]
    // method during recovery to obtain the list of transaction branches that are currently in prepared or heuristically
    // completed states."
    iterator.add((recoveryAwareTxTable()).getLocalPreparedXids());
    // 2. now also add the in-doubt transactions.
    iterator.add(getInDoubtTransactions());
    // 3. then the remote ones
    if (notOnlyMeInTheCluster() && broadcastForPreparedTx) {
        boolean success = true;
        Map<Address, Response> responses = getAllPreparedTxFromCluster();
        for (Map.Entry<Address, Response> rEntry : responses.entrySet()) {
            Response thisResponse = rEntry.getValue();
            if (isSuccessful(thisResponse)) {
                // noinspection unchecked
                List<XidImpl> responseValue = ((SuccessfulResponse<List<XidImpl>>) thisResponse).getResponseValue();
                if (log.isTraceEnabled()) {
                    log.tracef("Received Xid lists %s from node %s", responseValue, rEntry.getKey());
                }
                iterator.add(responseValue);
            } else {
                log.missingListPreparedTransactions(rEntry.getKey(), rEntry.getValue());
                success = false;
            }
        }
        // this makes sure that the broadcast only happens once!
        this.broadcastForPreparedTx = !success;
        if (!broadcastForPreparedTx)
            log.debug("Finished broadcasting for remote prepared transactions. Returning only local values from now on.");
    }
    return iterator;
}
Also used : Response(org.infinispan.remoting.responses.Response) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Address(org.infinispan.remoting.transport.Address) XidImpl(org.infinispan.commons.tx.XidImpl) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 18 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class XaTransactionTable method commit.

public CompletionStage<Void> commit(XidImpl xid, boolean isOnePhase) {
    LocalXaTransaction localTransaction = getLocalTransaction(xid);
    if (localTransaction == null) {
        return CompletableFutures.completedExceptionFuture(new XAException(XAException.XAER_NOTA));
    }
    CompletionStage<Boolean> commitStage;
    CompletionStage<Integer> prepareStage;
    // inconsistent state.
    if (isOnePhase && !CompletionStages.isCompletedSuccessfully(prepareStage = txCoordinator.prepare(localTransaction))) {
        commitStage = prepareStage.thenCompose(ignore -> txCoordinator.commit(localTransaction, false));
    } else {
        commitStage = txCoordinator.commit(localTransaction, false);
    }
    if (CompletionStages.isCompletedSuccessfully(commitStage)) {
        boolean committedInOnePhase = CompletionStages.join(commitStage);
        forgetSuccessfullyCompletedTransaction(localTransaction, committedInOnePhase);
        return CompletableFutures.completedNull();
    }
    return commitStage.thenApply(committedInOnePhase -> {
        forgetSuccessfullyCompletedTransaction(localTransaction, committedInOnePhase);
        return null;
    });
}
Also used : Transaction(javax.transaction.Transaction) CacheException(org.infinispan.commons.CacheException) ComponentName(org.infinispan.factories.annotations.ComponentName) XidImpl(org.infinispan.commons.tx.XidImpl) LogFactory(org.infinispan.util.logging.LogFactory) RecoveryManager(org.infinispan.transaction.xa.recovery.RecoveryManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletionException(java.util.concurrent.CompletionException) KnownComponentNames(org.infinispan.factories.KnownComponentNames) CompletionStages(org.infinispan.util.concurrent.CompletionStages) Inject(org.infinispan.factories.annotations.Inject) ConcurrentMap(java.util.concurrent.ConcurrentMap) Start(org.infinispan.factories.annotations.Start) CompletionStage(java.util.concurrent.CompletionStage) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Log(org.infinispan.util.logging.Log) XAException(javax.transaction.xa.XAException) TransactionTable(org.infinispan.transaction.impl.TransactionTable) XAException(javax.transaction.xa.XAException)

Example 19 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class XaTransactionTable method forgetSuccessfullyCompletedTransaction.

private void forgetSuccessfullyCompletedTransaction(LocalXaTransaction localTransaction, boolean committedInOnePhase) {
    final GlobalTransaction gtx = localTransaction.getGlobalTransaction();
    XidImpl xid = localTransaction.getXid();
    if (isRecoveryEnabled()) {
        recoveryManager.removeRecoveryInformation(localTransaction.getRemoteLocksAcquired(), xid, gtx, partitionHandlingManager.isTransactionPartiallyCommitted(gtx));
        removeLocalTransaction(localTransaction);
    } else {
        releaseLocksForCompletedTransaction(localTransaction, committedInOnePhase);
    }
}
Also used : XidImpl(org.infinispan.commons.tx.XidImpl)

Example 20 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class ForgetTest method testInternalIdOnSameNode.

public void testInternalIdOnSameNode() {
    XidImpl xid = tx.getXid();
    recoveryOps(0).forget(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
    // make sure tx has been removed
    assertEquals(tt(1).getRemoteTxCount(), 0);
}
Also used : XidImpl(org.infinispan.commons.tx.XidImpl)

Aggregations

XidImpl (org.infinispan.commons.tx.XidImpl)25 HashSet (java.util.HashSet)5 Map (java.util.Map)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 XAException (javax.transaction.xa.XAException)3 EmbeddedTransaction (org.infinispan.transaction.tm.EmbeddedTransaction)3 HashMap (java.util.HashMap)2 CacheException (org.infinispan.commons.CacheException)2 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 Response (org.infinispan.remoting.responses.Response)2 SuccessfulResponse (org.infinispan.remoting.responses.SuccessfulResponse)2 Address (org.infinispan.remoting.transport.Address)2 HotRodClient (org.infinispan.server.hotrod.test.HotRodClient)2 TxResponse (org.infinispan.server.hotrod.test.TxResponse)2 GlobalTxTable (org.infinispan.server.hotrod.tx.table.GlobalTxTable)2 GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)2 RecoveryManager (org.infinispan.transaction.xa.recovery.RecoveryManager)2 ByteBuf (io.netty.buffer.ByteBuf)1 CompletionException (java.util.concurrent.CompletionException)1