-
Notifications
You must be signed in to change notification settings - Fork 40
Add beginReadOnly() method to transaction abstraction #2734
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
Add beginReadOnly() method to transaction abstraction #2734
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 introduces the beginReadOnly() method to the transaction abstraction along with supporting tests and service API updates. Key changes include:
- Adding read-only transaction methods in various transaction managers and the TransactionService API.
- Implementing read-only transaction behavior by raising UnsupportedOperationExceptions (or placeholders for future work) in managers that do not yet support read-only transactions.
- Updating integration tests to cover and disable read-only transaction scenarios.
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| integration-test/src/main/java/com/scalar/db/transaction/singlecrudoperation/SingleCrudOperationTransactionIntegrationTestBase.java | Added disabled tests for read-only transactions in single CRUD operations. |
| integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java | Added disabled read-only tests for consensus commit transactions. |
| integration-test/src/main/java/com/scalar/db/api/DistributedTransactionIntegrationTestBase.java | Added enabled tests for read-only transactions in distributed transactions. |
| core/src/main/java/com/scalar/db/transaction/singlecrudoperation/SingleCrudOperationTransactionManager.java | Implemented read-only methods that throw an unsupported exception. |
| core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionManager.java | Introduced placeholder read-only methods with "implement later" messages. |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitManager.java | Introduced placeholder read-only methods with "implement later" messages. |
| core/src/main/java/com/scalar/db/service/TransactionService.java | Delegated beginning of read-only transactions to the manager. |
| core/src/main/java/com/scalar/db/common/error/CoreError.java | Added a new error code for mutation operations in read-only transactions. |
| Other files | Added annotations and API documentation updates to support the new read-only transaction methods. |
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly() { | ||
| throw new UnsupportedOperationException("implement later"); |
Copilot
AI
Jun 4, 2025
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.
Consider replacing the placeholder error message with a more descriptive and consistent message (or a reference to a constant error code) similar to the one used in the SingleCrudOperationTransactionManager.
core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitManager.java
Show resolved
Hide resolved
| * faults. You can try retrying the transaction, but you may not be able to begin the | ||
| * transaction due to nontransient faults | ||
| */ | ||
| DistributedTransaction beginReadOnly() throws TransactionNotFoundException, TransactionException; |
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.
Added several methods for the read-only mode.
| import javax.annotation.concurrent.NotThreadSafe; | ||
|
|
||
| @NotThreadSafe | ||
| public class ReadOnlyDistributedTransaction extends DecoratedDistributedTransaction { |
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.
Added a wrapper class to enforce immutability for read-only transactions.
| @Override | ||
| public DistributedTransaction beginReadOnly() { | ||
| throw new UnsupportedOperationException("implement later"); | ||
| } | ||
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly(String txId) { | ||
| throw new UnsupportedOperationException("implement later"); | ||
| } |
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 will add an implementation for Consensus Commit in a separate PR after this PR is merged.
| @Override | ||
| public DistributedTransaction beginReadOnly() { | ||
| throw new UnsupportedOperationException("implement later"); | ||
| } | ||
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly(String txId) { | ||
| throw new UnsupportedOperationException("implement later"); | ||
| } |
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 will add an implementation for JDBC transactions in a separate PR after this PR is merged.
| @Override | ||
| public DistributedTransaction beginReadOnly() throws TransactionException { | ||
| throw new UnsupportedOperationException( | ||
| CoreError.SINGLE_CRUD_OPERATION_TRANSACTION_BEGINNING_TRANSACTION_NOT_ALLOWED | ||
| .buildMessage()); | ||
| } | ||
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly(String txId) throws TransactionException { | ||
| throw new UnsupportedOperationException( | ||
| CoreError.SINGLE_CRUD_OPERATION_TRANSACTION_BEGINNING_TRANSACTION_NOT_ALLOWED | ||
| .buildMessage()); | ||
| } |
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.
For the Single Crud Operation transaction manager, just throw UnsupportedOperationException, since the Single Crud Operation transaction manager doesn't support beginning transactions.
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!
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! 👍
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!
Description
This PR adds a
beginReadOnly()method toDistributedTransactionManagerto begin a transaction in read-only mode.We do not add this method to
TwoPhaseCommitTransactionManagerbecause ensuring and managing read-only behavior across multiple transaction managers is challenging.Please note that this feature is being developed in the
support-begin-in-read-only-modefeature branch, as the changes may cause compile errors in dependent projects. Once all implementations are complete, we will merge this feature branch into themasterbranch.Related issues and/or PRs
N/A
Changes made
Added some inline comments. Please take a look for the details!
Checklist
Additional notes (optional)
N/A
Release notes
N/A