Search in sources :

Example 1 with RemoteTransaction

use of org.infinispan.transaction.impl.RemoteTransaction in project infinispan by infinispan.

the class StateConsumerImpl method applyTransactions.

private void applyTransactions(Address sender, Collection<TransactionInfo> transactions, int topologyId) {
    log.debugf("Applying %d transactions for cache %s transferred from node %s", transactions.size(), cacheName, sender);
    if (isTransactional) {
        for (TransactionInfo transactionInfo : transactions) {
            GlobalTransaction gtx = transactionInfo.getGlobalTransaction();
            if (rpcManager.getAddress().equals(gtx.getAddress())) {
                // it is a transaction originated in this node. can happen with partition handling
                continue;
            }
            // Mark the global transaction as remote. Only used for logging, hashCode/equals ignore it.
            gtx.setRemote(true);
            CacheTransaction tx = transactionTable.getLocalTransaction(gtx);
            if (tx == null) {
                tx = transactionTable.getRemoteTransaction(gtx);
                if (tx == null) {
                    try {
                        // just in case, set the previous topology id to make the current topology id check for pending locks.
                        tx = transactionTable.getOrCreateRemoteTransaction(gtx, transactionInfo.getModifications(), topologyId - 1);
                        // Force this node to replay the given transaction data by making it think it is 1 behind
                        ((RemoteTransaction) tx).setLookedUpEntriesTopology(topologyId - 1);
                    } catch (Throwable t) {
                        if (log.isTraceEnabled())
                            log.tracef(t, "Failed to create remote transaction %s", gtx);
                    }
                }
            }
            if (tx != null) {
                transactionInfo.getLockedKeys().forEach(tx::addBackupLockForKey);
            }
        }
    }
}
Also used : RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) CacheTransaction(org.infinispan.transaction.xa.CacheTransaction)

Example 2 with RemoteTransaction

use of org.infinispan.transaction.impl.RemoteTransaction in project infinispan by infinispan.

the class TransactionSynchronizerInterceptor method visitCommand.

@Override
public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable {
    if (ctx.isOriginLocal() || !(command instanceof TransactionBoundaryCommand)) {
        return invokeNext(ctx, command);
    }
    CompletableFuture<Void> releaseFuture = new CompletableFuture<>();
    RemoteTransaction remoteTransaction = ((TxInvocationContext<RemoteTransaction>) ctx).getCacheTransaction();
    Object result = asyncInvokeNext(ctx, command, remoteTransaction.enterSynchronizationAsync(releaseFuture));
    return makeStage(result).andFinally(ctx, command, (rCtx, rCommand, rv, t) -> {
        log.tracef("Completing tx command release future for %s", remoteTransaction);
        releaseFuture.complete(null);
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) TransactionBoundaryCommand(org.infinispan.commands.tx.TransactionBoundaryCommand) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext)

Example 3 with RemoteTransaction

use of org.infinispan.transaction.impl.RemoteTransaction in project infinispan by infinispan.

the class TxCompletionNotificationCommand method invokeAsync.

@Override
public CompletionStage<?> invokeAsync(ComponentRegistry componentRegistry) throws Throwable {
    if (log.isTraceEnabled())
        log.tracef("Processing completed transaction %s", gtx);
    RemoteTransaction remoteTx = null;
    RecoveryManager recoveryManager = componentRegistry.getRecoveryManager().running();
    if (recoveryManager != null) {
        // recovery in use
        if (xid != null) {
            remoteTx = (RemoteTransaction) recoveryManager.removeRecoveryInformation(xid);
        } else {
            remoteTx = (RemoteTransaction) recoveryManager.removeRecoveryInformation(internalId);
        }
    }
    if (remoteTx == null && gtx != null) {
        TransactionTable txTable = componentRegistry.getTransactionTableRef().running();
        remoteTx = txTable.removeRemoteTransaction(gtx);
    }
    if (remoteTx == null)
        return CompletableFutures.completedNull();
    forwardCommandRemotely(componentRegistry.getStateTransferManager(), remoteTx);
    LockManager lockManager = componentRegistry.getLockManager().running();
    lockManager.unlockAll(remoteTx.getLockedKeys(), remoteTx.getGlobalTransaction());
    return CompletableFutures.completedNull();
}
Also used : RecoveryManager(org.infinispan.transaction.xa.recovery.RecoveryManager) LockManager(org.infinispan.util.concurrent.locks.LockManager) RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) TransactionTable(org.infinispan.transaction.impl.TransactionTable)

Example 4 with RemoteTransaction

use of org.infinispan.transaction.impl.RemoteTransaction in project infinispan by infinispan.

the class RecoveryAwareTransactionTable method removeRemoteTransaction.

public RemoteTransaction removeRemoteTransaction(XidImpl xid) {
    if (clustered) {
        Iterator<RemoteTransaction> it = getRemoteTransactions().iterator();
        while (it.hasNext()) {
            RemoteTransaction next = it.next();
            GlobalTransaction gtx = next.getGlobalTransaction();
            if (xid.equals(gtx.getXid())) {
                it.remove();
                recalculateMinTopologyIdIfNeeded(next);
                next.notifyOnTransactionFinished();
                return next;
            }
        }
    }
    return null;
}
Also used : RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction)

Example 5 with RemoteTransaction

use of org.infinispan.transaction.impl.RemoteTransaction in project infinispan by infinispan.

the class ForgetTest method forgetWithInternalId.

protected void forgetWithInternalId(int cacheIndex) {
    long internalId = -1;
    for (RemoteTransaction rt : tt(1).getRemoteTransactions()) {
        GlobalTransaction a = rt.getGlobalTransaction();
        if (a.getXid().equals(tx.getXid())) {
            internalId = a.getInternalId();
        }
    }
    if (internalId == -1)
        throw new IllegalStateException();
    log.tracef("About to forget... %s", internalId);
    recoveryOps(cacheIndex).forget(internalId);
    assertEquals(tt(0).getRemoteTxCount(), 0);
    assertEquals(tt(1).getRemoteTxCount(), 0);
}
Also used : RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction)

Aggregations

RemoteTransaction (org.infinispan.transaction.impl.RemoteTransaction)15 TransactionTable (org.infinispan.transaction.impl.TransactionTable)6 GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)6 LocalTransaction (org.infinispan.transaction.impl.LocalTransaction)3 InvocationContextFactory (org.infinispan.context.InvocationContextFactory)2 RemoteTxInvocationContext (org.infinispan.context.impl.RemoteTxInvocationContext)2 TxInvocationContext (org.infinispan.context.impl.TxInvocationContext)2 MagicKey (org.infinispan.distribution.MagicKey)2 RecoveryManager (org.infinispan.transaction.xa.recovery.RecoveryManager)2 Method (java.lang.reflect.Method)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 PrepareCommand (org.infinispan.commands.tx.PrepareCommand)1 RollbackCommand (org.infinispan.commands.tx.RollbackCommand)1 TransactionBoundaryCommand (org.infinispan.commands.tx.TransactionBoundaryCommand)1 LocalTxInvocationContext (org.infinispan.context.impl.LocalTxInvocationContext)1 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)1 EmbeddedTransactionManager (org.infinispan.transaction.tm.EmbeddedTransactionManager)1 CacheTransaction (org.infinispan.transaction.xa.CacheTransaction)1 LockManager (org.infinispan.util.concurrent.locks.LockManager)1 Test (org.testng.annotations.Test)1