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);
}
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));
}
}
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);
}
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);
}
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);
}
Aggregations