Skip to content

Conversation

@brfrn169
Copy link
Collaborator

@brfrn169 brfrn169 commented Jun 4, 2025

Description

This PR adds a beginReadOnly() method to DistributedTransactionManager to begin a transaction in read-only mode.
We do not add this method to TwoPhaseCommitTransactionManager because 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-mode feature branch, as the changes may cause compile errors in dependent projects. Once all implementations are complete, we will merge this feature branch into the master branch.

Related issues and/or PRs

N/A

Changes made

Added some inline comments. Please take a look for the details!

Checklist

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • I have considered whether similar issues could occur in other products, components, or modules if this PR is for bug fixes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

N/A

Release notes

N/A

@brfrn169 brfrn169 requested a review from Copilot June 4, 2025 06:27
@brfrn169 brfrn169 self-assigned this Jun 4, 2025
Copy link
Contributor

Copilot AI left a 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");
Copy link

Copilot AI Jun 4, 2025

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.

Copilot uses AI. Check for mistakes.
* 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;
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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.

Comment on lines +148 to +156
@Override
public DistributedTransaction beginReadOnly() {
throw new UnsupportedOperationException("implement later");
}

@Override
public DistributedTransaction beginReadOnly(String txId) {
throw new UnsupportedOperationException("implement later");
}
Copy link
Collaborator Author

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.

Comment on lines +112 to +120
@Override
public DistributedTransaction beginReadOnly() {
throw new UnsupportedOperationException("implement later");
}

@Override
public DistributedTransaction beginReadOnly(String txId) {
throw new UnsupportedOperationException("implement later");
}
Copy link
Collaborator Author

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.

Comment on lines +79 to +91
@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());
}
Copy link
Collaborator Author

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.

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

Copy link
Contributor

@Torch3333 Torch3333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@brfrn169 brfrn169 merged commit b180847 into support-begin-in-read-only-mode Jun 5, 2025
56 checks passed
@brfrn169 brfrn169 deleted the add-beginReadOnly-method-to-transaction-abstraction branch June 5, 2025 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants