diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 31af3815cd5..6a4ceb6c301 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -33,6 +33,7 @@ #include "sql_acl.h" // *_ACL #include "sql_base.h" // fill_record #include "sql_statistics.h" // vers_stat_end +#include "vers_utils.h" #ifdef WITH_PARTITION_STORAGE_ENGINE #include "ha_partition.h" @@ -1168,6 +1169,17 @@ bool partition_info::vers_setup_stats(THD * thd, bool is_create_table_ind) bool error= false; + TABLE_LIST tl; + tl.init_one_table( + LEX_STRING_WITH_LEN(table->s->db), + LEX_STRING_WITH_LEN(table->s->table_name), + table->s->table_name.str, + TL_WRITE); + + MDL_auto_lock mdl_lock(thd, tl); + if (mdl_lock.acquire_error()) + return true; + mysql_mutex_lock(&table->s->LOCK_rotation); if (table->s->busy_rotation) { diff --git a/sql/vers_utils.h b/sql/vers_utils.h index 948139bfa9b..b9b93856ea6 100644 --- a/sql/vers_utils.h +++ b/sql/vers_utils.h @@ -16,8 +16,21 @@ public: thd(_thd), table(_table) { DBUG_ASSERT(thd); + MDL_request protection_request; + if (thd->global_read_lock.can_acquire_protection()) + { + error= true; + return; + } + protection_request.init(MDL_key::GLOBAL, "", "", MDL_INTENTION_EXCLUSIVE, + MDL_EXPLICIT); + error= thd->mdl_context.acquire_lock(&protection_request, thd->variables.lock_wait_timeout); + if (error) + return; + table.mdl_request.init(MDL_key::TABLE, table.db, table.table_name, MDL_EXCLUSIVE, MDL_EXPLICIT); error= thd->mdl_context.acquire_lock(&table.mdl_request, thd->variables.lock_wait_timeout); + thd->mdl_context.release_lock(protection_request.ticket); } ~MDL_auto_lock() {