Commit 26bc3b34 authored by Dmitry Lenev's avatar Dmitry Lenev

Bug #56137 "Assertion `thd->lock == 0' failed on upgrading

from 5.1.50 to 5.5.6".

Debug builds of the server aborted due to an assertion
failure when DROP DATABASE statement was run on an
installation which had outdated or corrupt mysql.proc table.
Particularly this affected the mysql_upgrade tool which is
run as part of 5.1 to 5.5 upgrade.

The problem was that sp_drop_db_routines(), which was invoked
during dropping of the database, could have returned without
closing and unlocking mysql.proc table in cases when this
table was not up-to-date with the current server. As a result
further attempt to open and lock the mysql.event table, which
was necessary to complete dropping of the database, ended up
with an assert.

This patch solves this problem by ensuring that
sp_drop_db_routines() always closes mysql.proc table and
releases metadata locks on it. This is achieved by changing
open_proc_table_for_update() function to close tables and
release metadata locks acquired by it in case of failure.
This step also makes behavior of the latter function
consistent with behavior of open_proc_table_for_read()/
open_and_lock_tables().


Test case for this bug was added to sp-destruct.test.
parent 0142c14a
...@@ -134,3 +134,19 @@ Warning 1405 Failed to revoke all privileges to dropped routine ...@@ -134,3 +134,19 @@ Warning 1405 Failed to revoke all privileges to dropped routine
# Restore the procs_priv table # Restore the procs_priv table
RENAME TABLE procs_priv_backup TO mysql.procs_priv; RENAME TABLE procs_priv_backup TO mysql.procs_priv;
FLUSH TABLE mysql.procs_priv; FLUSH TABLE mysql.procs_priv;
#
# Bug #56137 "Assertion `thd->lock == 0' failed on upgrading from
# 5.1.50 to 5.5.6".
#
drop database if exists mysqltest;
# Backup mysql.proc.
flush table mysql.proc;
create database mysqltest;
# Corrupt mysql.proc to make it unusable by current version of server.
alter table mysql.proc drop column type;
# The below statement should not cause assertion failure.
drop database mysqltest;
Warnings:
Error 1547 Column count of mysql.proc is wrong. Expected 20, found 19. The table is probably corrupted
# Restore mysql.proc.
drop table mysql.proc;
...@@ -222,3 +222,33 @@ SHOW WARNINGS; ...@@ -222,3 +222,33 @@ SHOW WARNINGS;
--echo # Restore the procs_priv table --echo # Restore the procs_priv table
RENAME TABLE procs_priv_backup TO mysql.procs_priv; RENAME TABLE procs_priv_backup TO mysql.procs_priv;
FLUSH TABLE mysql.procs_priv; FLUSH TABLE mysql.procs_priv;
--echo #
--echo # Bug #56137 "Assertion `thd->lock == 0' failed on upgrading from
--echo # 5.1.50 to 5.5.6".
--echo #
--disable_warnings
drop database if exists mysqltest;
--enable_warnings
--echo # Backup mysql.proc.
flush table mysql.proc;
let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file $MYSQLD_DATADIR/mysql/proc.frm $MYSQLTEST_VARDIR/tmp/proc.frm
--copy_file $MYSQLD_DATADIR/mysql/proc.MYD $MYSQLTEST_VARDIR/tmp/proc.MYD
--copy_file $MYSQLD_DATADIR/mysql/proc.MYI $MYSQLTEST_VARDIR/tmp/proc.MYI
create database mysqltest;
--echo # Corrupt mysql.proc to make it unusable by current version of server.
alter table mysql.proc drop column type;
--echo # The below statement should not cause assertion failure.
drop database mysqltest;
--echo # Restore mysql.proc.
drop table mysql.proc;
--copy_file $MYSQLTEST_VARDIR/tmp/proc.frm $MYSQLD_DATADIR/mysql/proc.frm
--copy_file $MYSQLTEST_VARDIR/tmp/proc.MYD $MYSQLD_DATADIR/mysql/proc.MYD
--copy_file $MYSQLTEST_VARDIR/tmp/proc.MYI $MYSQLD_DATADIR/mysql/proc.MYI
--remove_file $MYSQLTEST_VARDIR/tmp/proc.frm
--remove_file $MYSQLTEST_VARDIR/tmp/proc.MYD
--remove_file $MYSQLTEST_VARDIR/tmp/proc.MYI
...@@ -440,6 +440,7 @@ static TABLE *open_proc_table_for_update(THD *thd) ...@@ -440,6 +440,7 @@ static TABLE *open_proc_table_for_update(THD *thd)
{ {
TABLE_LIST table_list; TABLE_LIST table_list;
TABLE *table; TABLE *table;
MDL_ticket *mdl_savepoint= thd->mdl_context.mdl_savepoint();
DBUG_ENTER("open_proc_table_for_update"); DBUG_ENTER("open_proc_table_for_update");
table_list.init_one_table("mysql", 5, "proc", 4, "proc", TL_WRITE); table_list.init_one_table("mysql", 5, "proc", 4, "proc", TL_WRITE);
...@@ -450,6 +451,9 @@ static TABLE *open_proc_table_for_update(THD *thd) ...@@ -450,6 +451,9 @@ static TABLE *open_proc_table_for_update(THD *thd)
if (!proc_table_intact.check(table, &proc_table_def)) if (!proc_table_intact.check(table, &proc_table_def))
DBUG_RETURN(table); DBUG_RETURN(table);
close_thread_tables(thd);
thd->mdl_context.rollback_to_savepoint(mdl_savepoint);
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment