use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class RecoveryManagerImpl method registerInDoubtTransaction.
public void registerInDoubtTransaction(RecoveryAwareRemoteTransaction remoteTransaction) {
XidImpl xid = remoteTransaction.getGlobalTransaction().getXid();
RecoveryAwareTransaction previous = inDoubtTransactions.put(new RecoveryInfoKey(xid, cacheName), remoteTransaction);
if (previous != null) {
log.preparedTxAlreadyExists(previous, remoteTransaction);
throw new IllegalStateException("Are there two different transactions having same Xid in the cluster?");
}
}
use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class RecoveryManagerImpl method getPreparedTransactionsFromCluster.
@Override
public RecoveryIterator getPreparedTransactionsFromCluster() {
PreparedTxIterator iterator = new PreparedTxIterator();
// 1. get local transactions first
// add the locally prepared transactions. The list of prepared transactions (even if they are not in-doubt)
// is mandated by the recovery process according to the JTA spec: "The transaction manager calls this [i.e. recover]
// method during recovery to obtain the list of transaction branches that are currently in prepared or heuristically
// completed states."
iterator.add((recoveryAwareTxTable()).getLocalPreparedXids());
// 2. now also add the in-doubt transactions.
iterator.add(getInDoubtTransactions());
// 3. then the remote ones
if (notOnlyMeInTheCluster() && broadcastForPreparedTx) {
boolean success = true;
Map<Address, Response> responses = getAllPreparedTxFromCluster();
for (Map.Entry<Address, Response> rEntry : responses.entrySet()) {
Response thisResponse = rEntry.getValue();
if (isSuccessful(thisResponse)) {
// noinspection unchecked
List<XidImpl> responseValue = ((SuccessfulResponse<List<XidImpl>>) thisResponse).getResponseValue();
if (log.isTraceEnabled()) {
log.tracef("Received Xid lists %s from node %s", responseValue, rEntry.getKey());
}
iterator.add(responseValue);
} else {
log.missingListPreparedTransactions(rEntry.getKey(), rEntry.getValue());
success = false;
}
}
// this makes sure that the broadcast only happens once!
this.broadcastForPreparedTx = !success;
if (!broadcastForPreparedTx)
log.debug("Finished broadcasting for remote prepared transactions. Returning only local values from now on.");
}
return iterator;
}
use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class XaTransactionTable method commit.
public CompletionStage<Void> commit(XidImpl xid, boolean isOnePhase) {
LocalXaTransaction localTransaction = getLocalTransaction(xid);
if (localTransaction == null) {
return CompletableFutures.completedExceptionFuture(new XAException(XAException.XAER_NOTA));
}
CompletionStage<Boolean> commitStage;
CompletionStage<Integer> prepareStage;
// inconsistent state.
if (isOnePhase && !CompletionStages.isCompletedSuccessfully(prepareStage = txCoordinator.prepare(localTransaction))) {
commitStage = prepareStage.thenCompose(ignore -> txCoordinator.commit(localTransaction, false));
} else {
commitStage = txCoordinator.commit(localTransaction, false);
}
if (CompletionStages.isCompletedSuccessfully(commitStage)) {
boolean committedInOnePhase = CompletionStages.join(commitStage);
forgetSuccessfullyCompletedTransaction(localTransaction, committedInOnePhase);
return CompletableFutures.completedNull();
}
return commitStage.thenApply(committedInOnePhase -> {
forgetSuccessfullyCompletedTransaction(localTransaction, committedInOnePhase);
return null;
});
}
use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class XaTransactionTable method forgetSuccessfullyCompletedTransaction.
private void forgetSuccessfullyCompletedTransaction(LocalXaTransaction localTransaction, boolean committedInOnePhase) {
final GlobalTransaction gtx = localTransaction.getGlobalTransaction();
XidImpl xid = localTransaction.getXid();
if (isRecoveryEnabled()) {
recoveryManager.removeRecoveryInformation(localTransaction.getRemoteLocksAcquired(), xid, gtx, partitionHandlingManager.isTransactionPartiallyCommitted(gtx));
removeLocalTransaction(localTransaction);
} else {
releaseLocksForCompletedTransaction(localTransaction, committedInOnePhase);
}
}
use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class ForgetTest method testInternalIdOnSameNode.
public void testInternalIdOnSameNode() {
XidImpl xid = tx.getXid();
recoveryOps(0).forget(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
// make sure tx has been removed
assertEquals(tt(1).getRemoteTxCount(), 0);
}
Aggregations