Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix a livelock in TransactionManager #3156

Merged
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 @@ -240,6 +240,8 @@ public void commit(final Txn txn) throws TransactionException {
return;
}

boolean doneCommit = false;

// CAS loop
try {
while (true) {
Expand Down Expand Up @@ -269,11 +271,18 @@ public void commit(final Txn txn) throws TransactionException {
}

// if we are have active transactions and are not preempted by another thread, commit transaction
if (localState > STATE_IDLE && state.compareAndSet(localState, localState - 1)) {
doCommitTransaction(txn);
if (localState > STATE_IDLE) {
if (!doneCommit) {
doCommitTransaction(txn);
// NOTE: doCommitTransaction above might throw an exception before commit which will throw us out of the loop
doneCommit = txn.getState() == Txn.State.COMMITTED;
}

// done... exit CAS loop!
return;
// try and update our state to reflect that we have committed the transaction, if not then loop...
if (state.compareAndSet(localState, localState - 1)) {
// done... exit CAS loop!
return;
}
}
}
} catch (final InterruptedException e) {
Expand Down