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

schema : make update to partition tables when 'set tiflash replica' #5267

Merged
merged 8 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions dbms/src/TiDB/Schema/SchemaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ void SchemaBuilder<Getter, NameMapper>::applySetTiFlashReplica(TiDB::DBInfoPtr d
{
throw TiFlashException(fmt::format("miss table in TiKV : {}", table_id), Errors::DDL::StaleSchema);
}

auto & tmt_context = context.getTMTContext();
auto storage = tmt_context.getStorages().get(latest_table_info->id);
if (unlikely(storage == nullptr))
Expand All @@ -1208,15 +1209,34 @@ void SchemaBuilder<Getter, NameMapper>::applySetTiFlashReplica(TiDB::DBInfoPtr d
Errors::DDL::MissingTable);
}

auto managed_storage = std::dynamic_pointer_cast<IManageableStorage>(storage);
if (unlikely(!managed_storage))
throw Exception(fmt::format("{} is not a ManageableStorage", name_mapper.debugCanonicalName(*db_info, *latest_table_info)));
applySetTiFlashReplicaOnLogicalTable(db_info, latest_table_info, storage);
}

template <typename Getter, typename NameMapper>
void SchemaBuilder<Getter, NameMapper>::applySetTiFlashReplicaOnLogicalTable(TiDB::DBInfoPtr db_info, TiDB::TableInfoPtr table_info, ManageableStoragePtr storage)
{
applySetTiFlashReplicaOnPhysicalTable(db_info, table_info, storage);

if (table_info->isLogicalPartitionTable())
{
auto & tmt_context = context.getTMTContext();

applySetTiFlashReplica(db_info, latest_table_info, managed_storage);
for (const auto & part_def : table_info->partition.definitions)
{
auto new_part_table_info = table_info->producePartitionTableInfo(part_def.id, name_mapper);
auto part_storage = tmt_context.getStorages().get(new_part_table_info->id);
if (unlikely(part_storage == nullptr))
{
throw TiFlashException(fmt::format("miss table in TiFlash : {}", name_mapper.debugCanonicalName(*db_info, *new_part_table_info)),
Errors::DDL::MissingTable);
}
applySetTiFlashReplicaOnPhysicalTable(db_info, new_part_table_info, part_storage);
}
}
}

template <typename Getter, typename NameMapper>
void SchemaBuilder<Getter, NameMapper>::applySetTiFlashReplica(
void SchemaBuilder<Getter, NameMapper>::applySetTiFlashReplicaOnPhysicalTable(
TiDB::DBInfoPtr db_info,
TiDB::TableInfoPtr latest_table_info,
ManageableStoragePtr storage)
Expand Down Expand Up @@ -1306,7 +1326,7 @@ void SchemaBuilder<Getter, NameMapper>::syncAllSchema()
/// Rename if needed.
applyRenameLogicalTable(db, table, storage);
/// Update replica info if needed.
applySetTiFlashReplica(db, table, storage);
applySetTiFlashReplicaOnLogicalTable(db, table, storage);
/// Alter if needed.
applyAlterLogicalTable(db, table, storage);
LOG_FMT_DEBUG(log, "Table {} synced during sync all schemas", name_mapper.debugCanonicalName(*db, *table));
Expand Down
3 changes: 2 additions & 1 deletion dbms/src/TiDB/Schema/SchemaBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ struct SchemaBuilder
void applyExchangeTablePartition(const SchemaDiff & diff);

void applySetTiFlashReplica(TiDB::DBInfoPtr db_info, TableID table_id);
void applySetTiFlashReplica(TiDB::DBInfoPtr db_info, TiDB::TableInfoPtr table_info, ManageableStoragePtr storage);
void applySetTiFlashReplicaOnLogicalTable(TiDB::DBInfoPtr db_info, TiDB::TableInfoPtr table_info, ManageableStoragePtr storage);
void applySetTiFlashReplicaOnPhysicalTable(TiDB::DBInfoPtr db_info, TiDB::TableInfoPtr table_info, ManageableStoragePtr storage);
hongyunyan marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace DB