Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adjusting checks of completionBits from SubordinateTransactionControl #17

Merged
merged 1 commit into from
Mar 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.atomic.AtomicInteger;

import javax.resource.spi.XATerminator;
import javax.transaction.HeuristicCommitException;
Expand Down Expand Up @@ -273,10 +272,6 @@ public <T> T getProviderInterface(final Transaction transaction, final Class<T>
return providerInterfaceType.isInstance(transaction) ? providerInterfaceType.cast(transaction) : null;
}

static final int BIT_BEFORE_COMP = 1 << 0;
static final int BIT_PREPARE_OR_ROLLBACK = 1 << 1;
static final int BIT_COMMIT_OR_FORGET = 1 << 2;

static final class XidKey implements Comparable<XidKey> {
private final SimpleXid gtid;
private final long expiration;
Expand All @@ -299,7 +294,6 @@ SimpleXid getId() {
final class Entry implements SubordinateTransactionControl {
private final SimpleXid gtid;
private final Transaction transaction;
private final AtomicInteger completionBits = new AtomicInteger(0);
private final XidKey xidKey;

Entry(final SimpleXid gtid, final Transaction transaction, final XidKey xidKey) {
Expand All @@ -320,27 +314,13 @@ void rollbackLocal() throws SystemException {
if (transaction instanceof ImportedTransaction) {
throw Log.log.rollbackOnImported();
}
int oldVal;
do {
oldVal = completionBits.get();
if ((oldVal & BIT_PREPARE_OR_ROLLBACK) != 0) {
throw Log.log.invalidTxnState();
}
} while (! completionBits.compareAndSet(oldVal, oldVal | BIT_PREPARE_OR_ROLLBACK | BIT_BEFORE_COMP));
transaction.rollback();
}

void commitLocal() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException {
if (transaction instanceof ImportedTransaction) {
throw Log.log.commitOnImported();
}
int oldVal;
do {
oldVal = completionBits.get();
if ((oldVal & BIT_PREPARE_OR_ROLLBACK) != 0 || (oldVal & BIT_COMMIT_OR_FORGET) != 0) {
throw Log.log.invalidTxnState();
}
} while (! completionBits.compareAndSet(oldVal, oldVal | BIT_COMMIT_OR_FORGET | BIT_PREPARE_OR_ROLLBACK | BIT_BEFORE_COMP));
transaction.commit();
}

Expand All @@ -358,13 +338,6 @@ public void rollback() throws XAException {
if (! (transaction instanceof ImportedTransaction)) {
throw Log.log.notImportedXa(XAException.XAER_NOTA);
}
int oldVal;
do {
oldVal = completionBits.get();
if ((oldVal & BIT_PREPARE_OR_ROLLBACK) != 0) {
throw Log.log.invalidTxStateXa(XAException.XAER_NOTA);
}
} while (! completionBits.compareAndSet(oldVal, oldVal | BIT_PREPARE_OR_ROLLBACK | BIT_BEFORE_COMP));
final ImportedTransaction importedTransaction = (ImportedTransaction) transaction;
if (importedTransaction.activated()) try {
importedTransaction.doRollback();
Expand Down Expand Up @@ -414,13 +387,6 @@ public void beforeCompletion() throws XAException {
if (! (transaction instanceof ImportedTransaction)) {
throw Log.log.notImportedXa(XAException.XAER_NOTA);
}
int oldVal;
do {
oldVal = completionBits.get();
if ((oldVal & BIT_BEFORE_COMP) != 0) {
throw Log.log.invalidTxStateXa(XAException.XAER_NOTA);
}
} while (! completionBits.compareAndSet(oldVal, oldVal | BIT_BEFORE_COMP));
final ImportedTransaction importedTransaction = (ImportedTransaction) transaction;
try {
if (! importedTransaction.doBeforeCompletion()) {
Expand All @@ -438,13 +404,6 @@ public int prepare() throws XAException {
if (! (transaction instanceof ImportedTransaction)) {
throw Log.log.notImportedXa(XAException.XAER_NOTA);
}
int oldVal;
do {
oldVal = completionBits.get();
if ((oldVal & BIT_PREPARE_OR_ROLLBACK) != 0) {
throw Log.log.invalidTxStateXa(XAException.XAER_NOTA);
}
} while (! completionBits.compareAndSet(oldVal, oldVal | BIT_PREPARE_OR_ROLLBACK | BIT_BEFORE_COMP));
final ImportedTransaction importedTransaction = (ImportedTransaction) transaction;
final int tpo = importedTransaction.doPrepare();
switch (tpo) {
Expand Down Expand Up @@ -484,13 +443,6 @@ public void forget() throws XAException {
if (! (transaction instanceof ImportedTransaction)) {
throw Log.log.notImportedXa(XAException.XAER_NOTA);
}
int oldVal;
do {
oldVal = completionBits.get();
if ((oldVal & BIT_COMMIT_OR_FORGET) != 0) {
throw Log.log.invalidTxStateXa(XAException.XAER_NOTA);
}
} while (! completionBits.compareAndSet(oldVal, oldVal | BIT_COMMIT_OR_FORGET | BIT_PREPARE_OR_ROLLBACK | BIT_BEFORE_COMP));
final ImportedTransaction importedTransaction = (ImportedTransaction) transaction;
try {
importedTransaction.doForget();
Expand All @@ -506,13 +458,6 @@ public void commit(final boolean onePhase) throws XAException {
if (! (transaction instanceof ImportedTransaction)) {
throw Log.log.notImportedXa(XAException.XAER_NOTA);
}
int oldVal;
do {
oldVal = completionBits.get();
if (onePhase && (oldVal & BIT_PREPARE_OR_ROLLBACK) != 0 || (oldVal & BIT_COMMIT_OR_FORGET) != 0) {
throw Log.log.invalidTxStateXa(XAException.XAER_NOTA);
}
} while (! completionBits.compareAndSet(oldVal, oldVal | BIT_COMMIT_OR_FORGET | BIT_PREPARE_OR_ROLLBACK | BIT_BEFORE_COMP));
final ImportedTransaction importedTransaction = (ImportedTransaction) transaction;
try {
if (onePhase) {
Expand Down