Search in sources :

Example 1 with RemoteTxInvocationContext

use of org.infinispan.context.impl.RemoteTxInvocationContext in project infinispan by infinispan.

the class AbstractTransactionBoundaryCommand method invokeAsync.

@Override
public CompletionStage<?> invokeAsync(ComponentRegistry registry) throws Throwable {
    globalTx.setRemote(true);
    TransactionTable txTable = registry.getTransactionTableRef().running();
    RemoteTransaction transaction = txTable.getRemoteTransaction(globalTx);
    if (transaction == null) {
        if (log.isTraceEnabled())
            log.tracef("Did not find a RemoteTransaction for %s", globalTx);
        return CompletableFuture.completedFuture(invalidRemoteTxReturnValue(txTable));
    }
    visitRemoteTransaction(transaction);
    InvocationContextFactory icf = registry.getInvocationContextFactory().running();
    RemoteTxInvocationContext ctx = icf.createRemoteTxInvocationContext(transaction, getOrigin());
    if (log.isTraceEnabled())
        log.tracef("About to execute tx command %s", this);
    return registry.getInterceptorChain().running().invokeAsync(ctx, this);
}
Also used : RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext) TransactionTable(org.infinispan.transaction.impl.TransactionTable) InvocationContextFactory(org.infinispan.context.InvocationContextFactory)

Example 2 with RemoteTxInvocationContext

use of org.infinispan.context.impl.RemoteTxInvocationContext in project infinispan by infinispan.

the class PrepareCommand method invokeAsync.

@Override
public CompletionStage<?> invokeAsync(ComponentRegistry registry) throws Throwable {
    markTransactionAsRemote(true);
    RemoteTxInvocationContext ctx = createContext(registry);
    if (ctx == null) {
        return CompletableFutures.completedNull();
    }
    if (log.isTraceEnabled())
        log.tracef("Invoking remotely originated prepare: %s with invocation context: %s", this, ctx);
    CacheNotifier notifier = registry.getCacheNotifier().running();
    CompletionStage<Void> stage = notifier.notifyTransactionRegistered(ctx.getGlobalTransaction(), false);
    AsyncInterceptorChain invoker = registry.getInterceptorChain().running();
    for (VisitableCommand nested : getModifications()) nested.init(registry);
    if (CompletionStages.isCompletedSuccessfully(stage)) {
        return invoker.invokeAsync(ctx, this);
    } else {
        return stage.thenCompose(v -> invoker.invokeAsync(ctx, this));
    }
}
Also used : VisitableCommand(org.infinispan.commands.VisitableCommand) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain)

Example 3 with RemoteTxInvocationContext

use of org.infinispan.context.impl.RemoteTxInvocationContext in project infinispan by infinispan.

the class LockControlCommand method invokeAsync.

@Override
public CompletionStage<?> invokeAsync(ComponentRegistry registry) throws Throwable {
    globalTx.setRemote(true);
    RemoteTxInvocationContext ctx = createContext(registry);
    if (ctx == null) {
        return CompletableFutures.completedNull();
    }
    return registry.getInterceptorChain().running().invokeAsync(ctx, this);
}
Also used : RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext)

Example 4 with RemoteTxInvocationContext

use of org.infinispan.context.impl.RemoteTxInvocationContext in project infinispan by infinispan.

the class TxInterceptor method verifyRemoteTransaction.

private Object verifyRemoteTransaction(RemoteTxInvocationContext ctx, AbstractTransactionBoundaryCommand command, Object rv, Throwable throwable) throws Throwable {
    final GlobalTransaction globalTransaction = command.getGlobalTransaction();
    // It is also possible that the LCC timed out on the originator's end and this node has processed
    // a TxCompletionNotification.  So we need to check the presence of the remote transaction to
    // see if we need to clean up any acquired locks on our end.
    boolean alreadyCompleted = txTable.isTransactionCompleted(globalTransaction) || !txTable.containRemoteTx(globalTransaction);
    if (log.isTraceEnabled()) {
        log.tracef("Verifying transaction: alreadyCompleted=%s", alreadyCompleted);
    }
    if (alreadyCompleted) {
        if (log.isTraceEnabled()) {
            log.tracef("Rolling back remote transaction %s because it was already completed", globalTransaction);
        }
        // The rollback command only marks the transaction as completed in invokeAsync()
        txTable.markTransactionCompleted(globalTransaction, false);
        RollbackCommand rollback = commandsFactory.buildRollbackCommand(command.getGlobalTransaction());
        return invokeNextAndFinally(ctx, rollback, (rCtx, rCommand, rv1, throwable1) -> {
            // noinspection unchecked
            RemoteTransaction remoteTx = ((TxInvocationContext<RemoteTransaction>) rCtx).getCacheTransaction();
            remoteTx.markForRollback(true);
            txTable.removeRemoteTransaction(globalTransaction);
        });
    }
    return valueOrException(rv, throwable);
}
Also used : RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) RollbackCommand(org.infinispan.commands.tx.RollbackCommand)

Example 5 with RemoteTxInvocationContext

use of org.infinispan.context.impl.RemoteTxInvocationContext in project infinispan by infinispan.

the class TxInterceptor method visitCommitCommand.

@Override
public Object visitCommitCommand(@SuppressWarnings("rawtypes") TxInvocationContext ctx, CommitCommand command) throws Throwable {
    // TODO The local origin check is needed for CommitFailsTest, but it doesn't appear correct to roll back an in-doubt tx
    if (!ctx.isOriginLocal()) {
        GlobalTransaction gtx = ctx.getGlobalTransaction();
        if (txTable.isTransactionCompleted(gtx)) {
            if (log.isTraceEnabled())
                log.tracef("Transaction %s already completed, skipping commit", gtx);
            return null;
        }
        InvocationStage replayStage = replayRemoteTransactionIfNeeded((RemoteTxInvocationContext) ctx, command.getTopologyId());
        if (replayStage != null) {
            return replayStage.andHandle(ctx, command, (rCtx, rCommand, rv, t) -> finishCommit((TxInvocationContext<?>) rCtx, rCommand));
        } else {
            return finishCommit(ctx, command);
        }
    }
    return finishCommit(ctx, command);
}
Also used : InvocationStage(org.infinispan.interceptors.InvocationStage) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction)

Aggregations

RemoteTxInvocationContext (org.infinispan.context.impl.RemoteTxInvocationContext)6 LocalTxInvocationContext (org.infinispan.context.impl.LocalTxInvocationContext)2 TxInvocationContext (org.infinispan.context.impl.TxInvocationContext)2 RemoteTransaction (org.infinispan.transaction.impl.RemoteTransaction)2 GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)2 VisitableCommand (org.infinispan.commands.VisitableCommand)1 RollbackCommand (org.infinispan.commands.tx.RollbackCommand)1 InvocationContextFactory (org.infinispan.context.InvocationContextFactory)1 AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)1 InvocationStage (org.infinispan.interceptors.InvocationStage)1 IracMetadata (org.infinispan.metadata.impl.IracMetadata)1 CacheNotifier (org.infinispan.notifications.cachelistener.CacheNotifier)1 TransactionTable (org.infinispan.transaction.impl.TransactionTable)1