예제 #1
0
 /** Same comment as for {@link #prepare(javax.transaction.xa.Xid)} applies for commit. */
 public void commit(Xid externalXid, boolean isOnePhase) throws XAException {
   Xid xid = convertXid(externalXid);
   LocalXaTransaction localTransaction = getLocalTransactionAndValidate(xid);
   if (trace)
     log.tracef(
         "Committing transaction %s. One phase? %s",
         localTransaction.getGlobalTransaction(), isOnePhase);
   if (isOnePhase && !configuration.isOnePhaseCommit()) {
     // isOnePhase being true means that we're the only participant in the distributed transaction
     // and TM does the
     // 1PC optimization. We run a 2PC though, as running only 1PC has a high chance of leaving the
     // cluster in
     // inconsistent state.
     try {
       txCoordinator.prepare(localTransaction);
       txCoordinator.commit(localTransaction, false);
     } catch (XAException e) {
       if (trace)
         log.tracef("Couldn't commit 1PC transaction %s, trying to rollback.", localTransaction);
       try {
         rollback(xid);
         throw new XAException(XAException.XA_HEURRB); // this is a heuristic rollback
       } catch (XAException e1) {
         log.couldNotRollbackPrepared1PcTransaction(localTransaction, e1);
         // inform the TM that a resource manager error has occurred in the transaction branch
         // (XAER_RMERR).
         throw new XAException(XAException.XAER_RMERR);
       }
     }
   } else {
     txCoordinator.commit(localTransaction, configuration.isOnePhaseCommit());
   }
   forgetSuccessfullyCompletedTransaction(recoveryManager, xid, localTransaction);
 }
예제 #2
0
 /** Same comment as for {@link #prepare(javax.transaction.xa.Xid)} applies for commit. */
 public void rollback(Xid externalXid) throws XAException {
   Xid xid = convertXid(externalXid);
   LocalXaTransaction localTransaction1 = getLocalTransactionAndValidateImpl(xid, txTable);
   localTransaction.markForRollback(
       true); // ISPN-879 : make sure that locks are no longer associated to this transactions
   txCoordinator.rollback(localTransaction1);
   forgetSuccessfullyCompletedTransaction(recoveryManager, xid, localTransaction1);
 }