Search in sources :

Example 1 with XidImpl

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

the class RecoveryManagerImpl method removeRecoveryInformation.

@Override
public RecoveryAwareTransaction removeRecoveryInformation(Long internalId) {
    XidImpl remoteTransactionXid = recoveryAwareTxTable().getRemoteTransactionXid(internalId);
    if (remoteTransactionXid != null) {
        return removeRecoveryInformation(remoteTransactionXid);
    } else {
        for (RecoveryAwareRemoteTransaction raRemoteTx : inDoubtTransactions.values()) {
            GlobalTransaction globalTransaction = raRemoteTx.getGlobalTransaction();
            if (internalId.equals(globalTransaction.getInternalId())) {
                XidImpl xid = globalTransaction.getXid();
                log.tracef("Found transaction xid %s that maps internal id %s", xid, internalId);
                removeRecoveryInformation(xid);
                return raRemoteTx;
            }
        }
    }
    log.tracef("Could not find tx to map to internal id %s", internalId);
    return null;
}
Also used : XidImpl(org.infinispan.commons.tx.XidImpl) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction)

Example 2 with XidImpl

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

the class RecoveryManagerImpl method isTransactionPrepared.

@Override
public boolean isTransactionPrepared(GlobalTransaction globalTx) {
    XidImpl xid = globalTx.getXid();
    RecoveryAwareRemoteTransaction remoteTransaction = (RecoveryAwareRemoteTransaction) recoveryAwareTxTable().getRemoteTransaction(globalTx);
    boolean remotePrepared = remoteTransaction != null && remoteTransaction.isPrepared();
    boolean result = // if it is in doubt must be prepared
    inDoubtTransactions.get(new RecoveryInfoKey(xid, cacheName)) != null || recoveryAwareTxTable().getLocalPreparedXids().contains(xid) || remotePrepared;
    if (log.isTraceEnabled())
        log.tracef("Is tx %s prepared? %s", xid, result);
    return result;
}
Also used : XidImpl(org.infinispan.commons.tx.XidImpl)

Example 3 with XidImpl

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

the class RecoveryManagerImpl method getInDoubtTransactionInfoFromCluster.

@Override
public Set<InDoubtTxInfo> getInDoubtTransactionInfoFromCluster() {
    Map<XidImpl, InDoubtTxInfo> result = new HashMap<>();
    if (rpcManager != null) {
        GetInDoubtTxInfoCommand inDoubtTxInfoCommand = commandFactory.buildGetInDoubtTxInfoCommand();
        CompletionStage<Map<Address, Response>> completionStage = rpcManager.invokeCommandOnAll(inDoubtTxInfoCommand, MapResponseCollector.ignoreLeavers(), rpcManager.getSyncRpcOptions());
        Map<Address, Response> addressResponseMap = rpcManager.blocking(completionStage);
        for (Map.Entry<Address, Response> re : addressResponseMap.entrySet()) {
            Response r = re.getValue();
            if (!isSuccessful(r)) {
                throw new CacheException("Could not fetch in doubt transactions: " + r);
            }
            // noinspection unchecked
            Set<InDoubtTxInfo> infoInDoubtSet = ((SuccessfulResponse<Set<InDoubtTxInfo>>) r).getResponseValue();
            for (InDoubtTxInfo infoInDoubt : infoInDoubtSet) {
                InDoubtTxInfo inDoubtTxInfo = result.get(infoInDoubt.getXid());
                if (inDoubtTxInfo == null) {
                    inDoubtTxInfo = infoInDoubt;
                    result.put(infoInDoubt.getXid(), inDoubtTxInfo);
                } else {
                    inDoubtTxInfo.setStatus(infoInDoubt.getStatus());
                }
                inDoubtTxInfo.addOwner(re.getKey());
            }
        }
    }
    Set<InDoubtTxInfo> onThisNode = getInDoubtTransactionInfo();
    Iterator<InDoubtTxInfo> iterator = onThisNode.iterator();
    while (iterator.hasNext()) {
        InDoubtTxInfo info = iterator.next();
        InDoubtTxInfo inDoubtTxInfo = result.get(info.getXid());
        if (inDoubtTxInfo != null) {
            inDoubtTxInfo.setLocal(true);
            iterator.remove();
        } else {
            info.setLocal(true);
        }
    }
    HashSet<InDoubtTxInfo> value = new HashSet<>(result.values());
    value.addAll(onThisNode);
    return value;
}
Also used : SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Address(org.infinispan.remoting.transport.Address) HashMap(java.util.HashMap) CacheException(org.infinispan.commons.CacheException) XidImpl(org.infinispan.commons.tx.XidImpl) Response(org.infinispan.remoting.responses.Response) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) GetInDoubtTxInfoCommand(org.infinispan.commands.remote.recovery.GetInDoubtTxInfoCommand) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with XidImpl

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

the class RecoveryAdminOperations method lookupRecoveryInfo.

private InDoubtTxInfo lookupRecoveryInfo(int formatId, byte[] globalTxId, byte[] branchQualifier) {
    Set<InDoubtTxInfo> info = getRecoveryInfoFromCluster();
    XidImpl xid = XidImpl.create(formatId, globalTxId, branchQualifier);
    for (InDoubtTxInfo i : info) {
        if (i.getXid().equals(xid)) {
            log.tracef("Found matching recovery info: %s", i);
            return i;
        }
    }
    return null;
}
Also used : XidImpl(org.infinispan.commons.tx.XidImpl)

Example 5 with XidImpl

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

the class ForgetTest method forgetWithXid.

private void forgetWithXid(int nodeIndex) {
    XidImpl xid = tx.getXid();
    recoveryOps(nodeIndex).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