Skip to content
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

ddl: Fix rename partitioned table is not atomic (#9133) #9219

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #9133

What problem does this PR solve?

Issue Number: close #9132

Problem Summary:

In the previous implementation, when running RENAME for a partitioned table, it will skip renaming the following partitions if one of the IStorage instance does not exist.

template <typename Getter, typename NameMapper>
void SchemaBuilder<Getter, NameMapper>::applyRenameLogicalTable(
const DatabaseID new_database_id,
const String & new_database_display_name,
const TableInfoPtr & new_table_info,
const ManageableStoragePtr & storage)
{
applyRenamePhysicalTable(new_database_id, new_database_display_name, *new_table_info, storage);
if (new_table_info->isLogicalPartitionTable())
{
auto & tmt_context = context.getTMTContext();
for (const auto & part_def : new_table_info->partition.definitions)
{
auto part_storage = tmt_context.getStorages().get(keyspace_id, part_def.id);
if (part_storage == nullptr)
{
LOG_ERROR(
log,
"Storage instance is not exist in TiFlash, applyRenamePhysicalTable is ignored, "
"physical_table_id={} logical_table_id={}",
part_def.id,
new_table_info->id);
return;
}

That work well on the versions before v7.2. But after DDL framework refactor since v7.2, there could be a chance that the IStorage instance is not created.
If there are "p1, p2, p3" for a partitioned table, but "p2" is empty. Then the IStorage instance of "p2" is not created. When we need to rename the partitioned table to another database, it will make that "p1" is renamed to the new database, but "p3" remain in the old database. This cause inconsistency.

What is changed and how it works?


  1. applyRenameLogicalTable will continue the rename for remaining partitions even if it happen to a partition that does not have IStorage instance
  2. There could be a chance that tiflash restart when applying applyRenameLogicalTable, making some partitions is in the old database while some is in the new database. After restart, syncAllSchema will call tryFixPartitionsBelongingDatabase and check whether there are any partitions that does not belong to the database on disk. If so, rename the partition table to the correct database.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Fix the issue that tiflash may panic after renaming a partitioned table with empty partition to a new database

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR. labels Jul 12, 2024
@ti-chi-bot ti-chi-bot added cherry-pick-approved Cherry pick PR approved by release team. labels Jul 12, 2024
@JaySon-Huang
Copy link
Contributor

/run-all-tests

@JaySon-Huang
Copy link
Contributor

/hold
need to check the fail test case

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 12, 2024
@JaySon-Huang
Copy link
Contributor

/run-integration-test

@JaySon-Huang
Copy link
Contributor

JaySon-Huang commented Jul 15, 2024

/hold cancel

file another issue for the unstable case, will be fixed in another PR, #9233

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 15, 2024
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jul 15, 2024
@ti-chi-bot ti-chi-bot bot added the lgtm label Jul 16, 2024
Copy link
Contributor

ti-chi-bot bot commented Jul 16, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JaySon-Huang, Lloyd-Pottiger

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JaySon-Huang,Lloyd-Pottiger]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 16, 2024
Copy link
Contributor

ti-chi-bot bot commented Jul 16, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-15 07:55:48.491851657 +0000 UTC m=+254170.482793126: ☑️ agreed by Lloyd-Pottiger.
  • 2024-07-16 06:55:32.133249576 +0000 UTC m=+336954.124191045: ☑️ agreed by JaySon-Huang.

@ti-chi-bot ti-chi-bot bot merged commit 19a5859 into pingcap:release-7.5 Jul 16, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants