-
Notifications
You must be signed in to change notification settings - Fork 40
Allow multiple calls to rollback() #2751
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the transaction managers to allow multiple calls to rollback() (and abort()) without throwing exceptions if the transaction is already rolled back. Key changes include:
- Updating the tests in both StateManagedTwoPhaseCommitTransactionManagerTest and StateManagedDistributedTransactionManagerTest to verify that repeated calls to rollback() and abort() behave as expected.
- Adjusting the logic in rollback() and abort() in both transaction manager classes so that calling these methods on a transaction that is already rolled back returns silently, and only throws an IllegalStateException if the transaction has been committed.
- Changing the error message in CoreError to reflect that only a committed transaction now raises an exception on subsequent rollback/abort calls.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| core/src/test/java/com/scalar/db/common/StateManagedTwoPhaseCommitTransactionManagerTest.java | Updated test names and assertions to verify non-exception behavior on repeated rollback/abort calls |
| core/src/test/java/com/scalar/db/common/StateManagedDistributedTransactionManagerTest.java | Mirrored the test updates for distributed transactions |
| core/src/main/java/com/scalar/db/common/error/CoreError.java | Changed error message constant to remove mention of rollback for already finalized transactions |
| core/src/main/java/com/scalar/db/common/StateManagedTwoPhaseCommitTransactionManager.java | Modified rollback() and abort() logic to allow multiple calls with appropriate exception handling |
| core/src/main/java/com/scalar/db/common/StateManagedDistributedTransactionManager.java | Similar changes as above to support multiple rollback/abort calls |
Comments suppressed due to low confidence (3)
core/src/main/java/com/scalar/db/common/StateManagedTwoPhaseCommitTransactionManager.java:184
- Consider adding a clarifying comment here to document that multiple calls to rollback() are now allowed and that subsequent calls return silently when the status is ROLLED_BACK.
if (status == Status.ROLLED_BACK) {
core/src/main/java/com/scalar/db/common/StateManagedDistributedTransactionManager.java:147
- Consider adding a comment to indicate that if the transaction is already rolled back, further calls to rollback() will return silently, which supports the new behavior.
if (status == Status.ROLLED_BACK) {
core/src/main/java/com/scalar/db/common/error/CoreError.java:217
- Ensure that the updated error message 'TRANSACTION_ALREADY_COMMITTED' and its usage properly communicate that the exception is raised only when the transaction has been committed, not when it has been rolled back.
TRANSACTION_ALREADY_COMMITTED(
feeblefakie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
| @Override | ||
| public void rollback() throws RollbackException { | ||
| if (status == Status.COMMITTED || status == Status.ROLLED_BACK) { | ||
| if (status == Status.ROLLED_BACK) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status seems to move to ROLLED_BACK even when rolling back the transaction fails. If users first receive an exception from rollback() and then try the second attempt, it will look like success while the transaction might not be rolled back. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, that’s okay. Even if rolling back a transaction fails, the transaction manager is expected to automatically and eventually roll back the transaction. So, I don’t think applications need to retry the rollback themselves. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Sounds good 👍
Torch3333
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
komamitsu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
Description
This PR updates the code to allow multiple calls to the
rollback()method of transaction objects, making it more convenient for application developers.Currently, if users call the
rollback()method multiple times, anIllegalArgumentExceptionis thrown, as shown below:However, in certain situations—especially in modular or layered code—this behavior can be inconvenient for developers.
This PR addresses that issue by making repeated calls to
rollback()safe.Related issues and/or PRs
N/A
Changes made
StateManagedDistributedTransactionManagerandStateManagedTwoPhaseCommitTransactionManagerto allow multiple calls to therollback()method.Checklist
Additional notes (optional)
N/A
Release notes
N/A