Search in sources :

Example 1 with TxResolutionInfo

use of org.corfudb.protocols.wireprotocol.TxResolutionInfo 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();
    }
}
Also used : TxResolutionInfo(org.corfudb.protocols.wireprotocol.TxResolutionInfo) AbstractTransactionalContext(org.corfudb.runtime.object.transactions.AbstractTransactionalContext) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException)

Example 2 with TxResolutionInfo

use of org.corfudb.protocols.wireprotocol.TxResolutionInfo 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();
        }
    }
}
Also used : TxResolutionInfo(org.corfudb.protocols.wireprotocol.TxResolutionInfo) AbstractTransactionalContext(org.corfudb.runtime.object.transactions.AbstractTransactionalContext) AbortCause(org.corfudb.runtime.exceptions.AbortCause) NetworkException(org.corfudb.runtime.exceptions.NetworkException) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException) NetworkException(org.corfudb.runtime.exceptions.NetworkException)

Example 3 with TxResolutionInfo

use of org.corfudb.protocols.wireprotocol.TxResolutionInfo 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;
}
Also used : TxResolutionInfo(org.corfudb.protocols.wireprotocol.TxResolutionInfo) AbstractTransactionalContext(org.corfudb.runtime.object.transactions.AbstractTransactionalContext) AbortCause(org.corfudb.runtime.exceptions.AbortCause) NetworkException(org.corfudb.runtime.exceptions.NetworkException) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException)

Aggregations

TxResolutionInfo (org.corfudb.protocols.wireprotocol.TxResolutionInfo)3 TransactionAbortedException (org.corfudb.runtime.exceptions.TransactionAbortedException)3 AbstractTransactionalContext (org.corfudb.runtime.object.transactions.AbstractTransactionalContext)3 AbortCause (org.corfudb.runtime.exceptions.AbortCause)2 NetworkException (org.corfudb.runtime.exceptions.NetworkException)2