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

Merged
merged 15 commits into from
Jul 12, 2024

Conversation

JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Jun 7, 2024

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 bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. 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 Jun 7, 2024
@JaySon-Huang JaySon-Huang force-pushed the fix_rename_partition_table branch 2 times, most recently from 6d98b3a to 8fc127f Compare June 7, 2024 16:24
@JaySon-Huang JaySon-Huang marked this pull request as draft June 8, 2024 04:57
@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 8, 2024
@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2024
Copy link
Contributor

ti-chi-bot bot commented Jul 5, 2024

PR needs rebase.

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 kubernetes/test-infra repository.

@JaySon-Huang JaySon-Huang force-pushed the fix_rename_partition_table branch from 8fc127f to 07f9881 Compare July 9, 2024 09:32
@JaySon-Huang JaySon-Huang removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2024
@JaySon-Huang JaySon-Huang force-pushed the fix_rename_partition_table branch from dd77843 to fbefbd3 Compare July 11, 2024 03:48
@JaySon-Huang JaySon-Huang marked this pull request as ready for review July 11, 2024 03:50
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 11, 2024
@JaySon-Huang JaySon-Huang force-pushed the fix_rename_partition_table branch from b63bfb2 to 9342a3a Compare July 11, 2024 05:31
@ti-chi-bot ti-chi-bot added needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. labels Jul 11, 2024
const String & new_database_name,
const String & new_table_name)
{
std::lock_guard lock(tables_mutex);
Copy link
Member

Choose a reason for hiding this comment

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

Use scoped_lock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jul 11, 2024
auto opt_tbl_id = SchemaNameMapper::tryGetTableID(table_name);
if (!opt_tbl_id)
{
LOG_WARNING(
Copy link
Member

Choose a reason for hiding this comment

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

In what case could this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cases under "tests/delta-merge-test" may create table with the given table_name rather that "t_${table_id}"

database_id,
*opt_tbl_id,
new_database_id);
auto managed_storage = std::dynamic_pointer_cast<IManageableStorage>(tbl_iter->table());
Copy link
Member

Choose a reason for hiding this comment

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

Also protect the cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

Copy link
Contributor

ti-chi-bot bot commented Jul 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JinheLin, 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 [JinheLin,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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 12, 2024
Copy link
Contributor

ti-chi-bot bot commented Jul 12, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-11 07:51:13.864050023 +0000 UTC m=+516771.099284136: ☑️ agreed by Lloyd-Pottiger.
  • 2024-07-12 02:45:59.697288966 +0000 UTC m=+584856.932523075: ☑️ agreed by JinheLin.

@ti-chi-bot ti-chi-bot bot merged commit 02b61ea into pingcap:master Jul 12, 2024
5 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #9219.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Jul 12, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #9220.

@JaySon-Huang JaySon-Huang deleted the fix_rename_partition_table branch July 12, 2024 04:13
ti-chi-bot bot pushed a commit that referenced this pull request Jul 16, 2024
ti-chi-bot bot pushed a commit that referenced this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename partitioned table may leave some partition on the old database
5 participants