Search in sources :

Example 1 with HeuristicMixed

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

the class ServerTopLevelAction method prepare.

/*
 * Will only be called by the remote top-level transaction.
 */
public org.omg.CosTransactions.Vote prepare() throws HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::prepare for " + _theUid);
    }
    if (_theControl == null) {
        throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
    }
    if (_theControl.isWrapper()) {
        // won't necessarily get another invocation!
        destroyResource();
        return Vote.VoteReadOnly;
    }
    ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
    // ThreadActionData.pushAction(theTransaction); // LockManager needs to know if there is a transaction
    int result = TwoPhaseOutcome.PREPARE_NOTOK;
    /*
	 * Transaction may have locally timed out and been rolled back.
	 */
    int s = theTransaction.status();
    if ((s == ActionStatus.RUNNING) || (s == ActionStatus.ABORT_ONLY))
        result = theTransaction.doPrepare();
    else {
        switch(s) {
            case ActionStatus.COMMITTING:
            case ActionStatus.COMMITTED:
            case ActionStatus.H_COMMIT:
                result = TwoPhaseOutcome.PREPARE_OK;
                break;
            case ActionStatus.H_MIXED:
                result = TwoPhaseOutcome.HEURISTIC_MIXED;
                break;
            case ActionStatus.H_HAZARD:
                result = TwoPhaseOutcome.HEURISTIC_HAZARD;
                break;
        }
    }
    ThreadActionData.popAction();
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::prepare for " + _theUid + " : " + TwoPhaseOutcome.stringForm(result));
    }
    if (result == TwoPhaseOutcome.PREPARE_NOTOK) {
        try {
            rollback();
        } catch (HeuristicCommit ex1) {
            result = TwoPhaseOutcome.HEURISTIC_COMMIT;
        } catch (HeuristicMixed ex2) {
            result = TwoPhaseOutcome.HEURISTIC_MIXED;
        } catch (HeuristicHazard ex3) {
            result = TwoPhaseOutcome.HEURISTIC_HAZARD;
        } catch (SystemException ex4) {
            result = TwoPhaseOutcome.HEURISTIC_HAZARD;
        }
    }
    switch(result) {
        case TwoPhaseOutcome.INVALID_TRANSACTION:
            throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
        case TwoPhaseOutcome.PREPARE_OK:
            return Vote.VoteCommit;
        case TwoPhaseOutcome.PREPARE_NOTOK:
            // won't necessarily get another invocation!
            destroyResource();
            return Vote.VoteRollback;
        case TwoPhaseOutcome.PREPARE_READONLY:
            // won't necessarily get another invocation!
            destroyResource();
            return Vote.VoteReadOnly;
        case TwoPhaseOutcome.HEURISTIC_MIXED:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            // will eventually get forget
            throw new HeuristicMixed();
        case TwoPhaseOutcome.HEURISTIC_HAZARD:
        default:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicHazard();
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) HeuristicCommit(org.omg.CosTransactions.HeuristicCommit) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 2 with HeuristicMixed

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

the class ServerTopLevelAction method rollback.

public void rollback() throws HeuristicCommit, HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::rollback for " + _theUid);
    }
    if (_theControl == null) {
        throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
    }
    if (_theControl.isWrapper()) {
        destroyResource();
        return;
    }
    ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
    // LockManager needs to know if there is a transaction
    ThreadActionData.pushAction(theTransaction);
    int actionStatus = theTransaction.status();
    if (actionStatus == ActionStatus.PREPARED) {
        /*
	     * This will also call any after_completions on
	     * registered synchronizations.
	     */
        actionStatus = theTransaction.doPhase2Abort();
    } else {
        if ((actionStatus == ActionStatus.RUNNING) || (actionStatus == ActionStatus.ABORT_ONLY)) {
            try {
                if (!valid())
                    // must rollback
                    theTransaction.doPhase2Abort();
                else
                    theTransaction.rollback();
                actionStatus = ActionStatus.ABORTED;
            } catch (SystemException ex) {
                actionStatus = ActionStatus.ABORTED;
                throw ex;
            } finally {
                destroyResource();
            }
        }
    }
    ThreadActionData.popAction();
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::rollback for " + _theUid + " : " + ActionStatus.stringForm(actionStatus));
    }
    switch(actionStatus) {
        case ActionStatus.PREPARED:
            throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
        case ActionStatus.ABORTED:
        case ActionStatus.H_ROLLBACK:
            destroyResource();
            break;
        case ActionStatus.COMMITTED:
        case ActionStatus.H_COMMIT:
            destroyResource();
            throw new HeuristicCommit();
        case ActionStatus.H_MIXED:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicMixed();
        case ActionStatus.H_HAZARD:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicHazard();
        default:
            destroyResource();
            break;
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) HeuristicCommit(org.omg.CosTransactions.HeuristicCommit) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 3 with HeuristicMixed

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

the class ServerTopLevelAction method commit.

public void commit() throws NotPrepared, HeuristicRollback, HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::commit for " + _theUid);
    }
    if (_theControl == null) {
        throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
    }
    if (_theControl.isWrapper()) {
        destroyResource();
        return;
    }
    ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
    // LockManager needs to know if there is a transaction
    ThreadActionData.pushAction(theTransaction);
    int actionStatus = theTransaction.status();
    boolean notPrepared = false;
    if (actionStatus == ActionStatus.PREPARED) {
        /*
	     * This will also call any after_completions on
	     * registered synchronizations.
	     */
        actionStatus = theTransaction.doPhase2Commit();
    } else {
        if (actionStatus == ActionStatus.RUNNING) {
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("ServerTopLevelAction::commit for " + _theUid + " : NotPrepared");
            }
            notPrepared = true;
        }
    }
    ThreadActionData.popAction();
    if (notPrepared)
        throw new NotPrepared();
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::commit for " + _theUid + " : " + ActionStatus.stringForm(actionStatus));
    }
    switch(actionStatus) {
        case ActionStatus.PREPARED:
            throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
        case ActionStatus.COMMITTED:
        case ActionStatus.H_COMMIT:
            destroyResource();
            break;
        case ActionStatus.ABORTED:
        case ActionStatus.H_ROLLBACK:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicRollback();
        case ActionStatus.H_MIXED:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicMixed();
        case ActionStatus.H_HAZARD:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicHazard();
        default:
            destroyResource();
            break;
    }
}
Also used : HeuristicRollback(org.omg.CosTransactions.HeuristicRollback) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) NotPrepared(org.omg.CosTransactions.NotPrepared) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 4 with HeuristicMixed

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

the class XAResourceRecord method commit.

public void commit() throws org.omg.CORBA.SystemException, NotPrepared, HeuristicRollback, HeuristicMixed, HeuristicHazard {
    if (jtaxLogger.logger.isTraceEnabled()) {
        jtaxLogger.logger.trace("XAResourceRecord.commit for " + _tranID);
    }
    if (_tranID == null) {
        jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_nulltransaction("XAResourceRecord.commit");
    } else {
        if ((_theXAResource != null) && (!_committed)) {
            switch(_heuristic) {
                case TwoPhaseOutcome.HEURISTIC_HAZARD:
                    throw new org.omg.CosTransactions.HeuristicHazard();
                case TwoPhaseOutcome.HEURISTIC_MIXED:
                    throw new org.omg.CosTransactions.HeuristicMixed();
                case TwoPhaseOutcome.HEURISTIC_ROLLBACK:
                    throw new org.omg.CosTransactions.HeuristicRollback();
                default:
                    break;
            }
            if (!_prepared)
                throw new NotPrepared();
            boolean removeConnection = true;
            try {
                if (!_committed) {
                    _committed = true;
                    _theXAResource.commit(_tranID, false);
                    destroyState();
                }
            } catch (XAException e1) {
                if (notAProblem(e1, true)) {
                    // some other thread got there first (probably)
                    destroyState();
                } else {
                    _committed = false;
                    jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_xaerror("XAResourceRecord.commit", XAHelper.printXAErrorCode(e1), _theXAResource.toString(), XAHelper.xidToString(_tranID), e1);
                    if (jtaxLogger.logger.isTraceEnabled()) {
                        jtaxLogger.logger.tracef("XAResourceRecord.commit exception %s " + "resource_trace: txn uid=%s resource uid=%s\n", XAHelper.printXAErrorCode(e1), _tranID, get_uid());
                    }
                    switch(e1.errorCode) {
                        case XAException.XA_HEURHAZ:
                            updateState(TwoPhaseOutcome.HEURISTIC_HAZARD);
                            throw new org.omg.CosTransactions.HeuristicHazard();
                        case // what about forget? OTS doesn't support this code here.
                        XAException.XA_HEURCOM:
                            destroyState();
                            break;
                        case XAException.XA_HEURRB:
                        case XAException.XA_RBROLLBACK:
                        case XAException.XA_RBCOMMFAIL:
                        case XAException.XA_RBDEADLOCK:
                        case XAException.XA_RBINTEGRITY:
                        case XAException.XA_RBOTHER:
                        case XAException.XA_RBPROTO:
                        case XAException.XA_RBTIMEOUT:
                        case XAException.XA_RBTRANSIENT:
                        case XAException.XAER_RMERR:
                            updateState(TwoPhaseOutcome.HEURISTIC_ROLLBACK);
                            throw new org.omg.CosTransactions.HeuristicRollback();
                        case XAException.XA_HEURMIX:
                            updateState(TwoPhaseOutcome.HEURISTIC_MIXED);
                            throw new org.omg.CosTransactions.HeuristicMixed();
                        case XAException.XAER_NOTA:
                            if (// committed previously on participant
                            _phaseTwoStarted)
                                break;
                            // RM unexpectedly lost track of the tx, outcome is uncertain
                            updateState(TwoPhaseOutcome.HEURISTIC_HAZARD);
                            throw new org.omg.CosTransactions.HeuristicHazard();
                        case XAException.XAER_PROTO:
                            // presumed abort (or we could be really paranoid and throw a heuristic)
                            throw new TRANSACTION_ROLLEDBACK();
                        case XAException.XA_RETRY:
                        case XAException.XAER_RMFAIL:
                            removeConnection = false;
                            // Since JBTM-2710 this is not right because it will mean that commit is not reattempted _committed = true;  // remember for recovery later.
                            throw // will cause log to be rewritten.
                            new UNKNOWN();
                        // resource manager failed, did it rollback?
                        case XAException.XAER_INVAL:
                        default:
                            throw new org.omg.CosTransactions.HeuristicHazard();
                    }
                }
            } catch (Exception e2) {
                _committed = false;
                jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_generror("XAResourceRecord.commit", _theXAResource.toString(), XAHelper.xidToString(_tranID), e2);
                throw new UNKNOWN();
            } finally {
                _phaseTwoStarted = true;
                if (removeConnection) {
                    removeConnection();
                }
            }
        }
    }
}
Also used : XAException(javax.transaction.xa.XAException) HeuristicRollback(org.omg.CosTransactions.HeuristicRollback) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) NotPrepared(org.omg.CosTransactions.NotPrepared) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SystemException(org.omg.CORBA.SystemException) XAException(javax.transaction.xa.XAException) NotSerializableException(java.io.NotSerializableException) HeuristicRollback(org.omg.CosTransactions.HeuristicRollback) UNKNOWN(org.omg.CORBA.UNKNOWN) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK)

Example 5 with HeuristicMixed

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

the class AtomicTransaction method end.

/*
	 * public synchronized void begin () throws SubtransactionsUnavailable,
	 * SystemException { if (jtaxLogger.loggerI18N.isWarnEnabled()) {
	 * jtaxLogger.loggerI18N.warn("com.arjuna.ats.internal.jta.transaction.jts.atomictxnobegin"); }
	 * 
	 * throw new INVALID_TRANSACTION(ExceptionCodes.ALREADY_BEGUN,
	 * CompletionStatus.COMPLETED_NO); }
	 */
/**
 * Does not change thread-to-tx association as base class commit does.
 */
public synchronized void end(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, WrongTransaction, SystemException {
    if (jtaxLogger.logger.isTraceEnabled()) {
        jtaxLogger.logger.trace("AtomicTransaction::end ( " + report_heuristics + " ) for " + _theAction);
    }
    if (_theAction == null) {
        throw new NoTransaction();
    }
    try {
        _theAction.commit(report_heuristics);
        _theStatus = Status.StatusCommitted;
    } catch (Unavailable e) {
        _theStatus = Status.StatusNoTransaction;
        throw new NoTransaction();
    } catch (HeuristicMixed e) {
        _theStatus = getStatus();
        throw e;
    } catch (HeuristicHazard e) {
        _theStatus = getStatus();
        throw e;
    } catch (TRANSACTION_ROLLEDBACK e) {
        _theStatus = Status.StatusRolledBack;
        throw e;
    } catch (SystemException e) {
        _theStatus = getStatus();
        throw e;
    } finally {
        // now remove it from the reaper
        TransactionReaper.transactionReaper().remove(_theAction);
    }
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) SystemException(org.omg.CORBA.SystemException) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) Unavailable(org.omg.CosTransactions.Unavailable)

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