Search in sources :

Example 81 with InputObjectState

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

the class LogStore method allObjUids.

/**
 * This is a recovery-only method and should not be called during normal
 * execution. As such we need to load in all of the logs we can find that
 * aren't already loaded (or activated).
 */
public boolean allObjUids(String tName, InputObjectState state, int match) throws ObjectStoreException {
    /*
           * match will always be OS_COMMITTED since that's all we ever write for
           * the logs.
           */
    // in case of asynchronous removals trigger the purger now.
    _purger.trigger();
    /*
           * Get a list of logs. Load them in to memory if we aren't already
           * working on them/it. But we can prune the entry once we're
           * finished or the memory footprint will grow. We should do this
           * for all frozen entries eventually too.
           */
    InputObjectState logs = new InputObjectState();
    OutputObjectState objUids = new OutputObjectState();
    if (!super.allObjUids(tName, logs, match))
        return false;
    else {
        /*
                * Now we have all of the log names let's attach to each one
                * and locate the committed instances (not deleted.)
                */
        Uid logName = new Uid(Uid.nullUid());
        try {
            do {
                logName = UidHelper.unpackFrom(logs);
                if (logName.notEquals(Uid.nullUid())) {
                    /*
                               * Could check to see if log is in current working memory.
                               */
                    /*
                               * TODO
                               *
                               * First purge the log if we can, but we need to know that
                               * we're not playing with an instance that is being manipulated
                               * from another VM instance.
                               */
                    ArrayList<InputObjectState> txs = scanLog(logName, tName);
                    if (txs.size() > 0) {
                        for (int i = 0; i < txs.size(); i++) {
                            UidHelper.packInto(txs.get(i).stateUid(), objUids);
                        }
                    }
                }
            } while (logName.notEquals(Uid.nullUid()));
            // remember null terminator
            UidHelper.packInto(Uid.nullUid(), objUids);
            state.setBuffer(objUids.buffer());
        } catch (final IOException ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) IOException(java.io.IOException)

Example 82 with InputObjectState

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

the class ActivationRecordUnitTest method test.

@Test
public void test() {
    AtomicAction A = new AtomicAction();
    AtomicAction B = new AtomicAction();
    A.begin();
    B.begin();
    ActivationRecord cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), B);
    assertFalse(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.ACTIVATION);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    assertEquals((Integer) cr.value(), new Integer(ObjectType.ANDPERSISTENT));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), B);
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    B.abort();
    cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), A);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), A);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new ActivationRecord();
    cr.merge(new ActivationRecord());
    cr.alter(new ActivationRecord());
    assertTrue(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
    assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
    A.abort();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Example 83 with InputObjectState

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

the class ExpiredTransactionScanner method moveEntry.

public boolean moveEntry(Uid newUid) throws ObjectStoreException {
    InputObjectState state = _recoveryStore.read_committed(newUid, _typeName);
    boolean res = false;
    if (// just in case recovery
    state != null) // kicked-in
    {
        boolean moved = _recoveryStore.write_committed(newUid, _movedTypeName, new OutputObjectState(state));
        if (!moved) {
            tsLogger.logger.debugf("Removing old transaction status manager item %s", newUid);
        } else {
            res = _recoveryStore.remove_committed(newUid, _typeName);
            tsLogger.i18NLogger.warn_recovery_ExpiredTransactionStatusManagerScanner_6(newUid);
        }
    }
    return res;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState)

Example 84 with InputObjectState

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

the class ExpiredTransactionStatusManagerScanner method scan.

/**
 * This is called periodically by the RecoveryManager
 */
public void scan() {
    // calculate the time before which items will be removed
    Date oldestSurviving = new Date(new Date().getTime() - _expiryTime * 1000);
    if (tsLogger.logger.isDebugEnabled()) {
        tsLogger.logger.debug("ExpiredTransactionStatusManagerScanner - scanning to remove items from before " + _timeFormat.format(oldestSurviving));
    }
    try {
        InputObjectState uids = new InputObjectState();
        // find the uids of all the transaction status manager items
        if (_recoveryStore.allObjUids(_itemTypeName, uids)) {
            Uid theUid = null;
            boolean endOfUids = false;
            while (!endOfUids) {
                // extract a uid
                theUid = UidHelper.unpackFrom(uids);
                if (theUid.equals(Uid.nullUid()))
                    endOfUids = true;
                else {
                    Uid newUid = new Uid(theUid);
                    TransactionStatusManagerItem tsmItem = TransactionStatusManagerItem.recreate(newUid);
                    if (tsmItem != null) {
                        Date timeOfDeath = tsmItem.getDeadTime();
                        if (timeOfDeath != null && timeOfDeath.before(oldestSurviving)) {
                            tsLogger.logger.debugf("Removing old transaction status manager item %s", newUid);
                            _recoveryStore.remove_committed(newUid, _itemTypeName);
                        } else {
                            // if it is not possible to establish a connection
                            // to the Transaction Status Managers' process
                            // then it is removed from the object store.
                            Uid currentUid = newUid;
                            String process_id = currentUid.getHexPid();
                            TransactionStatusConnector tsc = new TransactionStatusConnector(process_id, currentUid);
                            tsc.test(tsmItem);
                            if (tsc.isDead()) {
                                tsLogger.logger.debugf("Removing old transaction status manager item %s", newUid);
                                tsc.delete();
                                tsc = null;
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
    // end of uids!
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) Date(java.util.Date)

Example 85 with InputObjectState

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

the class DisposeRecordUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    DisposeRecord cr = new DisposeRecord(store, new ExtendedObject());
    assertFalse(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.DISPOSE);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), true);
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord(store, new ExtendedObject());
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord(store, new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord(store, new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord();
    assertFalse(cr.shouldAdd(new PersistenceRecord()));
    assertFalse(cr.shouldAlter(new PersistenceRecord()));
    assertFalse(cr.shouldMerge(new PersistenceRecord()));
    assertFalse(cr.shouldReplace(new PersistenceRecord()));
    assertFalse(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
    assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) Test(org.junit.Test)

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