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);
}
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();
}
}
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();
}
}
}
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));
}
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
}
});
}
Aggregations