-
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
(release-7.5)
#8350
ddl: Fix potential data lost of alter_partition_by
(release-7.5)
#8350
Conversation
alter_partition_by
alter_partition_by
(release-7.5)
/run-all-tests |
return; | ||
} | ||
|
||
// If table is partition table, we will create the logical table here. |
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.
// If table is partition table, we will create the logical table here. | |
// If table is partition table, we will create the physical table here. |
typo?
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.
The applyCreatePhysicalTable
only create the IStorage for logical table. The function name is kind of misleading.
tiflash/dbms/src/TiDB/Schema/SchemaBuilder.cpp
Lines 940 to 1018 in 6999a2f
template <typename Getter, typename NameMapper> | |
void SchemaBuilder<Getter, NameMapper>::applyCreatePhysicalTable( | |
const TiDB::DBInfoPtr & db_info, | |
const TableInfoPtr & table_info) | |
{ | |
GET_METRIC(tiflash_schema_internal_ddl_count, type_create_table).Increment(); | |
LOG_INFO( | |
log, | |
"Creating table {} with database_id={}, table_id={}", | |
name_mapper.debugCanonicalName(*db_info, *table_info), | |
db_info->id, | |
table_info->id); | |
/// Check if this is a RECOVER table. | |
{ | |
auto & tmt_context = context.getTMTContext(); | |
if (auto * storage = tmt_context.getStorages().get(keyspace_id, table_info->id).get(); storage) | |
{ | |
if (!storage->isTombstone()) | |
{ | |
LOG_DEBUG( | |
log, | |
"Trying to create table {}, but it already exists and is not marked as tombstone, database_id={} " | |
"table_id={}", | |
name_mapper.debugCanonicalName(*db_info, *table_info), | |
db_info->id, | |
table_info->id); | |
return; | |
} | |
LOG_DEBUG( | |
log, | |
"Recovering table {} with database_id={}, table_id={}", | |
name_mapper.debugCanonicalName(*db_info, *table_info), | |
db_info->id, | |
table_info->id); | |
AlterCommands commands; | |
{ | |
AlterCommand command; | |
command.type = AlterCommand::RECOVER; | |
commands.emplace_back(std::move(command)); | |
} | |
auto alter_lock = storage->lockForAlter(getThreadNameAndID()); | |
storage->updateTombstone( | |
alter_lock, | |
commands, | |
name_mapper.mapDatabaseName(*db_info), | |
*table_info, | |
name_mapper, | |
context); | |
LOG_INFO( | |
log, | |
"Created table {}, database_id={} table_id={}", | |
name_mapper.debugCanonicalName(*db_info, *table_info), | |
db_info->id, | |
table_info->id); | |
return; | |
} | |
} | |
/// Normal CREATE table. | |
if (table_info->engine_type == StorageEngine::UNSPECIFIED) | |
{ | |
auto & tmt_context = context.getTMTContext(); | |
table_info->engine_type = tmt_context.getEngineType(); | |
} | |
String stmt = createTableStmt(*db_info, *table_info, name_mapper, log); | |
LOG_INFO( | |
log, | |
"Creating table {} (database_id={} table_id={}) with statement: {}", | |
name_mapper.debugCanonicalName(*db_info, *table_info), | |
db_info->id, | |
table_info->id, | |
stmt); | |
ParserCreateQuery parser; | |
ASTPtr ast = parseQuery(parser, stmt.data(), stmt.data() + stmt.size(), "from syncSchema " + table_info->name, 0); |
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.
get
Signed-off-by: JaySon-Huang <[email protected]>
/run-all-tests |
/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 |
[LGTM Timeline notifier]Timeline:
|
cherry-pick of #8337
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