Skip to content

Commit aedc65f

Browse files
midenokvuvova
authored andcommitted
MDEV-30364 Assertion MDL_EXCLUSIVE on DISCARD TABLESPACE in LOCK TABLE mode
In locked_tables_mode when table is opened without MYSQL_OPEN_GET_NEW_TABLE flag it is taken from pre-opened and locked tables. In that case we upgrade its MDL ticket to MDL_EXCLUSIVE before the operation and downgrade after operation.
1 parent db3e1ed commit aedc65f

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

mysql-test/main/debug_sync.result

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,30 @@ SHOW VARIABLES LIKE 'DEBUG_SYNC';
320320
Variable_name Value
321321
debug_sync ON - current signals: 's2,s7,s1,s5'
322322
SET DEBUG_SYNC= 'RESET';
323+
#
324+
# MDEV-30364 Assertion MDL_EXCLUSIVE on DISCARD TABLESPACE in LOCK TABLE mode
325+
#
326+
create table t (c int) engine=innodb;
327+
connect con1,localhost,root;
328+
set debug_sync='get_schema_column WAIT_FOR go';
329+
select column_name from information_schema.columns
330+
where table_schema='test' and table_name='t';
331+
connection default;
332+
lock table t write;
333+
alter table t discard tablespace;
334+
connect con2,localhost,root;
335+
disconnect con2;
336+
connection default;
337+
ERROR 70100: Query execution was interrupted
338+
set debug_sync='now SIGNAL go';
339+
connection con1;
340+
column_name
341+
c
342+
disconnect con1;
343+
connection default;
344+
unlock tables;
345+
drop table t;
346+
set debug_sync= 'reset';
347+
#
348+
# End of 10.6 tests
349+
#

mysql-test/main/debug_sync.test

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# We need the Debug Sync Facility.
1919
#
2020
--source include/have_debug_sync.inc
21+
--source include/have_innodb.inc
2122

2223
#
2324
# We are checking privileges, which the embedded server cannot do.
@@ -448,3 +449,42 @@ SHOW VARIABLES LIKE 'DEBUG_SYNC';
448449
#
449450
SET DEBUG_SYNC= 'RESET';
450451

452+
--echo #
453+
--echo # MDEV-30364 Assertion MDL_EXCLUSIVE on DISCARD TABLESPACE in LOCK TABLE mode
454+
--echo #
455+
create table t (c int) engine=innodb;
456+
--connect con1,localhost,root
457+
set debug_sync='get_schema_column WAIT_FOR go';
458+
send select column_name from information_schema.columns
459+
where table_schema='test' and table_name='t';
460+
461+
--connection default
462+
let $wait_condition=select 1 from information_schema.processlist where state like 'debug sync point%';
463+
--source include/wait_condition.inc
464+
let $connid=`select connection_id()`;
465+
lock table t write;
466+
send alter table t discard tablespace;
467+
468+
--connect con2,localhost,root
469+
--disable_query_log
470+
--eval kill query $connid
471+
--enable_query_log
472+
--disconnect con2
473+
474+
--connection default
475+
--error ER_QUERY_INTERRUPTED
476+
reap;
477+
set debug_sync='now SIGNAL go';
478+
479+
--connection con1
480+
reap;
481+
--disconnect con1
482+
483+
--connection default
484+
unlock tables;
485+
drop table t;
486+
set debug_sync= 'reset';
487+
488+
--echo #
489+
--echo # End of 10.6 tests
490+
--echo #

sql/sql_table.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5946,6 +5946,8 @@ int mysql_discard_or_import_tablespace(THD *thd,
59465946
{
59475947
Alter_table_prelocking_strategy alter_prelocking_strategy;
59485948
int error;
5949+
TABLE *table;
5950+
enum_mdl_type mdl_downgrade= MDL_NOT_INITIALIZED;
59495951
DBUG_ENTER("mysql_discard_or_import_tablespace");
59505952

59515953
mysql_audit_alter_table(thd, table_list);
@@ -5978,7 +5980,21 @@ int mysql_discard_or_import_tablespace(THD *thd,
59785980
DBUG_RETURN(-1);
59795981
}
59805982

5981-
error= table_list->table->file->ha_discard_or_import_tablespace(discard);
5983+
table= table_list->table;
5984+
DBUG_ASSERT(table->mdl_ticket || table->s->tmp_table);
5985+
if (table->mdl_ticket && table->mdl_ticket->get_type() < MDL_EXCLUSIVE)
5986+
{
5987+
DBUG_ASSERT(thd->locked_tables_mode);
5988+
mdl_downgrade= table->mdl_ticket->get_type();
5989+
if (thd->mdl_context.upgrade_shared_lock(table->mdl_ticket, MDL_EXCLUSIVE,
5990+
thd->variables.lock_wait_timeout))
5991+
{
5992+
error= 1;
5993+
goto err;
5994+
}
5995+
}
5996+
5997+
error= table->file->ha_discard_or_import_tablespace(discard);
59825998

59835999
THD_STAGE_INFO(thd, stage_end);
59846000

@@ -6004,6 +6020,9 @@ int mysql_discard_or_import_tablespace(THD *thd,
60046020
err:
60056021
thd->tablespace_op=FALSE;
60066022

6023+
if (mdl_downgrade > MDL_NOT_INITIALIZED)
6024+
table->mdl_ticket->downgrade_lock(mdl_downgrade);
6025+
60076026
if (likely(error == 0))
60086027
{
60096028
my_ok(thd);

0 commit comments

Comments
 (0)