Search in sources :

Example 36 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class XATerminatorImple method doRecover.

/**
 * Return a list of indoubt transactions. This may include those
 * transactions that are currently in-flight and running 2PC and do not need
 * recovery invoked on them.
 *
 * @param nodeName
 * 				Only recover transactions for this node (unless set to NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES)
 * @throws XAException
 *             thrown if any error occurs.
 * @return a list of potentially indoubt transactions or <code>null</code>.
 */
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException {
    /*
         * Requires going through the objectstore for the states of imported
         * transactions. Our own crash recovery takes care of transactions
         * imported via CORBA, Web Services etc.
         */
    Xid[] indoubt = null;
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        InputObjectState states = new InputObjectState();
        if (recoveryStore.allObjUids(SubordinateAtomicAction.getType(), states) && (states.notempty())) {
            Stack<Xid> values = new Stack<Xid>();
            boolean finished = false;
            do {
                Uid uid = null;
                try {
                    uid = UidHelper.unpackFrom(states);
                } catch (IOException ex) {
                    ex.printStackTrace();
                    finished = true;
                }
                if (uid.notEquals(Uid.nullUid())) {
                    if (parentNodeName != null) {
                        SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
                        XidImple loadedXid = (XidImple) saa.getXid();
                        if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
                            String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
                            if ((loadedXidSubordinateNodeName == null && loadedXidSubordinateNodeName == TxControl.getXANodeName()) || loadedXidSubordinateNodeName.equals(TxControl.getXANodeName())) {
                                if (parentNodeName.equals(saa.getParentNodeName())) {
                                    if (jtaLogger.logger.isDebugEnabled()) {
                                        jtaLogger.logger.debug("Found record for " + saa);
                                    }
                                    // TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                                    values.push(loadedXid);
                                }
                            }
                        }
                    } else if (xid == null) {
                        TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                        if (tx != null)
                            values.push(tx.baseXid());
                    } else {
                        SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
                        XidImple loadedXid = (XidImple) saa.getXid();
                        if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
                            String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
                            if (XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID()).equals(loadedXidSubordinateNodeName)) {
                                if (Arrays.equals(loadedXid.getGlobalTransactionId(), xid.getGlobalTransactionId())) {
                                    if (jtaLogger.logger.isDebugEnabled()) {
                                        jtaLogger.logger.debug("Found record for " + saa);
                                    }
                                    TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                                    values.push(loadedXid);
                                }
                            }
                        }
                    }
                } else
                    finished = true;
            } while (!finished);
            if (values.size() > 0) {
                int index = 0;
                indoubt = new Xid[values.size()];
                while (!values.empty()) {
                    indoubt[index] = values.pop();
                    index++;
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return indoubt;
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple) IOException(java.io.IOException) SubordinateAtomicAction(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) IOException(java.io.IOException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException) Stack(java.util.Stack) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid)

Example 37 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class XAResourceRecord method loadState.

private final boolean loadState() {
    setObjectStore();
    InputObjectState os = null;
    try {
        os = _participantStore.read_committed(_theUid, type());
    } catch (Exception e) {
        jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_loadstateread(e);
        os = null;
    }
    if (os != null) {
        _valid = restoreState(os);
        os = null;
    } else
        _valid = false;
    return _valid;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) SystemException(org.omg.CORBA.SystemException) XAException(javax.transaction.xa.XAException) NotSerializableException(java.io.NotSerializableException)

Example 38 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class XATerminatorImple method doRecover.

/**
 * <p>
 * Recovering /JCA section of object store.
 * The filtering functionality on xid or parentNodeName is not permitted and throws {@link NotSupportedException}.<br>
 * Expected to be called only with null parameters <code>doRecover(null, null)</code>
 *
 * @param xid has to be null
 * @param parentNodeName  has to be null
 * @return array of subordinate recovered xids
 * @throws XAException  if recovery operation fails for the XA protocol reason
 * @throws NotSupportedException  if not null params are passes as method parameters
 */
@Override
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException, NotSupportedException {
    if (xid != null || parentNodeName != null)
        throw new NotSupportedException("doRecover method works only with null arguments");
    Xid[] indoubt = null;
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        InputObjectState states = new InputObjectState();
        // only look in the JCA section of the object store
        if (recoveryStore.allObjUids(ServerTransaction.getType(), states) && (states.notempty())) {
            Stack<Transaction> values = new Stack<Transaction>();
            boolean finished = false;
            do {
                Uid uid = null;
                try {
                    uid = UidHelper.unpackFrom(states);
                } catch (IOException ex) {
                    jtsLogger.i18NLogger.info_fail_to_read_subordinate_uid(recoveryStore, states, ex);
                    finished = true;
                }
                if (uid.notEquals(Uid.nullUid())) {
                    Transaction tx = SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                    if (tx != null)
                        values.push(tx);
                } else
                    finished = true;
            } while (!finished);
            if (values.size() > 0) {
                int index = 0;
                indoubt = new Xid[values.size()];
                while (!values.empty()) {
                    TransactionImple id = (TransactionImple) values.pop();
                    indoubt[index] = id.baseXid();
                    index++;
                }
            }
        }
    } catch (Exception ex) {
        jtsLogger.i18NLogger.info_fail_to_dorecover(xid, parentNodeName, ex);
    }
    return indoubt;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple) IOException(java.io.IOException) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) IOException(java.io.IOException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException) Stack(java.util.Stack) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) ServerTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.coordinator.ServerTransaction) Transaction(javax.transaction.Transaction) SubordinateAtomicTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction) NotSupportedException(javax.transaction.NotSupportedException)

Example 39 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class XAResourceRecordWrappingPluginImpl method initialize.

private void initialize() throws ObjectStoreException, IOException {
    if (this.nodeIdentifier == null) {
        synchronized (this) {
            // null in case of race condition
            if (this.nodeIdentifier == null) {
                this.nodeIdentifier = TxControl.getXANodeName();
                this.eisNameStore = StoreManager.getEISNameStore();
                InputObjectState states = new InputObjectState();
                int keyMax = 0;
                boolean allObjUids = eisNameStore.allObjUids("EISNAME", states);
                while (states.notempty()) {
                    Uid uid = UidHelper.unpackFrom(states);
                    if (uid.equals(Uid.nullUid())) {
                        break;
                    } else {
                        InputObjectState oState = eisNameStore.read_committed(uid, "EISNAME");
                        String nodeName = oState.unpackString();
                        if (nodeName.equals(nodeIdentifier)) {
                            Integer key = oState.unpackInt();
                            String jndiName = oState.unpackString();
                            keyToName.put(key, jndiName);
                            nameToKey.put(jndiName, key);
                            if (key > keyMax) {
                                keyMax = key;
                            }
                        } else {
                        // logger warn that we are using a new node
                        }
                    }
                }
                nextKey.set(keyMax + 1);
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid)

Example 40 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class ComplexLockManagerProxyUnitTest method testSaveRestore.

public void testSaveRestore() {
    BasicLockable obj = new BasicLockable();
    LockManagerProxy<BasicLockable> proxy = new LockManagerProxy<BasicLockable>(obj);
    OutputObjectState os = new OutputObjectState();
    assertTrue(proxy.save_state(os, ObjectType.RECOVERABLE));
    obj._saved = 4567;
    // make sure it's ignored by save/restore.
    obj._isState = 0;
    InputObjectState ios = new InputObjectState(os);
    assertTrue(proxy.restore_state(ios, ObjectType.RECOVERABLE));
    assertEquals(obj._saved, 1234);
    assertEquals(obj._isState, 0);
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState)

Aggregations

InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)133 Uid (com.arjuna.ats.arjuna.common.Uid)83 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)55 Test (org.junit.Test)47 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)42 IOException (java.io.IOException)30 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)23 ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)17 XidImple (com.arjuna.ats.jta.xa.XidImple)9 XAException (javax.transaction.xa.XAException)9 ArrayList (java.util.ArrayList)8 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)7 Xid (javax.transaction.xa.Xid)6 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)5 Date (java.util.Date)5 Vector (java.util.Vector)5 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)4 HashedActionStore (com.arjuna.ats.internal.arjuna.objectstore.HashedActionStore)4 NullActionStore (com.arjuna.ats.internal.arjuna.objectstore.NullActionStore)4 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)4