From: Dmitry Shulga Date: June 23 2011 5:04pm Subject: bzr push into mysql-5.1 branch (Dmitry.Shulga:3656 to 3657) Bug#47870 Bug#11756013 List-Archive: http://lists.mysql.com/commits/139778 X-Bug: 47870,11756013 Message-Id: <201106231705.p5NH5KiM018048@acsmt356.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5659140740316762148==" --===============5659140740316762148== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 3657 Dmitry Shulga 2011-06-23 Fixed Bug#11756013 (formerly known as bug#47870): BOGUS "THE TABLE MYSQL.PROC IS MISSING,..." There was a race condition between loading a stored routine (function/procedure/trigger) specified by fully qualified name SCHEMA_NAME.PROC_NAME and dropping the stored routine database. The problem was that there is a window for race condition when one server thread tries to load a stored routine being executed and the other thread tries to drop the stored routine schema. This condition race window exists in implementation of function mysql_change_db() called by db_load_routine() during loading of stored routine to cache. Function mysql_change_db() calls check_db_dir_existence() that might failed because specified database was dropped during concurrent execution of DROP SCHEMA statement. db_load_routine() calls mysql_change_db() with flag 'force_switch' set to 'true' value so when referenced db is not found then my_error() is not called and function mysql_change_db() returns ok. This shadows information about schema opening error in db_load_routine(). Then db_load_routine() makes attempt to parse stored routine that is failed. This makes to return error to sp_cache_routines_and_add_tables_aux() but since during error generation a call to my_error wasn't made and hence THD::main_da wasn't set we set the generic "mysql.proc table corrupt" error when running sp_cache_routines_and_add_tables_aux(). The fix is to install an error handler inside db_load_routine() for the mysql_op_change_db() call, and check later if the ER_BAD_DB_ERROR was caught. @ sql/sql_db.cc Added synchronization point "before_db_dir_check" to emulate a race condition during processing of CALL/DROP SCHEMA. modified: mysql-test/r/sp_sync.result mysql-test/t/sp_sync.test sql/sp.cc sql/sql_db.cc 3656 Inaam Rana 2011-06-17 Bug 12635227 - 61188: DROP TABLE EXTREMELY SLOW approved by: Marko rb://681 Coalescing of free buf_page_t descriptors can prove to be one severe bottleneck in performance of compression. One such workload where it hurts badly is DROP TABLE. This patch removes buf_page_t allocations from buf_buddy and uses ut_malloc instead. In order to further reduce overhead of colaescing we no longer attempt to coalesce a block if the corresponding free_list is less than 16 in size. modified: storage/innodb_plugin/ChangeLog storage/innodb_plugin/btr/btr0cur.c storage/innodb_plugin/buf/buf0buddy.c storage/innodb_plugin/buf/buf0buf.c storage/innodb_plugin/buf/buf0lru.c storage/innodb_plugin/include/buf0buddy.h storage/innodb_plugin/include/buf0buddy.ic storage/innodb_plugin/include/buf0buf.h storage/innodb_plugin/include/buf0buf.ic storage/innodb_plugin/include/buf0lru.h storage/innodb_plugin/include/buf0types.h === modified file 'mysql-test/r/sp_sync.result' --- a/mysql-test/r/sp_sync.result 2010-01-12 14:16:26 +0000 +++ b/mysql-test/r/sp_sync.result 2011-06-23 13:41:04 +0000 @@ -1,4 +1,4 @@ -Tests of syncronization of stored procedure execution. +Tests of synchronization of stored procedure execution. # # Bug#48157: crash in Item_field::used_tables # @@ -20,4 +20,16 @@ SET DEBUG_SYNC = 'now SIGNAL go'; # code, this test statement will hang. DROP TABLE t1, t2; DROP PROCEDURE p1; +# +# test for bug#11756013 +# +DROP SCHEMA IF EXISTS s1; +CREATE SCHEMA s1; +CREATE PROCEDURE s1.p1() BEGIN END; +SET DEBUG_SYNC='before_db_dir_check SIGNAL check_db WAIT_FOR dropped_schema'; +CALL s1.p1; +SET DEBUG_SYNC='now WAIT_FOR check_db'; +DROP SCHEMA s1; +SET DEBUG_SYNC='now SIGNAL dropped_schema'; +ERROR 42000: Unknown database 's1' SET DEBUG_SYNC = 'RESET'; === modified file 'mysql-test/t/sp_sync.test' --- a/mysql-test/t/sp_sync.test 2010-01-15 08:51:39 +0000 +++ b/mysql-test/t/sp_sync.test 2011-06-23 13:41:04 +0000 @@ -1,7 +1,10 @@ # This test should work in embedded server after mysqltest is fixed -- source include/not_embedded.inc ---echo Tests of syncronization of stored procedure execution. +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + +--echo Tests of synchronization of stored procedure execution. --source include/have_debug_sync.inc @@ -54,5 +57,31 @@ connection default; DROP TABLE t1, t2; DROP PROCEDURE p1; +--echo # +--echo # test for bug#11756013 +--echo # +--disable_warnings +DROP SCHEMA IF EXISTS s1; +--enable_warnings +CREATE SCHEMA s1; +CREATE PROCEDURE s1.p1() BEGIN END; + +connect (con3, localhost, root); +SET DEBUG_SYNC='before_db_dir_check SIGNAL check_db WAIT_FOR dropped_schema'; +--send CALL s1.p1 + +connection default; +SET DEBUG_SYNC='now WAIT_FOR check_db'; +DROP SCHEMA s1; +SET DEBUG_SYNC='now SIGNAL dropped_schema'; + +connection con3; +--error ER_BAD_DB_ERROR +--reap +connection default; +disconnect con3; + SET DEBUG_SYNC = 'RESET'; +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc === modified file 'sql/sp.cc' --- a/sql/sp.cc 2010-06-11 12:52:06 +0000 +++ b/sql/sp.cc 2011-06-23 13:41:04 +0000 @@ -708,6 +708,37 @@ Silence_deprecated_warning::handle_error } +class Bad_db_error_handler : public Internal_error_handler +{ +public: + Bad_db_error_handler() + :m_error_caught(false) + {} + + virtual bool handle_error(uint sql_errno, const char *message, + MYSQL_ERROR::enum_warning_level level, + THD *thd); + + bool error_caught() const { return m_error_caught; } + +private: + bool m_error_caught; +}; + +bool +Bad_db_error_handler::handle_error(uint sql_errno, const char *message, + MYSQL_ERROR::enum_warning_level level, + THD *thd) +{ + if (sql_errno == ER_BAD_DB_ERROR) + { + m_error_caught= true; + return true; + } + return false; +} + + static int db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp, ulong sql_mode, const char *params, const char *returns, @@ -725,7 +756,7 @@ db_load_routine(THD *thd, int type, sp_n ha_rows old_select_limit= thd->variables.select_limit; sp_rcontext *old_spcont= thd->spcont; Silence_deprecated_warning warning_handler; - + Bad_db_error_handler db_not_exists_handler; char definer_user_name_holder[USERNAME_LENGTH + 1]; LEX_STRING definer_user_name= { definer_user_name_holder, USERNAME_LENGTH }; @@ -766,6 +797,7 @@ db_load_routine(THD *thd, int type, sp_n goto end; } + thd->push_internal_handler(&db_not_exists_handler); /* Change the current database (if needed). @@ -776,9 +808,17 @@ db_load_routine(THD *thd, int type, sp_n &cur_db_changed)) { ret= SP_INTERNAL_ERROR; + thd->pop_internal_handler(); goto end; } + thd->pop_internal_handler(); + if (db_not_exists_handler.error_caught()) + { + ret= SP_INTERNAL_ERROR; + my_error(ER_BAD_DB_ERROR, MYF(0), name->m_db.str); + goto end; + } thd->spcont= NULL; { === modified file 'sql/sql_db.cc' --- a/sql/sql_db.cc 2010-12-10 07:48:50 +0000 +++ b/sql/sql_db.cc 2011-06-23 13:41:04 +0000 @@ -26,6 +26,7 @@ #ifdef __WIN__ #include #endif +#include "debug_sync.h" #define MAX_DROP_TABLE_Q_LEN 1024 @@ -1702,6 +1703,8 @@ bool mysql_change_db(THD *thd, const LEX } #endif + DEBUG_SYNC(thd, "before_db_dir_check"); + if (check_db_dir_existence(new_db_file_name.str)) { if (force_switch) --===============5659140740316762148== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/dmitry.shulga@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: dmitry.shulga@stripped\ # 5ao4el9lwz95vsb3 # target_branch: file:///Users/shulga/projects/mysql/mysql-5.1-\ # bug11756013/ # testament_sha1: 7d2a339f4f4bf7e36daf8e2fecf69dc939a36184 # timestamp: 2011-06-24 00:05:13 +0700 # base_revision_id: inaam.rana@stripped\ # y4tpxn10owpf7d6x # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWTIU7zAABVH/gEAQAEDZ9/// f+f+4L////pgDa3D33xevfaxY6eSHp21cGbG9GKaaJVHQD05aC9whiRT0Ao8jUn5U3qanjRJ6n6p tT1PFAGmgaAAZBKICNTMIjRTTamm0kzKGAAI9GkDJpkeUGSMjSQ2qemJGU09Q9QBoAYmj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XKqweteqAJd6hX3hkKTzSpDKypWAXJ1qiiUQUBiUihpeCIoSIKIZqmuAULL6 tF9F7jI4r7g6ztLF42Y64UamxjFkP5yplQwMiFh06lx2RAjmkpmC6zXwAY2LIR6h7AvPBCNYkNMM nCVfbepRQGvWErdiXSlyaQMabQH/kByJShgNH+8b6LbobGso9m/HA/YbTk0Qs8g8Rnco36r15Loc IOY9sFUxfZ4sGJuZERiQw7xxFVlhTeCuD2pDwSqg4o2ykjLTIaYDwiNx1eP2Ajr2Ge06c+Le8cJs baiIZMEMaZn3wdYyrKi4IaMAYC51WuwoyBwFdhskCa0KtIoXWKZtWlyJlZaswZ4VoxIA8KwzL+BC Uwp/VnVdfGTCpEiCLIpewqViBV2OZ2NioplmISGEnsOc3443wckw798UZJfFbQyT16hEhYOu3hkB cAcXvASVMt98Komrcc0CGaqQoC01EHPG1SUCoQvf9i6GtRddke5jDvbeqpEsbgoe4qwpKr+mxVX7 UGiY31MIddMkoA5JoNNexV6zaBcrz2ZZchPbBNOx89xMQaqa46XfHRGKxhSasKvqoSXvG9WC9nEC MqrTIorV1Fi6I6LRFgvOVaiAHhae9/A38ZFRp6QR8i6l5353dBOxC33l0JsmQiICO9RwEQHOSbDu 38Rdqz1vuxGYkyBqwNVouoHNdsGQbKtmcasoEx39A9iNROYYHw0knaLDAWAMXedHHMx3xmhALktC MlHRG55B6Ey6nkQPese4m48bSbiGCz7Kp4pfGoie0Fy5EiwXE21lC7tgZubBrY2MPYwdUicbxM4L TcO59S8IucLevIcgeX3M044gwlOuvcpc1krxEEFfUvNatOJWb1yBcsE9kVmut5z9wybjcLggu1i3 /F3JFOFCQMhTvMA= --===============5659140740316762148==--