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 failure on executing exchange partition(release-6.5) #8374

Merged
merged 3 commits into from
Nov 16, 2023

Conversation

JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Nov 15, 2023

What problem does this PR solve?

Issue Number: close #8372

Problem Summary:

For example:

  1. Create a partition table, logical_table_id=100, partition p0 physical_table_id=101
  2. The partition table schema is synced to TiFlash
  3. A non-partition table (table_id=222) is created
  4. Execute exchange partition immediately, exchange non-partition table_id=222 with physical_table_id=101
  5. TiFlash starts its schema sync, try to get the TableInfo of table_id=222 from TiKV
  6. TiKV return nothing because table_id=222 is a partition table of logical_table_id=100 now. TiFlash treat the table as dropped and failed to create IStorage for table_id=222.
  7. TiFlash tries to execute the EXCHANGE PARTITION DDL, but failed to find the IStorage instance of table_id=222. However, the new partition list is persisted to .SQL file, which contains the partition_id of 222
  8. auto orig_table_info = storage->getTableInfo();
    orig_table_info.partition = table_info->partition;
    {
    auto alter_lock = storage->lockForAlter(getThreadName());
    storage->alterFromTiDB(
    alter_lock,
    AlterCommands{},
    name_mapper.mapDatabaseName(*pt_db_info),
    orig_table_info,
    name_mapper,
    context);
    }
    FAIL_POINT_TRIGGER_EXCEPTION(FailPoints::exception_after_step_1_in_exchange_partition);
    /// step 2 change non partition table to a partition of the partition table
    storage = tmt_context.getStorages().get(npt_table_id);
    if (storage == nullptr)
    throw TiFlashException(fmt::format("miss table in TiFlash : {}", name_mapper.debugCanonicalName(*npt_db_info, *table_info)),
    Errors::DDL::MissingTable);
  9. When other DDL try to apply, it can not pass the following check because the IStorage instance of table_id=222 is not created at all
  10. 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(part_def.id);
    if (part_storage == nullptr)
    {
    throw Exception(fmt::format("miss old table id in Flash {}", part_def.id));
    }

What is changed and how it works?

  • In the step 1 for executing exchange partition, create the new table which is new in the latest partition list. This ensure all the physical table in the partition list persisted in disk have been created.
  • But do not drop the non-existing ids in the step 1, because the non-existing ids could be changed into non-partition table
  • Suppress a verbose logging for rate limiter

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 panic issue caused by executing `ALTER TABLE ... EXCHANGE PARTITION ...`

@ti-chi-bot ti-chi-bot bot added do-not-merge/cherry-pick-not-approved release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 15, 2023
@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@JaySon-Huang JaySon-Huang changed the title ddl: Fix failure on executing exchange partition ddl: Fix failure on executing exchange partition(release-6.5) Nov 15, 2023
@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor

@hongyunyan hongyunyan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Nov 15, 2023
@ti-chi-bot ti-chi-bot bot added the lgtm label Nov 15, 2023
Copy link
Contributor

ti-chi-bot bot commented Nov 15, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hongyunyan, 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 [Lloyd-Pottiger,hongyunyan]

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 Nov 15, 2023
Copy link
Contributor

ti-chi-bot bot commented Nov 15, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-11-15 14:06:14.855969945 +0000 UTC m=+4257972.443080075: ☑️ agreed by hongyunyan.
  • 2023-11-15 14:24:40.313437882 +0000 UTC m=+4259077.900548027: ☑️ agreed by Lloyd-Pottiger.

@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Nov 16, 2023
@ti-chi-bot ti-chi-bot bot merged commit 717405f into pingcap:release-6.5 Nov 16, 2023
5 checks passed
@JaySon-Huang JaySon-Huang deleted the fix_exchange_part_6.5 branch November 16, 2023 02:40
@JinheLin
Copy link
Contributor

/cherry-pick release-6.5-20231120-v6.5.4

@ti-chi-bot
Copy link
Member

@JinheLin: new pull request created to branch release-6.5-20231120-v6.5.4: #8390.

In response to this:

/cherry-pick release-6.5-20231120-v6.5.4

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Nov 28, 2023
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants