-
Couldn't load subscription status.
- Fork 40
Implement scanner API for JDBC transactions #2702
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
Implement scanner API for JDBC transactions #2702
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 implements the scanner API for JDBC-based transactions by adding getScanner support in both JdbcTransaction and JdbcTransactionManager, extending ScannerImpl to optionally close its connection, updating JdbcService with a new overload, and adding comprehensive unit tests.
- Added
getScannerinJdbcTransactionandJdbcTransactionManagerwith proper commit/rollback semantics - Extended
ScannerImplto accept acloseConnectionOnCloseflag and updatedJdbcServiceto pass it - Introduced a new
CoreErrorfor scanner failures and added/updated unit tests for scanner behaviors
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransaction.java | Implemented getScanner with exception translation |
| core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionManager.java | Provided transactional wrapper via AbstractTransactionManagerCrudOperableScanner |
| core/src/main/java/com/scalar/db/storage/jdbc/ScannerImpl.java | Added closeConnectionOnClose flag to close connection on close |
| core/src/main/java/com/scalar/db/storage/jdbc/JdbcService.java | Added getScanner overload to pass connection-close flag |
| core/src/main/java/com/scalar/db/common/error/CoreError.java | Introduced JDBC_TRANSACTION_GETTING_SCANNER_FAILED error code |
| core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionTest.java | Added unit tests for JdbcTransaction.getScanner |
| core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionManagerTest.java | Added unit tests for JdbcTransactionManager.getScanner |
| core/src/test/java/com/scalar/db/storage/jdbc/JdbcDatabaseTest.java | Updated test to use new ScannerImpl constructor |
| core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java | Removed disabled integration tests |
Comments suppressed due to low confidence (4)
core/src/main/java/com/scalar/db/common/error/CoreError.java:1185
- [nitpick] The new error message
"Getting the scanner failed. Details: %s"is missing a trailing period to match the style of other messages. Consider ending it with...Details: %s.".
JDBC_TRANSACTION_GETTING_SCANNER_FAILED(
core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java:44
- Integration tests for
getScanneron committed records were removed. Re-enable or implement these scenarios (getScanner_ScanGivenForCommittedRecordandmanager_getScanner_ScanGivenForCommittedRecord) to ensure end-to-end coverage.
@Disabled("Implement later")
core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionTest.java:4
- [nitpick] The static import
assertThatCodeis not used in this test class. Remove unused imports (includingArgumentMatchers.anyif unused) to keep imports clean.
import static org.assertj.core.api.Assertions.assertThatCode;
core/src/test/java/com/scalar/db/storage/jdbc/JdbcDatabaseTest.java:101
- The test should verify that closing the scanner actually closes the connection when
closeConnectionOnCloseis true. Add a call toscanner.close()and thenverify(connection).close()to assert the new behavior.
.thenReturn(
new ScannerImpl(resultInterpreter, connection, preparedStatement, resultSet, true));
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!
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!
| } | ||
|
|
||
| try { | ||
| transaction.commit(); |
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.
If CrudException is thrown from one() or all(), only scanner is closed and closed is set to true. In this case, it seems calling this close() method won't close this transaction?
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.
If CrudException is thrown from one() or all(), we call rollbackTransaction(transaction) to roll back the transaction. After that, even if a user call the close() method, the method does nothing. Is there any problem?
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 see. Sounds good!
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 confused this with com.scalar.db.transaction.jdbc.JdbcTransaction#getScanner...
| try { | ||
| return scanner.all(); | ||
| } catch (CrudException e) { | ||
| closed.set(true); |
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.
[minor] How about moving this after scanner.close() so that calling closed()close() method can close scanner even if calling scanner.close() throws an exception?
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.
If scanner.close() throws an exception, we catch it:
https://github.com/scalar-labs/scalardb/pull/2702/files#diff-ca47f7038a18b284fd927596315c778f3c0dc5258d0ae101bb73c158c64e4917R224
Do you still think it’s necessary to move closed.set(true)?
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 only thought in the current implementation there is no way to re-try to close scanner by calling close(), since the flag is set to true before scanner.close() finishes successfully. The concern was not based on actual usages, and probably never mind.
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! 👍
| try { | ||
| return scanner.all(); | ||
| } catch (CrudException e) { | ||
| closed.set(true); |
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 only thought in the current implementation there is no way to re-try to close scanner by calling close(), since the flag is set to true before scanner.close() finishes successfully. The concern was not based on actual usages, and probably never mind.
| } | ||
|
|
||
| try { | ||
| transaction.commit(); |
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 confused this with com.scalar.db.transaction.jdbc.JdbcTransaction#getScanner...
5042c49
into
add-scanner-api-to-transaction-abstraction
Description
This PR adds a scanner API implementation for JDBC transactions.
Note that we are working on this feature in the
add-scanner-api-to-transaction-abstractionfeature branch.Related issues and/or PRs
Changes made
Checklist
Additional notes (optional)
N/A
Release notes
N/A