use of org.ballerinalang.util.transactions.LocalTransactionInfo in project ballerina by ballerina-lang.
the class CPU method endTransaction.
private static void endTransaction(WorkerExecutionContext ctx, int transactionBlockId, int status) {
LocalTransactionInfo localTransactionInfo = ctx.getLocalTransactionInfo();
boolean isGlobalTransactionEnabled = ctx.getGlobalTransactionEnabled();
boolean notifyCoordinator;
try {
// In success case no need to do anything as with the transaction end phase it will be committed.
if (status == TransactionStatus.FAILED.value()) {
notifyCoordinator = localTransactionInfo.onTransactionFailed(ctx, transactionBlockId);
if (notifyCoordinator) {
if (isGlobalTransactionEnabled) {
TransactionUtils.notifyTransactionAbort(ctx, localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
} else {
TransactionResourceManager.getInstance().notifyAbort(localTransactionInfo.getGlobalTransactionId(), transactionBlockId, false);
}
}
} else if (status == TransactionStatus.ABORTED.value()) {
if (isGlobalTransactionEnabled) {
TransactionUtils.notifyTransactionAbort(ctx, localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
} else {
TransactionResourceManager.getInstance().notifyAbort(localTransactionInfo.getGlobalTransactionId(), transactionBlockId, false);
}
} else if (status == TransactionStatus.SUCCESS.value()) {
// it will commit at the end message
if (!isGlobalTransactionEnabled) {
TransactionResourceManager.getInstance().prepare(localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
TransactionResourceManager.getInstance().notifyCommit(localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
}
} else if (status == TransactionStatus.END.value()) {
// status = 1 Transaction end
boolean isOuterTx = localTransactionInfo.onTransactionEnd(transactionBlockId);
if (isGlobalTransactionEnabled) {
TransactionUtils.notifyTransactionEnd(ctx, localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
}
if (isOuterTx) {
BLangVMUtils.removeTransactionInfo(ctx);
}
}
} catch (Throwable e) {
ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
handleError(ctx);
}
}
use of org.ballerinalang.util.transactions.LocalTransactionInfo in project ballerina by ballerina-lang.
the class CPU method retryTransaction.
private static void retryTransaction(WorkerExecutionContext ctx, int transactionBlockId, int startOfAbortIP, int startOfNoThrowEndIP) {
LocalTransactionInfo localTransactionInfo = ctx.getLocalTransactionInfo();
if (!localTransactionInfo.isRetryPossible(ctx, transactionBlockId)) {
if (ctx.getError() == null) {
ctx.ip = startOfNoThrowEndIP;
} else {
if (BLangVMErrors.TRANSACTION_ERROR.equals(ctx.getError().getStringField(0))) {
ctx.ip = startOfNoThrowEndIP;
} else {
ctx.ip = startOfAbortIP;
}
}
}
localTransactionInfo.incrementCurrentRetryCount(transactionBlockId);
}
Aggregations