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