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;
}
}
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();
}
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;
}
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!
}
}
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));
}
Aggregations