Skip to content

Conversation

@brfrn169
Copy link
Collaborator

@brfrn169 brfrn169 commented Jun 5, 2025

Description

This PR adds support for beginning a transaction in read-only mode for JDBC transactions.

Note that this feature is being developed in the support-begin-in-read-only-mode feature branch.

Related issues and/or PRs

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 5, 2025 05:38
@brfrn169 brfrn169 self-assigned this Jun 5, 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 adds support for starting JDBC transactions in read-only mode and updates related tests and execution logic.

  • Introduces beginReadOnly overloads and a unified begin(txId, readOnly) implementation
  • Updates executeTransaction to distinguish between read-only and read-write operations
  • Adjusts unit tests to cover read-only behavior and cleans up integration tests

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionManagerTest.java Added tests for beginReadOnly variants and updated scanner tests to use read-only transactions
core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionManager.java Added beginReadOnly methods, unified begin(txId, readOnly), and updated executeTransaction to accept a read-only flag
core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java Removed placeholder disabled tests for read-only integration scenarios
Comments suppressed due to low confidence (4)

core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java:42

  • Integration tests for read-only transactions have been removed; consider implementing and re-enabling tests to validate read-only begin methods in real database scenarios.
@Disabled("Implement later")

core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionManager.java:104

  • Public methods beginReadOnly and beginReadOnly(String) lack Javadoc comments; consider adding descriptions for their behavior and parameters.
public DistributedTransaction beginReadOnly() throws TransactionException {

core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionManager.java:114

  • [nitpick] Consider renaming the boolean parameter readOnly to isReadOnly for clearer intent in the method signature.
private DistributedTransaction begin(String txId, boolean readOnly) throws TransactionException {

core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionManager.java:376

  • [nitpick] The executeTransaction method now requires an explicit readOnly flag for each call; consider providing an overload without the flag (defaulting to write mode) to simplify calls for common write operations.
private <R> R executeTransaction(


DistributedTransaction transaction;
if (readOnly) {
rdbEngine.setReadOnly(connection, true);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Call Connection.setReadOnly() for read-only transactions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed the method name setReadOnly() seems to change the rdbEngine to read-only mode. setConnectionToReadOnly() might be less confusing. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 60c000f. Thanks!

Comment on lines +121 to +123
transaction =
new ReadOnlyDistributedTransaction(
new JdbcTransaction(txId, jdbcService, connection, rdbEngine));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wrap the transaction object with ReadOnlyDistributedTransaction.

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

@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

@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 c8230de into support-begin-in-read-only-mode Jun 9, 2025
55 checks passed
@brfrn169 brfrn169 deleted the support-begin-in-read-only-mode-for-jdbc-transaction branch June 9, 2025 07:38
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