use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class LogStore method removeState.
boolean removeState(Uid u, String tn, int s) throws ObjectStoreException {
try {
OutputObjectState removalState = new OutputObjectState(u, tn);
removalState.packBytes(_removedState);
if (!write_state(u, tn, removalState, s))
throw new ObjectStoreException();
} catch (IOException ex) {
throw new ObjectStoreException(ex.toString(), ex);
}
return true;
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class LogStore method scanLog.
private final ArrayList<InputObjectState> scanLog(final Uid logName, final String typeName) throws ObjectStoreException {
synchronized (_lock) {
try {
String fname = genPathName(logName, typeName, StateStatus.OS_COMMITTED);
File fd = openAndLock(fname, FileLock.F_WRLCK, true);
RandomAccessFile iFile = new RandomAccessFile(fd, FILE_MODE);
try {
/*
* Create a list of ObjectState entries.
*/
ArrayList<InputObjectState> objectStates = new ArrayList<InputObjectState>();
// make sure we're at the start
iFile.seek(0);
while (iFile.getFilePointer() < iFile.length()) {
byte[] buff = new byte[_redzone.length];
iFile.read(buff);
if (!redzoneProtected(buff)) {
break;
/*
* TODO add an end-of-log entry and check for that. Currently just assume
* that no RZ means end, rather than corruption.
*/
} else {
int uidSize = iFile.readInt();
byte[] uidString = new byte[uidSize];
iFile.read(uidString);
Uid txId = new Uid(new String(uidString, StandardCharsets.UTF_8));
int imageSize = iFile.readInt();
byte[] imageState = new byte[imageSize];
iFile.read(imageState);
try {
InputObjectState state = new InputObjectState(txId, "", imageState);
objectStates.add(state);
} catch (final Exception ex) {
ex.printStackTrace();
throw new ObjectStoreException(ex.toString(), ex);
}
}
}
unlockAndClose(fd, iFile);
iFile = null;
/*
* At this stage we now have a list of ObjectState entries.
* Now we need to go through and prune the list. This is
* complicated by the fact that there can be 1.. entries for
* a specific transaction since we continually update the
* log as we drive recovery. If an entry hasn't been deleted
* then we will keep the latest one we find.
*/
/*
* First search for those entries that have been deleted.
*/
ArrayList<InputObjectState> deletedLogs = new ArrayList<InputObjectState>();
for (int i = 0; i < objectStates.size(); i++) {
InputObjectState curr = objectStates.get(i);
try {
if (Arrays.equals(curr.unpackBytes(), _removedState)) {
deletedLogs.add(curr);
} else
// don't forget to reset the read pointer!
curr.reread();
} catch (final Exception ex) {
// if not a delete record then the first entry won't
// be an the defined byte array.
// don't forget to reset the read pointer!
curr.reread();
}
}
if (deletedLogs.size() > 0) {
/*
* make sure we remove them from the first list to save time.
*/
objectStates.removeAll(deletedLogs);
deleteEntries(objectStates, deletedLogs);
/*
* At this stage we should only have entries that refer
* to in-flight transactions. Go through the list and
* remove N-1 references for each transaction id.
*/
pruneEntries(objectStates);
return objectStates;
} else
return objectStates;
} finally {
if (iFile != null)
unlockAndClose(fd, iFile);
}
} catch (final ObjectStoreException ex) {
ex.printStackTrace();
throw ex;
} catch (final Exception ex) {
ex.printStackTrace();
throw new ObjectStoreException(ex.toString(), ex);
}
}
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class TwoPhaseVolatileStore method commit_state.
/**
* Commit the object's state in the object store.
*
* @param u The object to work on.
* @param tn The type of the object to work on.
* @return <code>true</code> if no errors occurred, <code>false</code>
* otherwise.
*/
public boolean commit_state(Uid u, String tn) throws ObjectStoreException {
synchronized (_stateMap) {
StateInstance inst = _stateMap.get(u);
if (inst == null)
throw new ObjectStoreException("Could not find state instance to commit!");
synchronized (inst) {
if (inst.shadow != null) {
inst.original = inst.shadow;
inst.shadow = null;
return true;
} else
return false;
}
}
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class CadaverRecord method topLevelCommit.
/**
* At topLevelCommit we commit the uncommitted version already saved
* into object participantStore.
* Cannot use inherited version since that assumes object is alive
* instead talk directly to the object participantStore itself.
*/
public int topLevelCommit() {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("CadaverRecord::topLevelCommit() for " + order());
}
boolean res = true;
OutputObjectState oState = super.state;
if ((oState != null) && (oType == RecordType.PERSISTENCE)) {
if (targetParticipantStore == null)
return TwoPhaseOutcome.FINISH_ERROR;
try {
res = targetParticipantStore.commit_state(oState.stateUid(), oState.type());
} catch (ObjectStoreException e) {
res = false;
}
}
return ((res) ? TwoPhaseOutcome.FINISH_OK : TwoPhaseOutcome.FINISH_ERROR);
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class TxLogWritePersistenceRecord method topLevelPrepare.
/**
* topLevelPrepare attempts to save the object.
* It will either do this in the action intention list or directly
* in the object store by using the 'deactivate' function of the object
* depending upon the size of the state.
* To ensure that objects are correctly hidden while they are in an
* uncommitted state if we use the abbreviated protocol then we write an
* EMPTY object state as the shadow state - THIS MUST NOT BE COMMITTED.
* Instead we write_committed the one saved in the intention list.
* If the store cannot cope with being given an empty state we revert to
* the old protocol.
*/
public int topLevelPrepare() {
int result = TwoPhaseOutcome.PREPARE_NOTOK;
StateManager sm = super.objectAddr;
LogWriteStateManager lwsm = null;
boolean writeToLog = true;
try {
lwsm = (LogWriteStateManager) sm;
writeToLog = lwsm.writeOptimisation();
} catch (ClassCastException ex) {
writeToLog = false;
}
if ((sm != null) && (targetParticipantStore != null)) {
topLevelState = new OutputObjectState(sm.get_uid(), sm.type());
if (writeToLog || (!targetParticipantStore.fullCommitNeeded() && (sm.save_state(topLevelState, ObjectType.ANDPERSISTENT)) && (topLevelState.size() <= PersistenceRecord.MAX_OBJECT_SIZE))) {
if (PersistenceRecord.classicPrepare) {
OutputObjectState dummy = new OutputObjectState(Uid.nullUid(), null);
try {
targetParticipantStore.write_uncommitted(sm.get_uid(), sm.type(), dummy);
result = TwoPhaseOutcome.PREPARE_OK;
} catch (ObjectStoreException e) {
tsLogger.i18NLogger.warn_PersistenceRecord_21(e);
}
dummy = null;
} else {
result = TwoPhaseOutcome.PREPARE_OK;
}
} else {
if (sm.deactivate(targetParticipantStore.getStoreName(), false)) {
shadowMade = true;
result = TwoPhaseOutcome.PREPARE_OK;
} else {
tsLogger.i18NLogger.warn_PersistenceRecord_7();
}
}
} else {
tsLogger.i18NLogger.warn_PersistenceRecord_8();
}
return result;
}
Aggregations