-
Notifications
You must be signed in to change notification settings - Fork 40
Refactor JdbcAdmin #3121
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
base: master
Are you sure you want to change the base?
Refactor JdbcAdmin #3121
Conversation
Summary of ChangesHello @brfrn169, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on a significant refactoring of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request refactors the JdbcAdmin class by extracting metadata management logic into new TableMetadataService and NamespaceMetadataService classes. This is a good improvement for separation of concerns. The review has identified a few potential issues with the refactored logic, including missing checks in corner cases like upgrading a fresh environment or dropping the last namespace, which could lead to unexpected behavior or metadata loss. There is also a minor issue where a schema is assumed to exist before a table is created, which could make the code more fragile.
core/src/main/java/com/scalar/db/storage/jdbc/NamespaceMetadataService.java
Show resolved
Hide resolved
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 refactors the JDBC admin code by extracting table and namespace metadata management logic into dedicated service classes (TableMetadataService and NamespaceMetadataService), improving code organization and separation of concerns.
- Extracted table metadata operations from
JdbcAdminintoTableMetadataService - Extracted namespace metadata operations from
JdbcAdminintoNamespaceMetadataService - Updated tests to reference the new service classes for metadata constants and methods
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
JdbcAdmin.java |
Refactored to use new metadata service classes, reducing class size and improving modularity |
TableMetadataService.java |
New service class handling all table metadata operations |
NamespaceMetadataService.java |
New service class handling all namespace metadata operations |
JdbcAdminTest.java |
Updated test to reference new service classes and removed unused test helper and variables |
JdbcOperationCheckerTest.java |
Removed unused import and mock variable |
JdbcAdminTestUtils.java |
Updated to reference metadata constants from new service classes |
MultiStorageAdminTestUtils.java |
Updated to reference metadata constants from new service classes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5095fcb to
6a5289c
Compare
|
/gemini review |
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.
Code Review
This pull request refactors the JdbcAdmin class by extracting metadata management logic into new TableMetadataService and NamespaceMetadataService classes. This is a significant improvement in terms of code organization and separation of concerns. The changes are well-executed, and the tests have been updated to match. I have a couple of suggestions for minor improvements related to code duplication and a small inefficiency, which I've detailed in the comments. Overall, this is a solid and beneficial refactoring.
core/src/main/java/com/scalar/db/storage/jdbc/NamespaceMetadataService.java
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/storage/jdbc/NamespaceMetadataService.java
Show resolved
Hide resolved
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
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| int count = 0; | ||
| while (results.next()) { | ||
| namespaces.add(results.getString(COL_NAMESPACE_NAME)); | ||
| // Only need to fetch the first two rows |
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.
The order of the records is always guaranteed? SELECT * FROM tbl WHERE namespace_name != $metadataSchema LIMIT 1 might be more robust?
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.
Actually, this logic doesn’t depend on the order. To determine whether the namespaces table is empty, we need to verify that it contains only the row for the system namespace (metadataSchema). So I think the current logic is robust enough.
BTW, this refactoring does not change the original behavior.
| + encloseFullTableName(metadataSchema, TABLE_NAME) | ||
| + " WHERE " | ||
| + enclose(COL_NAMESPACE_NAME) | ||
| + " = ?"; |
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] It might depend on the underlying RDBMS, but adding LIMIT 1 might optimize the scan.
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.
Yes, I think so too. However, I’d rather not do that now because we need the SELECT query to work across all supported JDBC databases. For example, Oracle doesn’t support the LIMIT clause, so we’d need database-specific SQL. So let’s add that optimization later if it becomes truly necessary. Thanks!
|
|
||
| private boolean isMetadataTableEmpty(Connection connection) throws SQLException { | ||
| String selectAllTables = | ||
| "SELECT DISTINCT " |
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.
[trivial] In this case, SELECT full_table_name FROM tbl LIMIT 1 might be a bit better?
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.
Yes. However, as I mentioned in the following, let’s add that optimization later if it becomes truly necessary. Thanks!
https://github.com/scalar-labs/scalardb/pull/3121/files#r2506970881
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!
KodaiD
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 refactors
JdbcAdminto improve maintainability and extensibility.Related issues and/or PRs
N/A
Changes made
JdbcAdminintoTableMetadataServiceJdbcAdminintoNamespaceMetadataServiceChecklist
Additional notes (optional)
N/A
Release notes
N/A