Search in sources :

Example 11 with HeuristicMixed

use of org.omg.CosTransactions.HeuristicMixed in project narayana by jbosstm.

the class XAResourceRecordUnitTest method testCommitFailure.

@Test
public void testCommitFailure() throws Exception {
    ThreadActionData.purgeActions();
    OTSImpleManager.current().contextManager().purgeActions();
    FailureXAResource fxa = new FailureXAResource(FailureXAResource.FailLocation.commit);
    TransactionImple tx = new TransactionImple();
    XAResourceRecord xares = new XAResourceRecord(tx, fxa, tx.getTxId(), null);
    assertEquals(xares.prepare(), Vote.VoteCommit);
    try {
        xares.commit();
        fail();
    } catch (final HeuristicMixed ex) {
    }
    xares.forget();
}
Also used : XAResourceRecord(com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) Test(org.junit.Test)

Example 12 with HeuristicMixed

use of org.omg.CosTransactions.HeuristicMixed in project narayana by jbosstm.

the class CurrentImple method commit.

/**
 * It's not possible to commit/abort out of order using the current
 * interface.
 *
 * Do we delete the control if the transaction gives an heuristic result?
 * CurrentImplely we do.
 *
 * If another thread has already terminated the transaction then: (i) if it
 * committed, we do nothing - could throw TransactionRequired of
 * INVALID_TRANSACTION, or NoTransaction. Probably not NoTransaction, since
 * it would be better to distinguish between the situation where the
 * transaction has already been terminated and there really is no
 * transaction for this thread. (ii) if it rolledback, we throw
 * TRANSACTION_ROLLEDBACK.
 */
public void commit(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("CurrentImple::commit ( " + report_heuristics + " )");
    }
    ControlWrapper currentAction = _theManager.current();
    if (currentAction != null) {
        try {
            ThreadAssociationControl.updateAssociation(currentAction, TX_COMMITTED);
        } catch (Exception e) {
            /*
				 * An error happened, so mark the transaction as rollback only
				 * (in case it hasn't already been so marked.)
				 */
            rollback_only();
        }
        try {
            currentAction.commit(report_heuristics);
            _theManager.popAction();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            /*
				 * Is ok to destroy transaction. Different for heuristics.
				 */
            _theManager.popAction();
            throw e1;
        } catch (HeuristicMixed e2) {
            _theManager.popAction();
            if (report_heuristics)
                throw e2;
        } catch (HeuristicHazard e3) {
            _theManager.popAction();
            if (report_heuristics)
                throw e3;
        } catch (SystemException e4) {
            _theManager.popAction();
            throw e4;
        } catch (Unavailable e5) {
            /*
				 * If terminated by some other thread then the reference we have
				 * will no longer be valid.
				 */
            _theManager.popAction();
            throw new INVALID_TRANSACTION();
        }
    } else
        throw new NoTransaction();
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Example 13 with HeuristicMixed

use of org.omg.CosTransactions.HeuristicMixed in project narayana by jbosstm.

the class ArjunaTransactionImple method commit.

/**
 * If the transaction has already been committed (by another thread, for
 * example) then we do nothing - could throw TransactionRequired or
 * INVALID_TRANSACTION. However, if it was rolledback then we throw
 * TRANSACTION_ROLLEDBACK. Seems like an inconsistency.
 *
 * OTS is vague as to what to do if the transaction has been terminated,
 * so we make a sensible choice.
 *
 * report_heuristics is ignored if we are a subtransaction.
 */
public void commit(boolean report_heuristics) throws HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::commit for " + get_uid());
    }
    if (ArjunaTransactionImple._checkedTransactions && !checkAccess()) {
        throw new NO_PERMISSION(0, CompletionStatus.COMPLETED_NO);
    }
    int outcome = super.status();
    if ((outcome == ActionStatus.RUNNING) || // have we already been
    (outcome == ActionStatus.ABORT_ONLY)) // committed?
    {
        try {
            if (_synchs != null) {
                if (outcome == ActionStatus.RUNNING || (outcome == ActionStatus.ABORT_ONLY && TxControl.isBeforeCompletionWhenRollbackOnly())) {
                    doBeforeCompletion();
                }
            }
        } catch (Exception e) {
        /*
				 * Don't do anything, since we will have marked the transaction
				 * as rollback only.
				 */
        }
        if (parentTransaction != null) {
            parentTransaction.removeChildAction(this);
        }
        outcome = super.End(report_heuristics);
        try {
            if (_synchs != null) {
                currentStatus = determineStatus(this);
                doAfterCompletion(currentStatus);
                _synchs = null;
            }
        } catch (Exception e) {
        }
        destroyAction();
    } else if (outcome == ActionStatus.ABORTED || outcome == ActionStatus.H_ROLLBACK) {
        throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.FAILED_TO_COMMIT, CompletionStatus.COMPLETED_NO);
    } else {
        throw new INVALID_TRANSACTION(0, CompletionStatus.COMPLETED_NO);
    }
    switch(outcome) {
        case ActionStatus.COMMITTED:
        case ActionStatus.H_COMMIT:
        case // in case asynchronous commit!
        ActionStatus.COMMITTING:
            return;
        case ActionStatus.ABORTED:
        // in case of asynchronous abort!
        case ActionStatus.ABORTING:
        case ActionStatus.H_ROLLBACK:
            throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.FAILED_TO_COMMIT, CompletionStatus.COMPLETED_NO);
        case ActionStatus.H_MIXED:
            if (report_heuristics)
                throw new HeuristicMixed();
            break;
        case ActionStatus.H_HAZARD:
        default:
            if (report_heuristics)
                throw new HeuristicHazard();
            break;
    }
}
Also used : NO_PERMISSION(org.omg.CORBA.NO_PERMISSION) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) SystemException(org.omg.CORBA.SystemException) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 14 with HeuristicMixed

use of org.omg.CosTransactions.HeuristicMixed in project narayana by jbosstm.

the class ServerNestedAction method commit_subtransaction.

public void commit_subtransaction(Coordinator parent) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerNestedAction::commit_subtransaction : " + _theUid);
    }
    if (_theControl == null) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_nullcontrol_1("ServerNestedAction.commit_subtransaction");
        throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
    }
    if (_theControl.isWrapper()) {
        destroyResource();
        return;
    }
    ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
    try {
        theTransaction.commit(false);
    } catch (TRANSACTION_ROLLEDBACK e1) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e1);
        throw e1;
    } catch (INVALID_TRANSACTION e5) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e5);
        throw e5;
    } catch (HeuristicMixed e2) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e2);
        throw new BAD_OPERATION(ExceptionCodes.HEURISTIC_COMMIT, CompletionStatus.COMPLETED_MAYBE);
    } catch (HeuristicHazard e3) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e3);
        throw new BAD_OPERATION(ExceptionCodes.HEURISTIC_COMMIT, CompletionStatus.COMPLETED_MAYBE);
    } catch (SystemException e4) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e4);
        throw e4;
    } catch (Exception e5) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e5);
        throw new UNKNOWN(e5.toString());
    } finally {
        ThreadActionData.popAction();
        destroyResource();
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) UNKNOWN(org.omg.CORBA.UNKNOWN) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SystemException(org.omg.CORBA.SystemException)

Example 15 with HeuristicMixed

use of org.omg.CosTransactions.HeuristicMixed in project narayana by jbosstm.

the class RCTest method test.

@Test
public void test() {
    boolean shouldCommit = true;
    boolean passed = false;
    Coordinator coord = null;
    ORB myORB = null;
    RootOA myOA = null;
    try {
        myORB = ORB.getInstance("test");
        myOA = OA.getRootOA(myORB);
        myORB.initORB(new String[] {}, null);
        myOA.initOA();
        ORBManager.setORB(myORB);
        ORBManager.setPOA(myOA);
        CurrentImple current = OTSImpleManager.current();
        AtomicResource aImpl = new AtomicResource(shouldCommit);
        Resource atomicObject = aImpl.getReference();
        System.out.println("beginning top-level transaction.");
        current.begin();
        Control myControl = current.get_control();
        assertNotNull(myControl);
        System.out.println("getting coordinator");
        coord = myControl.get_coordinator();
        myControl = null;
        System.out.println("registering resources.");
        RecoveryCoordinator rc = null;
        try {
            rc = coord.register_resource(atomicObject);
        } catch (Exception ex) {
            fail("Failed to register resources: " + ex);
            ex.printStackTrace();
        }
        if (rc == null)
            System.out.println("No recovery coordinator reference.");
        else {
            Status s = Status.StatusUnknown;
            try {
                System.out.println("Attempting to use recovery coordinator.");
                s = rc.replay_completion(atomicObject);
            } catch (NotPrepared e) {
                s = Status.StatusActive;
            } catch (Exception ex) {
                fail("Caught: " + ex);
                ex.printStackTrace();
            }
            System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            if (s == Status.StatusActive)
                passed = true;
        }
        System.out.println("committing top-level transaction.");
        if (shouldCommit)
            current.commit(true);
        else
            current.rollback();
        if (rc == null)
            System.out.println("No recovery coordinator reference.");
        else {
            Status s = Status.StatusUnknown;
            try {
                System.out.println("Attempting to use recovery coordinator.");
                s = rc.replay_completion(atomicObject);
            } catch (NotPrepared e) {
                s = Status.StatusActive;
            } catch (Exception ex) {
                fail("Caught: " + ex);
            }
            System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            if (passed && (s == Status.StatusRolledBack))
                passed = true;
            else
                passed = false;
        }
    } catch (TRANSACTION_ROLLEDBACK e1) {
        System.out.println("\nTransaction RolledBack exception");
    } catch (HeuristicMixed e2) {
        System.out.println("\nTransaction HeuristicMixed exception");
    } catch (HeuristicHazard e3) {
        System.out.println("\nTransaction HeuristicHazard exception");
    } catch (Exception e4) {
        System.out.println("Caught unexpected exception: " + e4);
    }
    System.out.println("Trying to determing final transaction outcome.");
    org.omg.CosTransactions.Status status = Status.StatusUnknown;
    try {
        if (coord != null) {
            status = coord.get_status();
            coord = null;
        } else
            System.out.println("\nCould not determine action status.");
    } catch (SystemException ex1) {
    // assume invalid reference - tx may have been garbage collected
    } catch (Exception e5) {
        System.out.println("Caught unexpected exception:" + e5);
    }
    System.out.println("\nFinal action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
    assertTrue(passed);
    myOA.destroy();
    myORB.shutdown();
}
Also used : Status(org.omg.CosTransactions.Status) AtomicResource(com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource) Resource(org.omg.CosTransactions.Resource) RootOA(com.arjuna.orbportability.RootOA) AtomicResource(com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) NotPrepared(org.omg.CosTransactions.NotPrepared) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) Status(org.omg.CosTransactions.Status) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Aggregations

HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)15 HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)12 SystemException (org.omg.CORBA.SystemException)10 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)9 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)6 ServerTransaction (com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction)4 Test (org.junit.Test)4 NoTransaction (org.omg.CosTransactions.NoTransaction)4 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)3 NotPrepared (org.omg.CosTransactions.NotPrepared)3 XAResourceRecord (com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord)2 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)2 ORB (com.arjuna.orbportability.ORB)2 RootOA (com.arjuna.orbportability.RootOA)2 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)2 AtomicResource (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource)2 XAException (javax.transaction.xa.XAException)2 UNKNOWN (org.omg.CORBA.UNKNOWN)2 Control (org.omg.CosTransactions.Control)2 Coordinator (org.omg.CosTransactions.Coordinator)2