use of org.corfudb.runtime.object.transactions.AbstractTransactionalContext in project CorfuDB by CorfuDB.
the class ObjectsView method TXAbort.
/**
* Aborts a transaction on the current thread.
* Modifications to objects in the current transactional
* context will be discarded.
*/
public void TXAbort() {
AbstractTransactionalContext context = TransactionalContext.getCurrentContext();
if (context == null) {
log.warn("Attempted to abort a transaction, but no transaction active!");
} else {
TxResolutionInfo txInfo = new TxResolutionInfo(context.getTransactionID(), context.getSnapshotTimestamp());
context.abortTransaction(new TransactionAbortedException(txInfo, null, AbortCause.USER));
TransactionalContext.removeContext();
}
}
use of org.corfudb.runtime.object.transactions.AbstractTransactionalContext in project CorfuDB by CorfuDB.
the class ObjectsView method TXEnd.
/**
* End a transaction on the current thread.
*
* @throws TransactionAbortedException If the transaction could not be executed successfully.
*
* @return The address of the transaction, if it commits.
*/
public long TXEnd() throws TransactionAbortedException {
AbstractTransactionalContext context = TransactionalContext.getCurrentContext();
if (context == null) {
log.warn("Attempted to end a transaction, but no transaction active!");
return AbstractTransactionalContext.UNCOMMITTED_ADDRESS;
} else {
// TODO remove this, doesn't belong here!
long totalTime = System.currentTimeMillis() - context.getStartTime();
log.trace("TXCommit[{}] time={} ms", context, totalTime);
// TODO up to here
try {
return TransactionalContext.getCurrentContext().commitTransaction();
} catch (TransactionAbortedException e) {
TransactionalContext.getCurrentContext().abortTransaction(e);
throw e;
} catch (Exception e) {
log.trace("TXCommit[{}] Exception {}", context, e);
AbortCause abortCause;
if (e instanceof NetworkException) {
abortCause = AbortCause.NETWORK;
} else {
abortCause = AbortCause.UNDEFINED;
}
long snapshot_timestamp;
try {
snapshot_timestamp = context.getSnapshotTimestamp();
} catch (NetworkException ne) {
snapshot_timestamp = -1L;
}
TxResolutionInfo txInfo = new TxResolutionInfo(context.getTransactionID(), snapshot_timestamp);
TransactionAbortedException tae = new TransactionAbortedException(txInfo, null, abortCause);
context.abortTransaction(tae);
throw tae;
} finally {
TransactionalContext.removeContext();
}
}
}
use of org.corfudb.runtime.object.transactions.AbstractTransactionalContext in project CorfuDB by CorfuDB.
the class CheckpointWriter method startCheckpoint.
/** Append a checkpoint START record to this object's stream.
*
* Corfu client transaction management, if desired, is the
* caller's responsibility.
*
* @return Global log address of the START record.
*/
public long startCheckpoint() {
startTime = LocalDateTime.now();
AbstractTransactionalContext context = TransactionalContext.getCurrentContext();
long txBeginGlobalAddress = context.getSnapshotTimestamp();
this.mdKV.put(CheckpointEntry.CheckpointDictKey.START_TIME, startTime.toString());
this.mdKV.put(CheckpointEntry.CheckpointDictKey.START_LOG_ADDRESS, Long.toString(txBeginGlobalAddress));
ImmutableMap<CheckpointEntry.CheckpointDictKey, String> mdKV = ImmutableMap.copyOf(this.mdKV);
CheckpointEntry cp = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.START, author, checkpointID, mdKV, null);
startAddress = sv.append(Collections.singleton(streamID), cp, null);
postAppendFunc.accept(cp, startAddress);
return startAddress;
}
use of org.corfudb.runtime.object.transactions.AbstractTransactionalContext in project CorfuDB by CorfuDB.
the class CorfuCompileProxy method abortTransaction.
private void abortTransaction(Exception e) {
long snapshot_timestamp;
AbortCause abortCause;
AbstractTransactionalContext context = TransactionalContext.getCurrentContext();
if (e instanceof NetworkException) {
// If a 'NetworkException' was received within a transactional context, an attempt to
// 'getSnapshotTimestamp' will also fail (as it requests it to the Sequencer). A new NetworkException
// would prevent the earliest to be propagated and encapsulated as a TransactionAbortedException.
snapshot_timestamp = -1L;
abortCause = AbortCause.NETWORK;
} else {
snapshot_timestamp = context.getSnapshotTimestamp();
abortCause = AbortCause.UNDEFINED;
}
TxResolutionInfo txInfo = new TxResolutionInfo(context.getTransactionID(), snapshot_timestamp);
TransactionAbortedException tae = new TransactionAbortedException(txInfo, null, abortCause);
context.abortTransaction(tae);
TransactionalContext.removeContext();
throw tae;
}
use of org.corfudb.runtime.object.transactions.AbstractTransactionalContext in project CorfuDB by CorfuDB.
the class CheckpointWriter method startGlobalSnapshotTxn.
public static long startGlobalSnapshotTxn(CorfuRuntime rt) {
TokenResponse tokenResponse = rt.getSequencerView().nextToken(Collections.EMPTY_SET, 0);
long globalTail = tokenResponse.getToken().getTokenValue();
rt.getObjectsView().TXBuild().setType(TransactionType.SNAPSHOT).setSnapshot(globalTail).begin();
AbstractTransactionalContext context = TransactionalContext.getCurrentContext();
return context.getSnapshotTimestamp();
}
Aggregations