mirror of
https://github.com/MariaDB/server.git
synced 2026-05-15 03:17:20 +02:00
MDEV-32899 InnoDB is holding shared dict_sys.latch while waiting for FOREIGN KEY child table lock on DDL
lock_table_children(): A new function to lock all child tables of a table. We will only hold dict_sys.latch while traversing dict_table_t::referenced_set. To prevent a race condition with std::set::erase() we will copy the pointers to the child tables to a local vector. Once we have acquired MDL and references to all child tables, we can safely release dict_sys.latch, wait for the locks, and finally release the references. dict_acquire_mdl_shared(): A new variant that takes mdl_context as a parameter. lock_table_for_trx(): Assert that we are not holding dict_sys.latch. ha_innobase::truncate(): When foreign_key_checks=ON, assert that no child tables exist (other than the current table). In any case, we will invoke lock_table_children() so that the child table metadata can be safely updated. (It is possible that a child table is being created concurrently with TRUNCATE TABLE.) ha_innobase::delete_table(): Before and after acquiring exclusive locks on the current table as well as all child tables, check that FOREIGN KEY constraints will not be violated. In this way, we can reject impossible DROP TABLE without having to wait for locks first. This fixes up commit2ca1123464(MDEV-26217) and commitc3c53926c4(MDEV-26554).
This commit is contained in:
parent
5f2dcd112b
commit
b2654ba826
8 changed files with 248 additions and 94 deletions
|
|
@ -11203,16 +11203,7 @@ ha_innobase::commit_inplace_alter_table(
|
|||
fts_optimize_remove_table(ctx->old_table);
|
||||
}
|
||||
|
||||
dict_sys.freeze(SRW_LOCK_CALL);
|
||||
for (auto f : ctx->old_table->referenced_set) {
|
||||
if (dict_table_t* child = f->foreign_table) {
|
||||
error = lock_table_for_trx(child, trx, LOCK_X);
|
||||
if (error != DB_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dict_sys.unfreeze();
|
||||
error = lock_table_children(ctx->old_table, trx);
|
||||
|
||||
if (ctx->new_table->fts) {
|
||||
ut_ad(!ctx->new_table->fts->add_wq);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue