Skip to content

Conversation

KodaiD
Copy link
Contributor

@KodaiD KodaiD commented Oct 17, 2025

Description

This PR updates the rename table feature to avoid dropping the metadata table if it is empty.

Currently, the feature drops the metadata table if it is empty. Therefore, it can fail due to the metadata table NOT FOUND exception when inserting new metadata if only one table exists:

  1. Delete the old metadata.
  2. Drop the empty metadata table.
  3. Rename the table in the storage.
  4. Insert a new metadata. <- TABLE NOT FOUND!

Related issues and/or PRs

Changes made

  • Updated to avoid dropping the metadata table even if it is empty in renameTable.
  • Updated unit tests.
  • Added integration tests.

Checklist

  • 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

@KodaiD KodaiD self-assigned this Oct 17, 2025
@KodaiD KodaiD added the bugfix label Oct 17, 2025
@KodaiD
Copy link
Contributor Author

KodaiD commented Oct 17, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 correctly addresses a potential NOT FOUND exception when renaming a table if the metadata table does not exist. The fix, which involves ensuring the metadata table is recreated, is sound. The addition of unit and integration tests is also great, especially the integration test that specifically covers the scenario where only one table exists. I have a couple of suggestions to improve the maintainability of the test code by reducing duplication.

@KodaiD KodaiD marked this pull request as ready for review October 17, 2025 11:53
@Copilot Copilot AI review requested due to automatic review settings October 17, 2025 11:53
Copy link
Contributor

@Copilot 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 fixes a bug in the rename table feature where the metadata table was not being recreated if it didn't exist, causing potential failures when inserting new metadata after renaming.

Key Changes:

  • Modified JdbcAdmin.renameTable() to recreate the metadata table if it doesn't exist by changing the addTableMetadata parameter from false to true
  • Added integration tests to verify table renaming works correctly when only one table exists in a namespace
  • Updated unit tests to verify metadata table recreation SQL statements are executed during rename operations

Reviewed Changes

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

File Description
core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java Changed parameter in addTableMetadata call to enable metadata table recreation
core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java Added expected SQL statements for metadata table creation across all database types
integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java Added integration test for renaming when only one table exists
integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java Added integration test for renaming when only one table exists

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@KodaiD KodaiD requested review from a team, Torch3333, brfrn169, feeblefakie and komamitsu and removed request for a team October 19, 2025 23:50
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

@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! 👍

@KodaiD KodaiD changed the title Fix to recreate the metadata table when renaming table Fix not to drop the metadata table when renaming table Oct 20, 2025
@KodaiD KodaiD changed the title Fix not to drop the metadata table when renaming table Fix to not drop the metadata table when renaming table Oct 20, 2025
@KodaiD KodaiD requested a review from brfrn169 October 20, 2025 05:41
Copy link
Collaborator

@brfrn169 brfrn169 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!

@KodaiD
Copy link
Contributor Author

KodaiD commented Oct 20, 2025

@komamitsu @Torch3333 I revised this PR to avoid dropping the metadata table instead of recreating it. Please take a look when you get a chance.

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 97a8387 into master Oct 21, 2025
60 checks passed
@brfrn169 brfrn169 deleted the fix-bug-in-rename-table branch October 21, 2025 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants