use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class LogStore method write_state.
/**
* write_state saves the ObjectState in a file named by the type and Uid of
* the ObjectState. If the second argument is SHADOW, then the file name is
* different so that a subsequent commit_state invocation will rename the
* file.
*
* We need to make sure that each entry is written to the next empty location
* in the log even if there's already an entry for this tx.
*/
protected boolean write_state(Uid objUid, String tName, OutputObjectState state, int ft) throws ObjectStoreException {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("ShadowingStore.write_state(" + objUid + ", " + tName + ", " + StateType.stateTypeString(ft) + ")");
}
String fname = null;
File fd = null;
if (tName != null) {
int imageSize = (int) state.length();
byte[] uidString = objUid.stringForm().getBytes(StandardCharsets.UTF_8);
// don't put in endOfLog since we keep overwriting that.
int buffSize = _redzone.length + uidString.length + imageSize + 8;
RandomAccessFile ofile = null;
java.nio.channels.FileLock lock = null;
if (imageSize > 0) {
// always adds entry to log
TransactionData theLogEntry = getLogName(objUid, tName, buffSize);
LogInstance theLog = theLogEntry.container;
if (theLog == null)
throw new ObjectStoreException();
fname = genPathName(theLog.getName(), tName, ft);
fd = openAndLock(fname, FileLock.F_WRLCK, true);
if (fd == null) {
tsLogger.i18NLogger.warn_objectstore_ShadowingStore_18(fname);
return false;
}
boolean setLength = !fd.exists();
try {
ofile = new RandomAccessFile(fd, FILE_MODE);
if (setLength) {
ofile.setLength(_maxFileSize);
} else {
if (theLog.remaining() < buffSize) {
long size = ofile.length() + buffSize - theLog.remaining();
ofile.setLength(size);
theLog.resize(size);
}
}
java.nio.ByteBuffer buff = java.nio.ByteBuffer.allocate(buffSize);
buff.put(_redzone);
buff.putInt(uidString.length);
buff.put(uidString);
buff.putInt(imageSize);
buff.put(state.buffer());
synchronized (_lock) {
ofile.seek(theLogEntry.offset);
ofile.write(buff.array());
}
} catch (SyncFailedException e) {
unlockAndClose(fd, ofile);
throw new ObjectStoreException("ShadowingStore::write_state() - write failed to sync for " + fname, e);
} catch (FileNotFoundException e) {
unlockAndClose(fd, ofile);
e.printStackTrace();
throw new ObjectStoreException("ShadowingStore::write_state() - write failed to locate file " + fname + ": " + e, e);
} catch (IOException e) {
unlockAndClose(fd, ofile);
e.printStackTrace();
throw new ObjectStoreException("ShadowingStore::write_state() - write failed for " + fname + ": " + e, e);
} finally {
try {
if (lock != null)
lock.release();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
if (!unlockAndClose(fd, ofile)) {
tsLogger.i18NLogger.warn_objectstore_ShadowingStore_19(fname);
}
super.addToCache(fname);
return true;
} else
throw new ObjectStoreException("ShadowStore::write_state - " + tsLogger.i18NLogger.get_objectstore_notypenameuid() + objUid);
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class LogStore method allObjUids.
public final InputObjectState allObjUids() throws ObjectStoreException {
OutputObjectState state = new OutputObjectState();
Iterator<Uid> iter = _ids.keySet().iterator();
try {
while (iter.hasNext()) {
UidHelper.packInto(iter.next(), state);
}
// don't forget to null terminate
UidHelper.packInto(Uid.nullUid(), state);
} catch (final IOException ex) {
throw new ObjectStoreException(ex);
}
return new InputObjectState(state);
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class LogStore method remove_state.
/**
* Does nothing except indicate that this thread is finished with the log on
* behalf of this transaction.
*/
protected boolean remove_state(Uid u, String tn, int s) throws ObjectStoreException {
try {
if (_synchronousRemoval) {
OutputObjectState removalState = new OutputObjectState(u, tn);
removalState.packBytes(_removedState);
if (!write_state(u, tn, removalState, s))
throw new ObjectStoreException();
} else
_purger.addRemovedState(u, tn, s);
} catch (IOException ex) {
throw new ObjectStoreException(ex.toString(), ex);
} catch (final Throwable ex) {
ex.printStackTrace();
throw new ObjectStoreException(ex.toString(), ex);
} finally {
removeFromLog(u);
}
return true;
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class PersistenceRecord method topLevelAbort.
/**
* topLevelAbort may have to remove the persistent state that was written
* into the object store during the processing of topLevelPrepare. It then
* does the standard abort processing.
*/
public int topLevelAbort() {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("PersistenceRecord::topLevelAbort() for " + order());
}
Uid uid = null;
String type = null;
if (// state written by StateManager instance
shadowMade) {
uid = order();
type = getTypeOfObject();
} else {
if (// hasn't been prepared, so no state
topLevelState == null) {
return nestedAbort();
} else {
uid = topLevelState.stateUid();
type = topLevelState.type();
}
}
try {
if (!targetParticipantStore.remove_uncommitted(uid, type)) {
tsLogger.i18NLogger.warn_PersistenceRecord_19();
return TwoPhaseOutcome.FINISH_ERROR;
}
} catch (ObjectStoreException e) {
tsLogger.i18NLogger.warn_PersistenceRecord_20(e);
return TwoPhaseOutcome.FINISH_ERROR;
}
return nestedAbort();
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class CadaverRecord method topLevelPrepare.
/**
* At topLevelPrepare write uncommitted version into object participantStore.
* Cannot use inherited version since that assumes object is alive
* instead talk directly to the object participantStore itself.
*/
public int topLevelPrepare() {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("CadaverRecord::topLevelPrepare() for " + order());
}
int tlpOk = TwoPhaseOutcome.PREPARE_NOTOK;
OutputObjectState oState = (newStateIsValid ? super.state : oldState);
if (oState != null) {
if (oType == RecordType.PERSISTENCE) {
if (targetParticipantStore == null)
return TwoPhaseOutcome.PREPARE_NOTOK;
try {
if (targetParticipantStore.write_uncommitted(oState.stateUid(), oState.type(), oState)) {
if (shadowForced())
tlpOk = TwoPhaseOutcome.PREPARE_OK;
}
} catch (final ObjectStoreException e) {
e.printStackTrace();
}
} else
tlpOk = TwoPhaseOutcome.PREPARE_OK;
}
return tlpOk;
}
Aggregations