-
Notifications
You must be signed in to change notification settings - Fork 411
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 potential data lost of alter_partition_by
#8337
Conversation
/run-all-tests |
/hold
|
/run-all-tests |
/run-all-tests |
[LGTM Timeline notifier]Timeline:
|
/run-all-tests |
/run-integration-test |
da25c78
to
b76fe2e
Compare
7ce6aea
to
4178513
Compare
/run-all-tests |
/run-all-tests |
/run-all-tests |
alter_partition_by
alter_partition_by
alter_partition_by
alter_partition_by
Signed-off-by: JaySon-Huang <[email protected]>
/run-all-tests |
@@ -252,9 +252,14 @@ void SchemaBuilder<Getter, NameMapper>::applyDiff(const SchemaDiff & diff) | |||
} | |||
else | |||
{ | |||
/// The new non-partitioned table will have a new id | |||
// Create the new table. | |||
// If the new table is a partition table, this will also overwrite |
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.
It may be better to seperate the logical for ActionAlterTablePartitioning and ActionRemovePartitioning
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.
For ActionRemovePartitioning
, it will
- Receive a schema diff, and add the new non-partition table as a table_id in
partition.adding_definitions
. -- TiFlash should add the new table id to mapping and handle the apply snapshot - Then receive a schema diff to make the new non-partition table as a normal table and remove the old partition-table
So it is the same logic as ActionAlterTablePartitioning
in tiflash
auto new_db_info = getter.getDatabase(database_id); | ||
applyCreateStorageInstance(new_db_info, table_info); | ||
|
||
for (const auto & part_def : table_info->partition.definitions) |
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.
when do applyPartitionDiff(new_db_info, table_info, storage), we also will emplacePartitionTableId based on the definitions, why do we also add it here?
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
I get what you mean, let me check it
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 we create the Storage instance by table_info
in line 402, then try to execute applyPartitionDiff
. Then nothing must change between the table_info
and storage.table_info
. So calling applyPartitionDiff
is redundant.
Then this function is simple the same as applyCreateTable
. So I have remove the function applyPartitionAlter
tiflash/dbms/src/TiDB/Schema/SchemaBuilder.cpp
Lines 250 to 262 in 01a1860
case SchemaActionType::ActionRemovePartitioning: | |
{ | |
if (diff.table_id == diff.old_table_id) | |
{ | |
/// Only internal additions of new partitions | |
applyPartitionDiff(diff.schema_id, diff.table_id); | |
} | |
else | |
{ | |
// Create the new table. | |
// If the new table is a partition table, this will also overwrite | |
// the partition id mapping to the new logical table | |
applyCreateTable(diff.schema_id, diff.table_id); |
/run-all-tests |
[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:
Approvers can indicate their approval by writing |
/hold cancel |
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <[email protected]>
In response to a cherrypick label: failed to apply #8337 on top of branch "release-7.5":
|
What problem does this PR solve?
Issue Number: close #8206
Problem Summary:
Introduced by #7822
When executing
alter table xxx partition by ...
to turn a non-partition table into partition table, there could be a chance that tiflash see a non-partition table turn into a partition table (using the same table_id). But it would be skipped by the previous implementationtiflash/dbms/src/TiDB/Schema/SchemaBuilder.cpp
Lines 407 to 423 in b092db0
And then tiflash mistaken drop the old table along with all its partitions, but actually those partition are now attached to a new logical table. This leads to data lost after `alter table xxx partition ...
What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note