-
Notifications
You must be signed in to change notification settings - Fork 40
Optimize JDBC storage by using Connection.setReadOnly() #2651
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 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); |
Copilot
AI
May 14, 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.
[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.
2577763 to
11cacf1
Compare
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! 👍
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.
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. |
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!
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!
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
Connection.setReadOnly()for the Get and Scan operations.Checklist
Additional notes (optional)
N/A
Release notes
N/A