Search in sources :

Example 1 with HeuristicHazard

use of org.omg.CosTransactions.HeuristicHazard 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 HeuristicHazard

use of org.omg.CosTransactions.HeuristicHazard 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 HeuristicHazard

use of org.omg.CosTransactions.HeuristicHazard 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 HeuristicHazard

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

the class XAResourceRecord method prepare.

public org.omg.CosTransactions.Vote prepare() throws HeuristicMixed, HeuristicHazard, org.omg.CORBA.SystemException {
    if (jtaxLogger.logger.isTraceEnabled()) {
        jtaxLogger.logger.trace("XAResourceRecord.prepare for " + _tranID);
    }
    if (!_valid || (_theXAResource == null) || (_tranID == null)) {
        jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_nulltransaction("XAResourceRecord.prepare");
        removeConnection();
        return Vote.VoteRollback;
    }
    try {
        /*
			 * Window of vulnerability versus performance trade-off: if we
			 * create the resource log here then we slow things down in the case
			 * the resource rolls back or returns read only (since we have
			 * written data for no reason and now need to delete it). If we
			 * create the resource log after we know the prepare outcome then
			 * there's a chance we may crash between prepare and writing the
			 * state.
			 *
			 * We go for the latter currently since failures are rare, but
			 * performance is always required. The result is that the
			 * transaction will roll back (since it won't get an ack from
			 * prepare) and the resource won't be recovered. The sys. admin.
			 * will have to clean up manually.
			 *
			 * Actually what will happen in the case of ATS is that the XA
			 * recovery module will eventually roll back this resource when it
			 * notices that there is no log entry for it.
			 */
        endAssociation(XAResource.TMSUCCESS, TxInfo.NOT_ASSOCIATED);
        if (_theXAResource.prepare(_tranID) == XAResource.XA_RDONLY) {
            removeConnection();
            return Vote.VoteReadOnly;
        } else {
            if (createState())
                return Vote.VoteCommit;
            else
                return Vote.VoteRollback;
        }
    } catch (XAException e1) {
        jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_preparefailed(_theXAResource.toString(), XAHelper.xidToString(_tranID), XAHelper.printXAErrorCode(e1), e1);
        if (jtaxLogger.logger.isTraceEnabled()) {
            jtaxLogger.logger.tracef("XAResourceRecord.prepare exception %s resource_trace: txn uid=%s " + "resource uid=%s\n", XAHelper.printXAErrorCode(e1), _tranID, get_uid());
        }
        if (// won't have rollback called on it
        _rollbackOptimization)
            removeConnection();
        switch(e1.errorCode) {
            case XAException.XAER_RMERR:
            case XAException.XAER_RMFAIL:
            case XAException.XA_RBROLLBACK:
            case XAException.XA_RBEND:
            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.XAER_INVAL:
            case XAException.XAER_PROTO:
            case // resource may have arbitrarily rolled back (shouldn't, but ...)
            XAException.XAER_NOTA:
                return Vote.VoteRollback;
            default:
                // we're not really sure (shouldn't get here though).
                throw new HeuristicHazard();
        }
    } catch (Exception e2) {
        jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_preparefailed(_theXAResource.toString(), XAHelper.xidToString(_tranID), "-", e2);
        if (// won't have rollback called on it
        _rollbackOptimization)
            removeConnection();
        return Vote.VoteRollback;
    }
}
Also used : XAException(javax.transaction.xa.XAException) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SystemException(org.omg.CORBA.SystemException) XAException(javax.transaction.xa.XAException) NotSerializableException(java.io.NotSerializableException)

Example 5 with HeuristicHazard

use of org.omg.CosTransactions.HeuristicHazard 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)

Aggregations

HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)19 SystemException (org.omg.CORBA.SystemException)13 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)12 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)11 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)7 ServerTransaction (com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction)5 Test (org.junit.Test)5 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)4 UNKNOWN (org.omg.CORBA.UNKNOWN)4 NoTransaction (org.omg.CosTransactions.NoTransaction)4 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)3 NotSerializableException (java.io.NotSerializableException)3 XAException (javax.transaction.xa.XAException)3 NotPrepared (org.omg.CosTransactions.NotPrepared)3 ORB (com.arjuna.orbportability.ORB)2 RootOA (com.arjuna.orbportability.RootOA)2 ExtendedCrashRecord (com.hp.mwtests.ts.jta.jts.common.ExtendedCrashRecord)2 AtomicResource (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource)2 Control (org.omg.CosTransactions.Control)2 Coordinator (org.omg.CosTransactions.Coordinator)2