Skip to content

Conversation

@brfrn169
Copy link
Collaborator

@brfrn169 brfrn169 commented May 14, 2025

Description

This PR updates the JDBC storage to use Connection.setReadOnly() to optimize read operations.

For details about the Connection.setReadOnly() method, see:
https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setReadOnly-boolean-

Related issues and/or PRs

N/A

Changes made

  • Updated the JDBC storage to use Connection.setReadOnly() for the Get and Scan operations.

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 self-assigned this May 14, 2025
@brfrn169 brfrn169 requested a review from Copilot May 14, 2025 07:47
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 optimizes JDBC storage by enabling connection read-only mode for Get and Scan operations to potentially improve performance.

  • Updated tests to assert the default read-only flag and verify that connection.setReadOnly(true) is invoked.
  • Modified the JdbcUtils and JdbcDatabase classes to set default read-only configuration and mark connections as read-only on demand.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
core/src/test/java/com/scalar/db/storage/jdbc/JdbcUtilsTest.java Added assertions for default read-only flag in the data source.
core/src/test/java/com/scalar/db/storage/jdbc/JdbcDatabaseTest.java Verified that connection.setReadOnly(true) is called during Get and Scan operations.
core/src/main/java/com/scalar/db/storage/jdbc/JdbcUtils.java Configured the data source to have a default read-only flag of false.
core/src/main/java/com/scalar/db/storage/jdbc/JdbcDatabase.java Set the connection to read-only for Get and Scan operations before using the JDBC service.

Connection connection = null;
try {
connection = dataSource.getConnection();
connection.setReadOnly(true);
Copy link

Copilot AI May 14, 2025

Choose a reason for hiding this comment

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

[nitpick] The call to setReadOnly(true) is duplicated in both the get and scan methods. Consider extracting this operation into a helper method to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
@brfrn169 brfrn169 force-pushed the optimize-jdbc-storage-by-using-setReadOnly branch from 2577763 to 11cacf1 Compare May 14, 2025 14:11
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.

What about adding setReadOnly to JdbcAdmin.getTableMetadata(), metadata are cached so it might not do much though.

@brfrn169
Copy link
Collaborator Author

What about adding setReadOnly to JdbcAdmin.getTableMetadata(), metadata are cached so it might not do much though.

@Torch3333 Thanks for your feedback! Fixed in febd642.

@brfrn169 brfrn169 requested a review from Torch3333 May 17, 2025 07:45
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!

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!

@brfrn169 brfrn169 merged commit a763467 into master May 20, 2025
55 checks passed
@brfrn169 brfrn169 deleted the optimize-jdbc-storage-by-using-setReadOnly branch May 20, 2025 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants