Search in sources :

Example 1 with TransactionAbortedException

use of org.corfudb.runtime.exceptions.TransactionAbortedException in project CorfuDB by CorfuDB.

the class WriteWriteTXs method mixedReadWriteLoad1.

/**
     * generate a workload with mixed R/W TX's
     *   - NUM_BATCHES TX's
     *   - each TX performs BATCH_SZ operations, mixing R/W according to the specified ratio.
     *
     * @param readPrecent ratio of reads (to 100)
     */
void mixedReadWriteLoad1(int threadNum, int readPrecent) {
    System.out.print("running mixedRWload1..");
    long startt = System.currentTimeMillis();
    AtomicInteger aborts = new AtomicInteger(0);
    for (int i = 0; i < NUM_BATCHES; i++) {
        System.out.print(".");
        TXBegin();
        int accumulator = 0;
        for (int j = 0; j < BATCH_SZ; j++) {
            // perform random get()'s with probability 'readPercent/100'
            if (rand.nextInt(TOTAL_PERCENT) < readPrecent) {
                int r1 = rand.nextInt(numTasks);
                int r2 = rand.nextInt(numTasks);
                int r3 = rand.nextInt(numTasks);
                try {
                    accumulator += map1.get("m1" + r1);
                    accumulator += map2.get("m2" + r2);
                    accumulator += map3.get("m3" + r3);
                } catch (Exception e) {
                    System.out.println(threadNum + ": exception on iteration " + i + "," + j + ", r=" + r1 + "," + r2 + "," + r3);
                    e.printStackTrace();
                    return;
                }
            } else // otherwise, perform a random put()
            {
                if (rand.nextInt(2) == 1)
                    map2.put("m2" + rand.nextInt(numTasks), accumulator);
                else
                    map3.put("m3" + rand.nextInt(numTasks), accumulator);
            }
        }
        try {
            TXEnd();
        } catch (TransactionAbortedException te) {
            aborts.getAndIncrement();
        }
    }
    System.out.println("END");
    long endt = System.currentTimeMillis();
    System.out.println(threadNum + ": mixedReadWriteLoad elapsed time (msecs): " + (endt - startt));
    System.out.println(threadNum + ":   #aborts/#TXs: " + aborts.get() + "/" + numTasks);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException)

Example 2 with TransactionAbortedException

use of org.corfudb.runtime.exceptions.TransactionAbortedException 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 3 with TransactionAbortedException

use of org.corfudb.runtime.exceptions.TransactionAbortedException 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 4 with TransactionAbortedException

use of org.corfudb.runtime.exceptions.TransactionAbortedException in project CorfuDB by CorfuDB.

the class StreamTest method concurrentStreamRWLoad.

/**
     * generate a workload with mixed R/W TX's
     *   - NUM_BATCHES TX's
     *   - each TX performs BATCH_SZ operations, mixing R/W according to the specified ratio.
     *
     * @param readPrecent ratio of reads (to 100)
     */
public void concurrentStreamRWLoad(int ignoredThreadNum, int readPrecent) {
    final AtomicInteger aborts = new AtomicInteger(0);
    for (int i = 0; i < NUM_BATCHES; i++) {
        final int fi = i;
        addTestStep(task_num -> {
            WWTXBegin();
        });
        for (int j = 0; j < BATCH_SZ; j++) {
            final int fj = j;
            addTestStep(task_num -> {
                int r1 = rand.nextInt(numTasks);
                int r2 = rand.nextInt(numTasks);
                int r3 = rand.nextInt(numTasks);
                int accumulator = 0;
                accumulator += map1.get("m1" + r1);
                accumulator += map2.get("m2" + r2);
                accumulator += map3.get("m3" + r3);
                if (rand.nextInt(MAX_PERCENT) >= readPrecent) {
                    if (rand.nextInt(2) == 1)
                        map2.put("m2" + rand.nextInt(numTasks), accumulator);
                    else
                        map3.put("m3" + rand.nextInt(numTasks), accumulator);
                }
            });
        }
        addTestStep(task_num -> {
            try {
                TXEnd();
            } catch (TransactionAbortedException te) {
                aborts.getAndIncrement();
            }
        });
    }
    addTestStep(task_num -> calculateAbortRate(aborts.get(), numTasks));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException)

Example 5 with TransactionAbortedException

use of org.corfudb.runtime.exceptions.TransactionAbortedException in project CorfuDB by CorfuDB.

the class TXConflictScenariosTest method testNoWriteConflictSimple.

void testNoWriteConflictSimple() throws Exception {
    final CorfuSharedCounter sharedCounter1 = instantiateCorfuObject(CorfuSharedCounter.class, "test" + 1);
    final CorfuSharedCounter sharedCounter2 = instantiateCorfuObject(CorfuSharedCounter.class, "test" + 2);
    commitStatus = new AtomicIntegerArray(2);
    t(1, this::TXBegin);
    t(2, this::TXBegin);
    t(1, () -> {
        sharedCounter1.setValue(OVERWRITE_ONCE);
    });
    t(2, () -> {
        sharedCounter2.setValue(OVERWRITE_ONCE);
    });
    t(1, () -> sharedCounter1.getValue());
    t(2, () -> sharedCounter2.getValue());
    t(1, () -> sharedCounter2.getValue());
    t(2, () -> sharedCounter1.getValue());
    t(1, () -> {
        sharedCounter1.setValue(OVERWRITE_TWICE);
    });
    t(2, () -> {
        sharedCounter2.setValue(OVERWRITE_TWICE);
    });
    t(1, () -> sharedCounter1.getValue());
    t(1, () -> sharedCounter2.getValue());
    t(2, () -> sharedCounter2.getValue());
    t(2, () -> sharedCounter1.getValue());
    t(1, () -> {
        try {
            TXEnd();
            commitStatus.set(0, COMMITVALUE);
        } catch (TransactionAbortedException tae) {
        // do nothing
        }
    });
    t(2, () -> {
        try {
            TXEnd();
            commitStatus.set(1, COMMITVALUE);
        } catch (TransactionAbortedException tae) {
        // do nothing
        }
    });
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) CorfuSharedCounter(org.corfudb.runtime.object.CorfuSharedCounter) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException)

Aggregations

TransactionAbortedException (org.corfudb.runtime.exceptions.TransactionAbortedException)12 TypeToken (com.google.common.reflect.TypeToken)6 Test (org.junit.Test)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 TxResolutionInfo (org.corfudb.protocols.wireprotocol.TxResolutionInfo)3 AbstractTransactionalContext (org.corfudb.runtime.object.transactions.AbstractTransactionalContext)3 Semaphore (java.util.concurrent.Semaphore)2 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)2 SMRMap (org.corfudb.runtime.collections.SMRMap)2 AbortCause (org.corfudb.runtime.exceptions.AbortCause)2 NetworkException (org.corfudb.runtime.exceptions.NetworkException)2 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)1 CorfuSharedCounter (org.corfudb.runtime.object.CorfuSharedCounter)1 ObjectsView (org.corfudb.runtime.view.ObjectsView)1