From 359dfdea80db838766d1b1f73f5904d2c2312205 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 20 Nov 2009 00:13:54 +0100 Subject: Bug#32115: Bad use of Name_resolution_context from current LEX in partitioning port from mysql-next (5.4) to mysql-next-mr-bugfixing (5.5/5.6?) 2755 Konstantin Osipov 2008-11-27 Bug#32115 will remove the pre-requisite to initialize LEX to open tables. This dependency was added in 5.1 and was supposed to be removed in 6.0. Remove asserts and initialization of LEX in places where we don't deal with partitioned tables. sql/sp_head.cc: Fix a typo. --- sql/sql_plugin.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 936c9ae8866..d15c97de912 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1359,7 +1359,6 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) } new_thd->thread_stack= (char*) &tables; new_thd->store_globals(); - lex_start(new_thd); new_thd->db= my_strdup("mysql", MYF(0)); new_thd->db_length= 5; bzero((uchar*)&tables, sizeof(tables)); -- cgit v1.2.1 From e3b03d5de57173ec31c339794c34635818fa9b90 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Mon, 30 Nov 2009 18:55:03 +0300 Subject: Initial import of WL#3726 "DDL locking for all metadata objects". Backport of: ------------------------------------------------------------ revno: 2630.4.1 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Fri 2008-05-23 17:54:03 +0400 message: WL#3726 "DDL locking for all metadata objects". After review fixes in progress. ------------------------------------------------------------ This is the first patch in series. It transforms the metadata locking subsystem to use a dedicated module (mdl.h,cc). No significant changes in the locking protocol. The import passes the test suite with the exception of deprecated/removed 6.0 features, and MERGE tables. The latter are subject to a fix by WL#4144. Unfortunately, the original changeset comments got lost in a merge, thus this import has its own (largely insufficient) comments. This patch fixes Bug#25144 "replication / binlog with view breaks". Warning: this patch introduces an incompatible change: Under LOCK TABLES, it's no longer possible to FLUSH a table that was not locked for WRITE. Under LOCK TABLES, it's no longer possible to DROP a table or VIEW that was not locked for WRITE. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.2 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 14:03:45 +0400 message: WL#3726 "DDL locking for all metadata objects". After review fixes in progress. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.3 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 14:08:51 +0400 message: WL#3726 "DDL locking for all metadata objects" Fixed failing Windows builds by adding mdl.cc to the lists of files needed to build server/libmysqld on Windows. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.4 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 21:57:58 +0400 message: WL#3726 "DDL locking for all metadata objects". Fix for assert failures in kill.test which occured when one tried to kill ALTER TABLE statement on merge table while it was waiting in wait_while_table_is_used() for other connections to close this table. These assert failures stemmed from the fact that cleanup code in this case assumed that temporary table representing new version of table was open with adding to THD::temporary_tables list while code which were opening this temporary table wasn't always fulfilling this. This patch changes code that opens new version of table to always do this linking in. It also streamlines cleanup process for cases when error occurs while we have new version of table open. ****** WL#3726 "DDL locking for all metadata objects" Add libmysqld/mdl.cc to .bzrignore. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.6 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Sun 2008-05-25 00:33:22 +0400 message: WL#3726 "DDL locking for all metadata objects". Addition to the fix of assert failures in kill.test caused by changes for this worklog. Make sure we close the new table only once. .bzrignore: Add libmysqld/mdl.cc libmysqld/CMakeLists.txt: Added mdl.cc to the list of files needed for building of libmysqld. libmysqld/Makefile.am: Added files implementing new meta-data locking subsystem to the server. mysql-test/include/handler.inc: Use separate connection for waiting while threads performing DDL operations conflicting with open HANDLER tables reach blocked state. This is required because now we check and close tables open by HANDLER statements in this connection conflicting with DDL in another each time open_tables() is called and thus select from I_S which is used for waiting will unblock DDL operations if issued from connection with open HANDLERs. mysql-test/r/create.result: Adjusted test case after change in implementation of CREATE TABLE ... SELECT. We no longer have special check in open_table() which catches the case when we select from the table created. Instead we rely on unique_table() call which happens after opening and locking all tables. mysql-test/r/flush.result: FLUSH TABLES WITH READ LOCK can no longer happen under LOCK TABLES. Updated test accordingly. mysql-test/r/flush_table.result: Under LOCK TABLES we no longer allow to do FLUSH TABLES for tables locked for read. Updated test accordingly. mysql-test/r/handler_innodb.result: Use separate connection for waiting while threads performing DDL operations conflicting with open HANDLER tables reach blocked state. This is required because now we check and close tables open by HANDLER statements in this connection conflicting with DDL in another each time open_tables() is called and thus select from I_S which is used for waiting will unblock DDL operations if issued from connection with open HANDLERs. mysql-test/r/handler_myisam.result: Use separate connection for waiting while threads performing DDL operations conflicting with open HANDLER tables reach blocked state. This is required because now we check and close tables open by HANDLER statements in this connection conflicting with DDL in another each time open_tables() is called and thus select from I_S which is used for waiting will unblock DDL operations if issued from connection with open HANDLERs. mysql-test/r/information_schema.result: Additional test for WL#3726 "DDL locking for all metadata objects". Check that we use high-priority metadata lock requests when filling I_S tables. Rearrange tests to match 6.0 better (fewer merge conflicts). mysql-test/r/kill.result: Added tests checking that DDL and DML statements waiting for metadata locks can be interrupted by KILL command. mysql-test/r/lock.result: One no longer is allowed to do DROP VIEW under LOCK TABLES even if this view is locked by LOCK TABLES. The problem is that in such situation write locks on view are not mutually exclusive so upgrading metadata lock which is required for dropping of view will lead to deadlock. mysql-test/r/partition_column_prune.result: Update results (same results in 6.0), WL#3726 mysql-test/r/partition_pruning.result: Update results (same results in 6.0), WL#3726 mysql-test/r/ps_ddl.result: We no longer invalidate prepared CREATE TABLE ... SELECT statement if target table changes. This is OK since it is not strictly necessary. The first change is wrong, is caused by FLUSH TABLE now flushing all unused tables. This is a regression that Dmitri fixed in 6.0 in a follow up patch. mysql-test/r/sp.result: Under LOCK TABLES we no longer allow accessing views which were not explicitly locked. To access view we need to obtain metadata lock on it and doing this under LOCK TABLES may lead to deadlocks. mysql-test/r/view.result: One no longer is allowed to do DROP VIEW under LOCK TABLES even if this view is locked by LOCK TABLES. The problem is that in such situation even "write locks" on view are not mutually exclusive so upgrading metadata lock which is required for dropping of view will lead to deadlock mysql-test/r/view_grant.result: ALTER VIEW implementation was changed to open a view only after checking that user which does alter has appropriate privileges on it. This means that in case when user's privileges are insufficient for this we won't check that new view definer is the same as original one or user performing alter has SUPER privilege. Adjusted test case accordingly. mysql-test/r/view_multi.result: Added test case for bug#25144 "replication / binlog with view breaks". mysql-test/suite/rpl/t/disabled.def: Disable test for deprecated features (they don't work with new MDL). mysql-test/t/create.test: Adjusted test case after change in implementation of CREATE TABLE ... SELECT. We no longer have special check in open_table() which catches the case when we select from the table created. Instead we rely on unique_table() call which happens after opening and locking all tables. mysql-test/t/disabled.def: Disable merge.test, subject of WL#4144 mysql-test/t/flush.test: FLUSH TABLES WITH READ LOCK can no longer happen under LOCK TABLES. Updated test accordingly. mysql-test/t/flush_table.test: Under LOCK TABLES we no longer allow to do FLUSH TABLES for tables locked for read. Updated test accordingly. mysql-test/t/information_schema.test: Additional test for WL#3726 "DDL locking for all metadata objects". Check that we use high-priority metadata lock requests when filling I_S tables. Rearrange the results for easier merges with 6.0. mysql-test/t/kill.test: Added tests checking that DDL and DML statements waiting for metadata locks can be interrupted by KILL command. mysql-test/t/lock.test: One no longer is allowed to do DROP VIEW under LOCK TABLES even if this view is locked by LOCK TABLES. The problem is that in such situation write locks on view are not mutually exclusive so upgrading metadata lock which is required for dropping of view will lead to deadlock. mysql-test/t/lock_multi.test: Adjusted test case to the changes of status in various places caused by change in implementation FLUSH TABLES WITH READ LOCK, which is now takes global metadata lock before flushing tables and therefore waits on at these places. mysql-test/t/ps_ddl.test: We no longer invalidate prepared CREATE TABLE ... SELECT statement if target table changes. This is OK since it is not strictly necessary. The first change is wrong, is caused by FLUSH TABLE now flushing all unused tables. This is a regression that Dmitri fixed in 6.0 in a follow up patch. mysql-test/t/sp.test: Under LOCK TABLES we no longer allow accessing views which were not explicitly locked. To access view we need to obtain metadata lock on it and doing this under LOCK TABLES may lead to deadlocks. mysql-test/t/trigger_notembedded.test: Adjusted test case to the changes of status in various places caused by change in implementation FLUSH TABLES WITH READ LOCK, which is now takes global metadata lock before flushing tables and therefore waits on at these places. mysql-test/t/view.test: One no longer is allowed to do DROP VIEW under LOCK TABLES even if this view is locked by LOCK TABLES. The problem is that in such situation even "write locks" on view are not mutually exclusive so upgrading metadata lock which is required for dropping of view will lead to deadlock. mysql-test/t/view_grant.test: ALTER VIEW implementation was changed to open a view only after checking that user which does alter has appropriate privileges on it. This means that in case when user's privileges are insufficient for this we won't check that new view definer is the same as original one or user performing alter has SUPER privilege. Adjusted test case accordingly. mysql-test/t/view_multi.test: Added test case for bug#25144 "replication / binlog with view breaks". sql/CMakeLists.txt: Added mdl.cc to the list of files needed for building of server. sql/Makefile.am: Added files implementing new meta-data locking subsystem to the server. sql/event_db_repository.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when TABLE_LIST objects is also allocated there or on stack. sql/ha_ndbcluster.cc: Adjusted code to work nicely with new metadata locking subsystem. close_cached_tables() no longer has wait_for_placeholder argument. Instead of relying on this parameter and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. sql/ha_ndbcluster_binlog.cc: Adjusted code to work with new metadata locking subsystem. close_cached_tables() no longer has wait_for_placeholder argument. Instead of relying on this parameter and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. sql/handler.cc: update_frm_version(): Directly update TABLE_SHARE::mysql_version member instead of going through all TABLE instances for this table (old code was a legacy from pre-table-definition-cache days). sql/lock.cc: Use new metadata locking subsystem. Threw away most of functions related to name locking as now one is supposed to use metadata locking API instead. In lock_global_read_lock() and unlock_global_read_lock() in order to avoid problems with global read lock sneaking in at the moment when we perform FLUSH TABLES or ALTER TABLE under LOCK TABLES and when tables being reopened are protected only by metadata locks we also have to take global shared meta data lock. sql/log_event.cc: Adjusted code to work with new metadata locking subsystem. For tables open by slave thread for applying RBR events allocate memory for lock request object in the same chunk of memory as TABLE_LIST objects for them. In order to ensure that we keep these objects around until tables are open always close tables before calling Relay_log_info::clear_tables_to_lock(). Use new auxiliary Relay_log_info::slave_close_thread_tables() method to enforce this. sql/log_event_old.cc: Adjusted code to work with new metadata locking subsystem. Since for tables open by slave thread for applying RBR events memory for lock request object is allocated in the same chunk of memory as TABLE_LIST objects for them we have to ensure that we keep these objects around until tables are open. To ensure this we always close tables before calling Relay_log_info::clear_tables_to_lock(). To enfore this we use new auxiliary Relay_log_info::slave_close_thread_tables() method. sql/mdl.cc: Implemented new metadata locking subsystem and API described in WL3726 "DDL locking for all metadata objects". sql/mdl.h: Implemented new metadata locking subsystem and API described in WL3726 "DDL locking for all metadata objects". sql/mysql_priv.h: - close_thread_tables()/close_tables_for_reopen() now has one more argument which indicates that metadata locks should be released but not removed from the context in order to be used later in mdl_wait_for_locks() and tdc_wait_for_old_version(). - close_cached_table() routine is no longer public. - Thread waiting in wait_while_table_is_used() can be now killed so this function returns boolean to make caller aware of such situation. - We no longer have table cache as separate entity instead used and unused TABLE instances are linked to TABLE_SHARE objects in table definition cache. - Now third argument of open_table() is also used for requesting table repair or auto-discovery of table's new definition. So its type was changed from bool to enum. - Added tdc_open_view() function for opening view by getting its definition from disk (and table cache in future). - reopen_name_locked_table() no longer needs "link_in" argument as now we have exclusive metadata locks instead of dummy TABLE instances when this function is called. - find_locked_table() now takes head of list of TABLE instances instead of always scanning through THD::open_tables list. Also added find_write_locked_table() auxiliary. - reopen_tables(), close_cached_tables() no longer have mark_share_as_old and wait_for_placeholder arguments. Instead of relying on this parameters and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. - We no longer need drop_locked_tables() and abort_locked_tables(). - mysql_ha_rm_tables() now always assume that LOCK_open is not acquired by caller. - Added notify_thread_having_shared_lock() callback invoked by metadata locking subsystem when acquiring an exclusive lock, for each thread that has a conflicting shared metadata lock. - Introduced expel_table_from_cache() as replacement for remove_table_from_cache() (the main difference is that this new function assumes that caller follows metadata locking protocol and never waits). - Threw away most of functions related to name locking. One should use new metadata locking subsystem and API instead. sql/mysqld.cc: Got rid of call initializing/deinitializing table cache since now it is embedded into table definition cache. Added calls for initializing/ deinitializing metadata locking subsystem. sql/rpl_rli.cc: Introduced auxiliary Relay_log_info::slave_close_thread_tables() method which is used for enforcing that we always close tables open for RBR before deallocating TABLE_LIST elements and MDL_LOCK objects for them. sql/rpl_rli.h: Introduced auxiliary Relay_log_info::slave_close_thread_tables() method which is used for enforcing that we always close tables open for RBR before deallocating TABLE_LIST elements and MDL_LOCK objects for them. sql/set_var.cc: close_cached_tables() no longer has wait_for_placeholder argument. Instead of relying on this parameter and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. sql/sp_head.cc: For tables added to the statement's table list by prelocking algorithm we allocate these objects either on the same memory as corresponding table list elements or on THD::locked_tables_root (if we are building table list for LOCK TABLES). sql/sql_acl.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when we use stack TABLE_LIST objects to open tables. Got rid of redundant code by using unlock_locked_tables() function. sql/sql_base.cc: Changed code to use new MDL subsystem. Got rid of separate table cache. Now used and unused TABLE instances are linked to the TABLE_SHAREs in table definition cache. check_unused(): Adjusted code to the fact that we no longer have separate table cache. Removed dead code. table_def_free(): Free TABLE instances referenced from TABLE_SHARE objects before destroying table definition cache. get_table_share(): Added assert which ensures that noone will be able to access table (and its share) without acquiring some kind of metadata lock first. close_handle_and_leave_table_as_lock(): Adjusted code to the fact that TABLE instances now are linked to list in TABLE_SHARE. list_open_tables(): Changed this function to use table definition cache instead of table cache. free_cache_entry(): Unlink freed TABLE elements from the list of all TABLE instances for the table in TABLE_SHARE. kill_delayed_thread_for_table(): Added auxiliary for killing delayed insert threads for particular table. close_cached_tables(): Got rid of wait_for_refresh argument as we now rely on global shared metadata lock to prevent FLUSH WITH READ LOCK sneaking in when we are reopening tables. Heavily reworked this function to use new MDL code and not to rely on separate table cache entity. close_open_tables(): We no longer have separate table cache. close_thread_tables(): Release metadata locks after closing all tables. Added skip_mdl argument which allows us not to remove metadata lock requests from the context in case when we are going to use this requests later in mdl_wait_for_locks() and tdc_wait_for_old_versions(). close_thread_table()/close_table_for_reopen(): Since we no longer have separate table cache and all TABLE instances are linked to TABLE_SHARE objects in table definition cache we have to link/unlink TABLE object to/from appropriate lists in the share. name_lock_locked_table(): Moved redundant code to find_write_locked_table() function and adjusted code to the fact that wait_while_table_is_used() can now return with an error if our thread is killed. reopen_table_entry(): We no longer need "link_in" argument as with MDL we no longer call this function with dummy TABLE object pre-allocated and added to the THD::open_tables. Also now we add newly-open TABLE instance to the list of share's used TABLE instances. table_cache_insert_placeholder(): Got rid of name-locking legacy. lock_table_name_if_not_cached(): Moved to sql_table.cc the only place where it is used. It was also reimplemented using new MDL API. open_table(): - Reworked this function to use new MDL subsystem. - Changed code to deal with table definition cache directly instead of going through separate table cache. - Now third argument is also used for requesting table repair or auto-discovery of table's new definition. So its type was changed from bool to enum. find_locked_table()/find_write_locked_table(): Accept head of list of TABLE objects as first argument and use this list instead of always searching in THD::open_tables list. Also added auxiliary for finding write-locked locked tables. reopen_table(): Adjusted function to work with new MDL subsystem and to properly manuipulate with lists of used/unused TABLE instaces in TABLE_SHARE. reopen_tables(): Removed mark_share_as_old parameter. Instead of relying on it and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. Changed code after removing separate table cache. drop_locked_tables()/abort_locked_tables(): Got rid of functions which are no longer needed. unlock_locked_tables(): Moved this function from sql_parse.cc and changed it to release memory which was used for allocating metadata lock requests for tables open and locked by LOCK TABLES. tdc_open_view(): Intoduced function for opening a view by getting its definition from disk (and table cache in future). reopen_table_entry(): Introduced function for opening table definitions while holding exclusive metatadata lock on it. open_unireg_entry(): Got rid of this function. Most of its functionality is relocated to open_table() and open_table_fini() functions, and some of it to reopen_table_entry() and tdc_open_view(). Also code resposible for auto-repair and auto-discovery of tables was moved to separate function. open_table_entry_fini(): Introduced function which contains common actions which finalize process of TABLE object creation. auto_repair_table(): Moved code responsible for auto-repair of table being opened here. handle_failed_open_table_attempt() Moved code responsible for handling failing attempt to open table to one place (retry due to lock conflict/old version, auto-discovery and repair). open_tables(): - Flush open HANDLER tables if they have old version of if there is conflicting metadata lock against them (before this moment we had this code in open_table()). - When we open view which should be processed via derived table on the second execution of prepared statement or stored routine we still should call open_table() for it in order to obtain metadata lock on it and prepare its security context. - In cases when we discover that some special handling of failure to open table is needed call handle_failed_open_table_attempt() which handles all such scenarios. open_ltable(): Handling of various special scenarios of failure to open a table was moved to separate handle_failed_open_table_attempt() function. remove_db_from_cache(): Removed this function as it is no longer used. notify_thread_having_shared_lock(): Added callback which is invoked by MDL subsystem when acquiring an exclusive lock, for each thread that has a conflicting shared metadata lock. expel_table_from_cache(): Introduced function for removing unused TABLE instances. Unlike remove_table_from_cache() it relies on caller following MDL protocol and having appropriate locks when calling it and thus does not do any waiting if table is still in use. tdc_wait_for_old_version(): Added function which allows open_tables() to wait in cases when we discover that we should back-off due to presence of old version of table. abort_and_upgrade_lock(): Use new MDL calls. mysql_wait_completed_table(): Got rid of unused function. open_system_tables_for_read/for_update()/performance_schema_table(): Allocate MDL_LOCK objects on execution memory root in cases when TABLE_LIST objects for corresponding tables is allocated on stack. close_performance_schema_table(): Release metadata locks after closing tables. ****** Use I_P_List for free/used tables list in the table share. sql/sql_binlog.cc: Use Relay_log_info::slave_close_thread_tables() method to enforce that we always close tables open for RBR before deallocating TABLE_LIST elements and MDL_LOCK objects for them. sql/sql_class.cc: Added meta-data locking contexts as part of Open_tables_state context. Also introduced THD::locked_tables_root memory root which is to be used for allocating MDL_LOCK objects for tables in LOCK TABLES statement (end of lifetime for such objects is UNLOCK TABLES so we can't use statement or execution root for them). sql/sql_class.h: Added meta-data locking contexts as part of Open_tables_state context. Also introduced THD::locked_tables_root memory root which is to be used for allocating MDL_LOCK objects for tables in LOCK TABLES statement (end of lifetime for such objects is UNLOCK TABLES so we can't use statement or execution root for them). Note: handler_mdl_context and locked_tables_root and mdl_el_root will be removed by subsequent patches. sql/sql_db.cc: mysql_rm_db() does not really need to call remove_db_from_cache() as it drops each table in the database using mysql_rm_table_part2(), which performs all necessary operations on table (definition) cache. sql/sql_delete.cc: Use the new metadata locking API for TRUNCATE. sql/sql_handler.cc: Changed HANDLER implementation to use new metadata locking subsystem. Note that MDL_LOCK objects for HANDLER tables are allocated in the same chunk of heap memory as TABLE_LIST object for those tables. sql/sql_insert.cc: mysql_insert(): find_locked_table() now takes head of list of TABLE object as its argument instead of always scanning through THD::open_tables list. handle_delayed_insert(): Allocate metadata lock request object for table open by delayed insert thread on execution memroot. create_table_from_items(): We no longer allocate dummy TABLE objects for tables being created if they don't exist. As consequence reopen_name_locked_table() no longer has link_in argument. open_table() now has one more argument which is not relevant for temporary tables. sql/sql_parse.cc: - Moved unlock_locked_tables() routine to sql_base.cc and made available it in other files. Got rid of some redundant code by using this function. - Replaced boolean TABLE_LIST::create member with enum open_table_type member. - Use special memory root for allocating MDL_LOCK objects for tables open and locked by LOCK TABLES (these object should live till UNLOCK TABLES so we can't allocate them on statement nor execution memory root). Also properly set metadata lock upgradability attribure for those tables. - Under LOCK TABLES it is no longer allowed to flush tables which are not write-locked as this breaks metadata locking protocol and thus potentially might lead to deadlock. - Added auxiliary adjust_mdl_locks_upgradability() function. sql/sql_partition.cc: Adjusted code to the fact that reopen_tables() no longer has "mark_share_as_old" argument. Got rid of comments which are no longer true. sql/sql_plist.h: Added I_P_List template class for parametrized intrusive doubly linked lists and I_P_List_iterator for corresponding iterator. Unlike for I_List<> list elements of such list can participate in several lists. Unlike List<> such lists are doubly-linked and intrusive. sql/sql_plugin.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when we use stack TABLE_LIST objects to open tables. sql/sql_prepare.cc: Replaced boolean TABLE_LIST::create member with enum open_table_type member. This allows easily handle situation in which instead of opening the table we want only to take exclusive metadata lock on it. sql/sql_rename.cc: Use new metadata locking subsystem in implementation of RENAME TABLE. sql/sql_servers.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when we use stack TABLE_LIST objects to open tables. Got rid of redundant code by using unlock_locked_tables() function. sql/sql_show.cc: Acquire shared metadata lock when we are getting information for I_S table directly from TABLE_SHARE without doing full-blown table open. We use high priority lock request in this situation in order to avoid deadlocks. Also allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when TABLE_LIST objects are also allocated there sql/sql_table.cc: mysql_rm_table(): Removed comment which is no longer relevant. mysql_rm_table_part2(): Now caller of mysql_ha_rm_tables() should not own LOCK_open. Adjusted code to use new metadata locking subsystem instead of name-locks. lock_table_name_if_not_cached(): Moved this function from sql_base.cc to this file and reimplemented it using metadata locking API. mysql_create_table(): Adjusted code to use new MDL API. wait_while_table_is_used(): Changed function to use new MDL subsystem. Made thread waiting in it killable (this also led to introduction of return value so caller can distinguish successful executions from situations when waiting was aborted). close_cached_tables(): Thread waiting in this function is killable now. As result it has return value for distinguishing between succes and failure. Got rid of redundant boradcast_refresh() call. prepare_for_repair(): Use MDL subsystem instead of name-locks. mysql_admin_table(): mysql_ha_rm_tables() now always assumes that caller doesn't own LOCK_open. mysql_repair_table(): We should mark all elements of table list as requiring upgradable metadata locks. mysql_create_table_like(): Use new MDL subsystem instead of name-locks. create_temporary_tables(): We don't need to obtain metadata locks when creating temporary table. mysql_fast_or_online_alter_table(): Thread waiting in wait_while_table_is_used() is now killable. mysql_alter_table(): Adjusted code to work with new MDL subsystem and to the fact that threads waiting in what_while_table_is_used() and close_cached_table() are now killable. sql/sql_test.cc: We no longer have separate table cache. TABLE instances are now associated with/linked to TABLE_SHARE objects in table definition cache. sql/sql_trigger.cc: Adjusted code to work with new metadata locking subsystem. Also reopen_tables() no longer has mark_share_as_old argument (Instead of relying on this parameter and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock). sql/sql_udf.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when we use stack TABLE_LIST objects to open tables. sql/sql_update.cc: Adjusted code to work with new meta-data locking subsystem. sql/sql_view.cc: Added proper meta-data locking to implementations of CREATE/ALTER/DROP VIEW statements. Now we obtain exclusive meta-data lock on a view before creating/ changing/dropping it. This ensures that all concurrent statements that use this view will finish before our statement will proceed and therefore we will get correct order of statements in the binary log. Also ensure that TABLE_LIST::mdl_upgradable attribute is properly propagated for underlying tables of view. sql/table.cc: Added auxiliary alloc_mdl_locks() function for allocating metadata lock request objects for all elements of table list. sql/table.h: TABLE_SHARE: Got rid of unused members. Introduced members for storing lists of used and unused TABLE objects for this share. TABLE: Added members for linking TABLE objects into per-share lists of used and unused TABLE instances. Added member for holding pointer to metadata lock for this table. TABLE_LIST: Replaced boolean TABLE_LIST::create member with enum open_table_type member. This allows easily handle situation in which instead of opening the table we want only to take exclusive meta-data lock on it (we need this in order to handle ALTER VIEW and CREATE VIEW statements). Introduced new mdl_upgradable member for marking elements of table list for which we need to take upgradable shared metadata lock instead of plain shared metadata lock. Added pointer for holding pointer to MDL_LOCK for the table. Added auxiliary alloc_mdl_locks() function for allocating metadata lock requests objects for all elements of table list. Added auxiliary set_all_mdl_upgradable() function for marking all elements in table list as requiring upgradable metadata locks. storage/myisammrg/ha_myisammrg.cc: Allocate MDL_LOCK objects for underlying tables of MERGE table. To be reworked once Ingo pushes his patch for WL4144. --- sql/sql_plugin.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 936c9ae8866..e9f4152f861 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1366,6 +1366,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) tables.alias= tables.table_name= (char*)"plugin"; tables.lock_type= TL_READ; tables.db= new_thd->db; + alloc_mdl_locks(&tables, tmp_root); #ifdef EMBEDDED_LIBRARY /* @@ -1659,6 +1660,8 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl if (check_table_access(thd, INSERT_ACL, &tables, FALSE, 1, FALSE)) DBUG_RETURN(TRUE); + alloc_mdl_locks(&tables, thd->mem_root); + /* need to open before acquiring LOCK_plugin or it will deadlock */ if (! (table = open_ltable(thd, &tables, TL_WRITE, 0))) DBUG_RETURN(TRUE); @@ -1732,6 +1735,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) bzero(&tables, sizeof(tables)); tables.db= (char *)"mysql"; tables.table_name= tables.alias= (char *)"plugin"; + alloc_mdl_locks(&tables, thd->mem_root); /* need to open before acquiring LOCK_plugin or it will deadlock */ if (! (table= open_ltable(thd, &tables, TL_WRITE, 0))) -- cgit v1.2.1 From 0e080c9ac4df54ddcc0fd3ef267834bfd96522cf Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Fri, 4 Dec 2009 02:29:40 +0300 Subject: Backport of: ------------------------------------------------------------ revno: 2617.23.18 committer: Davi Arnaut branch nick: 4284-6.0 timestamp: Mon 2009-03-02 18:18:26 -0300 message: Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order WL#4284: Transactional DDL locking This is a prerequisite patch: These changes are intended to split lock requests from granted locks and to allow the memory and lifetime of granted locks to be managed within the MDL subsystem. Furthermore, tickets can now be shared and therefore are used to satisfy multiple lock requests, but only shared locks can be recursive. The problem is that the MDL subsystem morphs lock requests into granted locks locks but does not manage the memory and lifetime of lock requests, and hence, does not manage the memory of granted locks either. This can be problematic because it puts the burden of tracking references on the users of the subsystem and it can't be easily done in transactional contexts where the locks have to be kept around for the duration of a transaction. Another issue is that recursive locks (when the context trying to acquire a lock already holds a lock on the same object) requires that each time the lock is granted, a unique lock request/granted lock structure structure must be kept around until the lock is released. This can lead to memory leaks in transactional contexts as locks taken during the transaction should only be released at the end of the transaction. This also leads to unnecessary wake ups (broadcasts) in the MDL subsystem if the context still holds a equivalent of the lock being released. These issues are exacerbated due to the fact that WL#4284 low-level design says that the implementation should "2) Store metadata locks in transaction memory root, rather than statement memory root" but this is not possible because a memory root, as implemented in mysys, requires all objects allocated from it to be freed all at once. This patch combines review input and significant code contributions from Konstantin Osipov (kostja) and Dmitri Lenev (dlenev). mysql-test/r/mdl_sync.result: Add test case result. mysql-test/t/mdl_sync.test: Add test case for shared lock upgrade case. sql/event_db_repository.cc: Rename mdl_alloc_lock to mdl_request_alloc. sql/ha_ndbcluster_binlog.cc: Use new function names to initialize MDL lock requests. sql/lock.cc: Rename MDL functions. sql/log_event.cc: The MDL request now holds the table and database name data (MDL_KEY). sql/mdl.cc: Move the MDL key to the MDL_LOCK structure in order to make the object suitable for allocation from a fixed-size allocator. This allows the simplification of the lists in the MDL_LOCK object, which now are just two, one for granted tickets and other for waiting (upgraders) tickets. Recursive requests for a shared lock on the same object can now be granted using the same lock ticket. This schema is only used for shared locks because that the only case that matters. This is used to avoid waste of resources in case a context (connection) already holds a shared lock on a object. sql/mdl.h: Introduce a metadata lock object key which is used to uniquely identify lock objects. Separate the structure used to represent pending lock requests from the structure used to represent granted metadata locks. Rename functions used to manipulate locks requests in order to have a more consistent function naming schema. sql/sp_head.cc: Rename mdl_alloc_lock to mdl_request_alloc. sql/sql_acl.cc: Rename alloc_mdl_locks to alloc_mdl_requests. sql/sql_base.cc: Various changes to accommodate that lock requests are separated from lock tickets (granted locks). sql/sql_class.h: Last acquired lock before the savepoint was set. sql/sql_delete.cc: Various changes to accommodate that lock requests are separated from lock tickets (granted locks). sql/sql_handler.cc: Various changes to accommodate that lock requests are separated from lock tickets (granted locks). sql/sql_insert.cc: Rename alloc_mdl_locks to alloc_mdl_requests. sql/sql_parse.cc: Rename alloc_mdl_locks to alloc_mdl_requests. sql/sql_plist.h: Typedef for iterator type. sql/sql_plugin.cc: Rename alloc_mdl_locks to alloc_mdl_requests. sql/sql_servers.cc: Rename alloc_mdl_locks to alloc_mdl_requests. sql/sql_show.cc: Various changes to accommodate that lock requests are separated from lock tickets (granted locks). sql/sql_table.cc: Various changes to accommodate that lock requests are separated from lock tickets (granted locks). sql/sql_trigger.cc: Save reference to the lock ticket so it can be downgraded later. sql/sql_udf.cc: Rename alloc_mdl_locks to alloc_mdl_requests. sql/table.cc: Rename mdl_alloc_lock to mdl_request_alloc. sql/table.h: Separate MDL lock requests from lock tickets (granted locks). storage/myisammrg/ha_myisammrg.cc: Rename alloc_mdl_locks to alloc_mdl_requests. --- sql/sql_plugin.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index e9f4152f861..77b5552d977 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1366,7 +1366,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) tables.alias= tables.table_name= (char*)"plugin"; tables.lock_type= TL_READ; tables.db= new_thd->db; - alloc_mdl_locks(&tables, tmp_root); + alloc_mdl_requests(&tables, tmp_root); #ifdef EMBEDDED_LIBRARY /* @@ -1660,7 +1660,7 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl if (check_table_access(thd, INSERT_ACL, &tables, FALSE, 1, FALSE)) DBUG_RETURN(TRUE); - alloc_mdl_locks(&tables, thd->mem_root); + alloc_mdl_requests(&tables, thd->mem_root); /* need to open before acquiring LOCK_plugin or it will deadlock */ if (! (table = open_ltable(thd, &tables, TL_WRITE, 0))) @@ -1735,7 +1735,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) bzero(&tables, sizeof(tables)); tables.db= (char *)"mysql"; tables.table_name= tables.alias= (char *)"plugin"; - alloc_mdl_locks(&tables, thd->mem_root); + alloc_mdl_requests(&tables, thd->mem_root); /* need to open before acquiring LOCK_plugin or it will deadlock */ if (! (table= open_ltable(thd, &tables, TL_WRITE, 0))) -- cgit v1.2.1 From 709f8b5bd31fe983331b9d46d51184cace184d11 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Sat, 5 Dec 2009 02:02:48 +0300 Subject: Backport of revno ## 2617.31.1, 2617.31.3, 2617.31.4, 2617.31.5, 2617.31.12, 2617.31.15, 2617.31.15, 2617.31.16, 2617.43.1 - initial changeset that introduced the fix for Bug#989 and follow up fixes for all test suite failures introduced in the initial changeset. ------------------------------------------------------------ revno: 2617.31.1 committer: Davi Arnaut branch nick: 4284-6.0 timestamp: Fri 2009-03-06 19:17:00 -0300 message: Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order WL#4284: Transactional DDL locking Currently the MySQL server does not keep metadata locks on schema objects for the duration of a transaction, thus failing to guarantee the integrity of the schema objects being used during the transaction and to protect then from concurrent DDL operations. This also poses a problem for replication as a DDL operation might be replicated even thought there are active transactions using the object being modified. The solution is to defer the release of metadata locks until a active transaction is either committed or rolled back. This prevents other statements from modifying the table for the entire duration of the transaction. This provides commitment ordering for guaranteeing serializability across multiple transactions. - Incompatible change: If MySQL's metadata locking system encounters a lock conflict, the usual schema is to use the try and back-off technique to avoid deadlocks -- this schema consists in releasing all locks and trying to acquire them all in one go. But in a transactional context this algorithm can't be utilized as its not possible to release locks acquired during the course of the transaction without breaking the transaction commitments. To avoid deadlocks in this case, the ER_LOCK_DEADLOCK will be returned if a lock conflict is encountered during a transaction. Let's consider an example: A transaction has two statements that modify table t1, then table t2, and then commits. The first statement of the transaction will acquire a shared metadata lock on table t1, and it will be kept utill COMMIT to ensure serializability. At the moment when the second statement attempts to acquire a shared metadata lock on t2, a concurrent ALTER or DROP statement might have locked t2 exclusively. The prescription of the current locking protocol is that the acquirer of the shared lock backs off -- gives up all his current locks and retries. This implies that the entire multi-statement transaction has to be rolled back. - Incompatible change: FLUSH commands such as FLUSH PRIVILEGES and FLUSH TABLES WITH READ LOCK won't cause locked tables to be implicitly unlocked anymore. mysql-test/extra/binlog_tests/drop_table.test: Add test case for Bug#989. mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test: Fix test case to reflect the fact that transactions now hold metadata locks for the duration of a transaction. mysql-test/include/mix1.inc: Fix test case to reflect the fact that transactions now hold metadata locks for the duration of a transaction. mysql-test/include/mix2.inc: Fix test case to reflect the fact that transactions now hold metadata locks for the duration of a transaction. mysql-test/r/flush_block_commit.result: Update test case result (WL#4284). mysql-test/r/flush_block_commit_notembedded.result: Update test case result (WL#4284). mysql-test/r/innodb.result: Update test case result (WL#4284). mysql-test/r/innodb_mysql.result: Update test case result (WL#4284). mysql-test/r/lock.result: Add test case result for an effect of WL#4284/Bug#989 (all locks should be released when a connection terminates). mysql-test/r/mix2_myisam.result: Update test case result (effects of WL#4284/Bug#989). mysql-test/r/not_embedded_server.result: Update test case result (effects of WL#4284/Bug#989). Add a test case for interaction of WL#4284 and FLUSH PRIVILEGES. mysql-test/r/partition_innodb_semi_consistent.result: Update test case result (effects of WL#4284/Bug#989). mysql-test/r/partition_sync.result: Temporarily disable the test case for Bug#43867, which will be fixed by a subsequent backport. mysql-test/r/ps.result: Add a test case for effect of PREPARE on transactional locks: we take a savepoint at beginning of PREAPRE and release it at the end. Thus PREPARE does not accumulate metadata locks (Bug#989/WL#4284). mysql-test/r/read_only_innodb.result: Update test case result (effects of WL#4284/Bug#989). mysql-test/suite/binlog/r/binlog_row_drop_tbl.result: Add a test case result (WL#4284/Bug#989). mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result: Update test case result (effects of WL#4284/Bug#989). mysql-test/suite/binlog/r/binlog_stm_drop_tbl.result: Add a test case result (WL#4284/Bug#989). mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result: Update test case result (effects of WL#4284/Bug#989). mysql-test/suite/binlog/r/binlog_unsafe.result: A side effect of Bug#989 -- slightly different table map ids. mysql-test/suite/binlog/t/binlog_row_drop_tbl.test: Add a test case for WL#4284/Bug#989. mysql-test/suite/binlog/t/binlog_stm_drop_tbl.test: Add a test case for WL#4284/Bug#989. mysql-test/suite/binlog/t/binlog_stm_row.test: Update to the new state name. This is actually a follow up to another patch for WL#4284, that changes Locked thread state to Table lock. mysql-test/suite/ndb/r/ndb_index_ordered.result: Remove result for disabled part of the test case. mysql-test/suite/ndb/t/disabled.def: Temporarily disable a test case (Bug#45621). mysql-test/suite/ndb/t/ndb_index_ordered.test: Disable a part of a test case (needs update to reflect semantics of Bug#989). mysql-test/suite/rpl/t/disabled.def: Disable tests made meaningless by transactional metadata locking. mysql-test/suite/sys_vars/r/autocommit_func.result: Add a commit (Bug#989). mysql-test/suite/sys_vars/t/autocommit_func.test: Add a commit (Bug#989). mysql-test/t/flush_block_commit.test: Fix test case to reflect the fact that transactions now hold metadata locks for the duration of a transaction. mysql-test/t/flush_block_commit_notembedded.test: Fix test case to reflect the fact that transactions now hold metadata locks for the duration of a transaction. Add a test case for transaction-scope locks and the global read lock (Bug#989/WL#4284). mysql-test/t/innodb.test: Fix test case to reflect the fact that transactions now hold metadata locks for the duration of a transaction (effects of Bug#989/WL#4284). mysql-test/t/lock.test: Add a test case for Bug#989/WL#4284. mysql-test/t/not_embedded_server.test: Add a test case for Bug#989/WL#4284. mysql-test/t/partition_innodb_semi_consistent.test: Replace TRUNCATE with DELETE, to not issue an implicit commit of a transaction, and not depend on metadata locks. mysql-test/t/partition_sync.test: Temporarily disable the test case for Bug#43867, which needs a fix to be backported from 6.0. mysql-test/t/ps.test: Add a test case for semantics of PREPARE and transaction-scope locks: metadata locks on tables used in PREPARE are enclosed into a temporary savepoint, taken at the beginning of PREPARE, and released at the end. Thus PREPARE does not effect what locks a transaction owns. mysql-test/t/read_only_innodb.test: Fix test case to reflect the fact that transactions now hold metadata locks for the duration of a transaction (Bug#989/WL#4284). Wait for the read_only statement to actually flush tables before sending other concurrent statements that depend on its state. mysql-test/t/xa.test: Fix test case to reflect the fact that transactions now hold metadata locks for the duration of a transaction (Bug#989/WL#4284). sql/ha_ndbcluster_binlog.cc: Backport bits of changes of ha_ndbcluster_binlog.cc from 6.0, to fix the failing binlog test suite with WL#4284. WL#4284 implementation does not work with 5.1 implementation of ndbcluster binlog index. sql/log_event.cc: Release metadata locks after issuing a commit. sql/mdl.cc: Style changes (WL#4284). sql/mysql_priv.h: Rename parameter to match the name used in the definition (WL#4284). sql/rpl_injector.cc: Release metadata locks on commit (WL#4284). sql/rpl_rli.cc: Remove assert made meaningless, metadata locks are released at the end of the transaction. sql/set_var.cc: Close tables and release locks if autocommit mode is set. sql/slave.cc: Release metadata locks after a rollback. sql/sql_acl.cc: Don't implicitly unlock locked tables. Issue a implicit commit at the end and unlock tables. sql/sql_base.cc: Defer the release of metadata locks when closing tables if not required to. Issue a deadlock error if the locking protocol requires that a transaction re-acquire its locks. Release metadata locks when closing tables for reopen. sql/sql_class.cc: Release metadata locks if the thread is killed. sql/sql_parse.cc: Release metadata locks after implicitly committing a active transaction, or after explicit commits or rollbacks. sql/sql_plugin.cc: Allocate MDL request on the stack as the use of the table is contained within the function. It will be removed from the context once close_thread_tables is called at the end of the function. sql/sql_prepare.cc: The problem is that the prepare phase of the CREATE TABLE statement takes a exclusive metadata lock lock and this can cause a self-deadlock the thread already holds a shared lock on the table being that should be created. The solution is to make the prepare phase take a shared metadata lock when preparing a CREATE TABLE statement. The execution of the statement will still acquire a exclusive lock, but won't cause any problem as it issues a implicit commit. After some discussions with stakeholders it has been decided that metadata locks acquired during a PREPARE statement must be released once the statement is prepared even if it is prepared within a multi statement transaction. sql/sql_servers.cc: Don't implicitly unlock locked tables. Issue a implicit commit at the end and unlock tables. sql/sql_table.cc: Close table and release metadata locks after a admin operation. sql/table.h: The problem is that the prepare phase of the CREATE TABLE statement takes a exclusive metadata lock lock and this can cause a self-deadlock the thread already holds a shared lock on the table being that should be created. The solution is to make the prepare phase take a shared metadata lock when preparing a CREATE TABLE statement. The execution of the statement will still acquire a exclusive lock, but won't cause any problem as it issues a implicit commit. sql/transaction.cc: Release metadata locks after the implicitly committed due to a new transaction being started. Also, release metadata locks acquired after a savepoint if the transaction is rolled back to the save point. The problem is that in some cases transaction-long metadata locks could be released before the transaction was committed. This could happen when a active transaction was ended by a "START TRANSACTION" or "BEGIN" statement, in which case the metadata locks would be released before the actual commit of the active transaction. The solution is to defer the release of metadata locks to after the transaction has been implicitly committed. No test case is provided as the effort to provide one is too disproportional to the size of the fix. --- sql/sql_plugin.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 77b5552d977..b7efe13e26e 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1349,6 +1349,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) #ifdef EMBEDDED_LIBRARY bool table_exists; #endif /* EMBEDDED_LIBRARY */ + MDL_request mdl_request; DBUG_ENTER("plugin_load"); if (!(new_thd= new THD)) @@ -1366,7 +1367,8 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) tables.alias= tables.table_name= (char*)"plugin"; tables.lock_type= TL_READ; tables.db= new_thd->db; - alloc_mdl_requests(&tables, tmp_root); + tables.mdl_request= &mdl_request; + mdl_request.init(0, tables.db, tables.table_name); #ifdef EMBEDDED_LIBRARY /* -- cgit v1.2.1 From 6d86b5604d470f2f5edd8e4b1e3245645ee386ad Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Tue, 8 Dec 2009 12:57:07 +0300 Subject: Backport of: ---------------------------------------------------------- revno: 2617.69.20 committer: Konstantin Osipov branch nick: 5.4-4284-1-assert timestamp: Thu 2009-08-13 18:29:55 +0400 message: WL#4284 "Transactional DDL locking" A review fix. Since WL#4284 implementation separated MDL_request and MDL_ticket, MDL_request becamse a utility object necessary only to get a ticket. Store it by-value in TABLE_LIST with the intent to merge MDL_request::key with table_list->table_name and table_list->db in future. Change the MDL subsystem to not require MDL_requests to stay around till close_thread_tables(). Remove the list of requests from the MDL context. Requests for shared metadata locks acquired in open_tables() are only used as a list in recover_from_failed_open_table_attempt(), which calls mdl_context.wait_for_locks() for this list. To keep such list for recover_from_failed_open_table_attempt(), introduce a context class (Open_table_context), that collects all requests. A lot of minor cleanups and simplications that became possible with this change. sql/event_db_repository.cc: Remove alloc_mdl_requests(). Now MDL_request instance is a member of TABLE_LIST, and init_one_table() initializes it. sql/ha_ndbcluster_binlog.cc: Remove now unnecessary declaration and initialization of binlog_mdl_request. sql/lock.cc: No need to allocate MDL requests in lock_table_names() now. sql/log.cc: Use init_one_table() method, remove alloc_mdl_requests(), which is now unnecessary. sql/log_event.cc: No need to allocate mdl_request separately now. Use init_one_table() method. sql/log_event_old.cc: Update to the new signature of close_tables_for_reopen(). sql/mdl.cc: Update try_acquire_exclusive_lock() to be more easy to use. Function lock_table_name_if_not_cached() has been removed. Make acquire_shared_lock() signature consistent with try_acquire_exclusive_lock() signature. Remove methods that are no longer used. Update comments. sql/mdl.h: Implement an assignment operator that doesn't copy MDL_key (MDL_key::operator= is private and should remain private). This is a hack to work-around assignment of TABLE_LIST by value in several places. Such assignments violate encapsulation, since only perform a shallow copy. In most cases these assignments are a hack on their own. sql/mysql_priv.h: Update signatures of close_thread_tables() and close_tables_for_reopen(). sql/sp.cc: Allocate TABLE_LIST in thd->mem_root. Use init_one_table(). sql/sp_head.cc: Use init_one_table(). Remove thd->locked_tables_root, it's no longer needed. sql/sql_acl.cc: Use init_mdl_requests() and init_one_table(). sql/sql_base.cc: Update to new signatures of try_acquire_shared_lock() and try_acquire_exclusive_lock(). Remove lock_table_name_if_not_cached(). Fix a bug in open_ltable() that would not return ER_LOCK_DEADLOCK in case of a failed lock_tables() and a multi-statement transaction. Fix a bug in open_and_lock_tables_derived() that would not return ER_LOCK_DEADLOCK in case of a multi-statement transaction and a failure of lock_tables(). Move assignment of enum_open_table_action to a method of Open_table_context, a new class that maintains information for backoff actions. Minor rearrangements of the code. Remove alloc_mdl_requests() in functions that work with system tables: instead the patch ensures that callers always initialize TABLE_LIST argument. sql/sql_class.cc: THD::locked_tables_root is no more. sql/sql_class.h: THD::locked_tables_root is no more. Add a declaration for Open_table_context class. sql/sql_delete.cc: Update to use the simplified MDL API. sql/sql_handler.cc: TABLE_LIST::mdl_request is stored by-value now. Ensure that mdl_request.ticket is NULL for every request that is passed into MDL, to satisfy MDL asserts. @ sql/sql_help.cc Function open_system_tables_for_read() no longer initializes mdl_requests. Move TABLE_LIST::mdl_request initialization closer to TABLE_LIST initialization. sql/sql_help.cc: Function open_system_tables_for_read() no longer initializes mdl_requests. Move TABLE_LIST::mdl_request initialization closer to TABLE_LIST initialization. sql/sql_insert.cc: Remove assignment by-value of TABLE_LIST in TABLEOP_HOOKS. We can't carry over a granted MDL ticket from one table list to another. sql/sql_parse.cc: Change alloc_mdl_requests() -> init_mdl_requests(). @todo We can remove init_mdl_requests() altogether in some places: all places that call add_table_to_list() already have mdl requests initialized. sql/sql_plugin.cc: Use init_one_table(). THD::locked_tables_root is no more. sql/sql_servers.cc: Use init_one_table(). sql/sql_show.cc: Update acquire_high_priority_shared_lock() to use TABLE_LIST::mdl_request rather than allocate an own. Fix get_trigger_table_impl() to use init_one_table(), check for out of memory, follow the coding style. sql/sql_table.cc: Update to work with TABLE_LIST::mdl_request by-value. Remove lock_table_name_if_not_cached(). The code that used to delegate to it is quite simple and concise without it now. sql/sql_udf.cc: Use init_one_table(). sql/sql_update.cc: Update to use the new signature of close_tables_for_reopen(). sql/table.cc: Move re-setting of mdl_requests for prepared statements and stored procedures from close_thread_tables() to reinit_stmt_before_use(). Change alloc_mdl_requests() to init_mdl_requests(). init_mdl_requests() is a hack that can't be deleted until we don't have a list-aware TABLE_LIST constructor. Hopefully its use will be minimal sql/table.h: Change alloc_mdl_requests() to init_mdl_requests() TABLE_LIST::mdl_request is stored by value. sql/tztime.cc: We no longer initialize mdl requests in open_system_tables_for*() functions. Move this initialization closer to initialization of the rest of TABLE_LIST members. storage/myisammrg/ha_myisammrg.cc: Simplify mdl_request initialization. --- sql/sql_plugin.cc | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index b7efe13e26e..7dd7dd0d4b9 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1349,7 +1349,6 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) #ifdef EMBEDDED_LIBRARY bool table_exists; #endif /* EMBEDDED_LIBRARY */ - MDL_request mdl_request; DBUG_ENTER("plugin_load"); if (!(new_thd= new THD)) @@ -1363,12 +1362,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) lex_start(new_thd); new_thd->db= my_strdup("mysql", MYF(0)); new_thd->db_length= 5; - bzero((uchar*)&tables, sizeof(tables)); - tables.alias= tables.table_name= (char*)"plugin"; - tables.lock_type= TL_READ; - tables.db= new_thd->db; - tables.mdl_request= &mdl_request; - mdl_request.init(0, tables.db, tables.table_name); + tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_READ); #ifdef EMBEDDED_LIBRARY /* @@ -1656,14 +1650,10 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl struct st_plugin_int *tmp; DBUG_ENTER("mysql_install_plugin"); - bzero(&tables, sizeof(tables)); - tables.db= (char *)"mysql"; - tables.table_name= tables.alias= (char *)"plugin"; + tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_WRITE); if (check_table_access(thd, INSERT_ACL, &tables, FALSE, 1, FALSE)) DBUG_RETURN(TRUE); - alloc_mdl_requests(&tables, thd->mem_root); - /* need to open before acquiring LOCK_plugin or it will deadlock */ if (! (table = open_ltable(thd, &tables, TL_WRITE, 0))) DBUG_RETURN(TRUE); @@ -1734,10 +1724,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) struct st_plugin_int *plugin; DBUG_ENTER("mysql_uninstall_plugin"); - bzero(&tables, sizeof(tables)); - tables.db= (char *)"mysql"; - tables.table_name= tables.alias= (char *)"plugin"; - alloc_mdl_requests(&tables, thd->mem_root); + tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_WRITE); /* need to open before acquiring LOCK_plugin or it will deadlock */ if (! (table= open_ltable(thd, &tables, TL_WRITE, 0))) -- cgit v1.2.1 From 76d33819a1bd8ac8891c9a2f70480431f51e1377 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 9 Dec 2009 20:19:51 -0700 Subject: WL#2360 Performance schema Part III: mysys instrumentation --- sql/sql_plugin.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 936c9ae8866..098783111a1 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1372,10 +1372,10 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) When building an embedded library, if the mysql.plugin table does not exist, we silently ignore the missing table */ - pthread_mutex_lock(&LOCK_open); + mysql_mutex_lock(&LOCK_open); if (check_if_table_exists(new_thd, &tables, &table_exists)) table_exists= FALSE; - pthread_mutex_unlock(&LOCK_open); + mysql_mutex_unlock(&LOCK_open); if (!table_exists) goto end; #endif /* EMBEDDED_LIBRARY */ -- cgit v1.2.1 From 540f85214f3a02b3b42882ec397689c67aba9ac6 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Tue, 15 Dec 2009 23:52:47 +0400 Subject: Backport from 6.0-codebase. WL#3771 "Audit Plugin Interface" Implement new plug-in type - AUDIT New plug-in: audit_null simply increments counter for how many times it was called. include/Makefile.am: wl3771 add new headers to distribution include/mysql/plugin.h: wl3771 define new AUDIT plugin type Split out fulltext plugin type into its own header include/mysql/plugin.h.pp: wl3771 no real API change, just re-arranged some code include/mysql/plugin_audit.h: wl3771 pluggable audit interface include/mysql/plugin_ftparser.h: wl3771 Split out fulltext plugin type into its own header libmysqld/CMakeLists.txt: wl3771 add sql_audit.cc to build libmysqld/Makefile.am: wl3771 add sql_audit.cc to build plugin/audit_null: wl3771 an example plugin for testing pluggable audit interface plugin/audit_null/Makefile.am: wl3771 an example plugin for testing pluggable audit interface plugin/audit_null/audit_null.c: wl3771 an example plugin for testing pluggable audit interface plugin/audit_null/plug.in: wl3771 an example plugin for testing pluggable audit interface sql/CMakeLists.txt: wl3771 add sql_audit.cc to build sql/Makefile.am: wl3771 add sql_audit.cc to build sql/event_queue.cc: wl3771 release audit resources before waiting sql/log.cc: wl3771 add general audit call for log sql/mysqld.cc: wl3771 add audit initialize/finalize add general audit call for error sql/sql_audit.cc: wl3771 pluggable audit interface implementation sql/sql_audit.h: wl3771 pluggable audit interface implementation sql/sql_class.cc: wl3771 add thd audit init/deinit calls sql/sql_class.h: wl3771 add required data structures for audit to THD sql/sql_connect.cc: wl3771 release audit resources before waiting sql/sql_insert.cc: wl3771 release audit plugins before waiting sql/sql_parse.cc: wl3771 add general audit call for results sql/sql_plugin.cc: wl3771 add declarations for audit plugin type --- sql/sql_plugin.cc | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index d15c97de912..bcaeb452894 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -16,6 +16,7 @@ #include "mysql_priv.h" #include #include +#include #define REPORT_TO_LOG 1 #define REPORT_TO_USER 2 @@ -47,12 +48,16 @@ const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]= { C_STRING_WITH_LEN("FTPARSER") }, { C_STRING_WITH_LEN("DAEMON") }, { C_STRING_WITH_LEN("INFORMATION SCHEMA") }, + { C_STRING_WITH_LEN("AUDIT") }, { C_STRING_WITH_LEN("REPLICATION") }, }; extern int initialize_schema_table(st_plugin_int *plugin); extern int finalize_schema_table(st_plugin_int *plugin); +extern int initialize_audit_plugin(st_plugin_int *plugin); +extern int finalize_audit_plugin(st_plugin_int *plugin); + /* The number of elements in both plugin_type_initialize and plugin_type_deinitialize should equal to the number of plugins @@ -60,12 +65,14 @@ extern int finalize_schema_table(st_plugin_int *plugin); */ plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= { - 0,ha_initialize_handlerton,0,0,initialize_schema_table + 0,ha_initialize_handlerton,0,0,initialize_schema_table, + initialize_audit_plugin }; plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= { - 0,ha_finalize_handlerton,0,0,finalize_schema_table + 0,ha_finalize_handlerton,0,0,finalize_schema_table, + finalize_audit_plugin }; #ifdef HAVE_DLOPEN @@ -87,6 +94,7 @@ static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= MYSQL_FTPARSER_INTERFACE_VERSION, MYSQL_DAEMON_INTERFACE_VERSION, MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION, + MYSQL_AUDIT_INTERFACE_VERSION, MYSQL_REPLICATION_INTERFACE_VERSION, }; static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= @@ -96,6 +104,7 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= MYSQL_FTPARSER_INTERFACE_VERSION, MYSQL_DAEMON_INTERFACE_VERSION, MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION, + MYSQL_AUDIT_INTERFACE_VERSION, MYSQL_REPLICATION_INTERFACE_VERSION, }; @@ -1341,26 +1350,22 @@ end: */ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) { + THD thd; TABLE_LIST tables; TABLE *table; READ_RECORD read_record_info; int error; - THD *new_thd; + THD *new_thd= &thd; #ifdef EMBEDDED_LIBRARY bool table_exists; #endif /* EMBEDDED_LIBRARY */ DBUG_ENTER("plugin_load"); - if (!(new_thd= new THD)) - { - sql_print_error("Can't allocate memory for plugin structures"); - delete new_thd; - DBUG_VOID_RETURN; - } new_thd->thread_stack= (char*) &tables; new_thd->store_globals(); new_thd->db= my_strdup("mysql", MYF(0)); new_thd->db_length= 5; + bzero((char*) &thd.net, sizeof(thd.net)); bzero((uchar*)&tables, sizeof(tables)); tables.alias= tables.table_name= (char*)"plugin"; tables.lock_type= TL_READ; @@ -1418,7 +1423,6 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) new_thd->version--; // Force close to free memory end: close_thread_tables(new_thd); - delete new_thd; /* Remember that we don't have a THD */ my_pthread_setspecific_ptr(THR_THD, 0); DBUG_VOID_RETURN; -- cgit v1.2.1 From adb35154d75e53ac68b210a5a063115b8388d3bb Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Wed, 16 Dec 2009 15:56:36 +0400 Subject: Backport from 6.0-codebase. Bug #36098 Audit plugin (wl 3771) feature disabled in 6.0 avoid recusrive locking of LOCK_plugin include/mysql/plugin_audit.h: fix incorrect version sql/log.cc: move the common code to a shared header sql/mysqld.cc: restore the deleted functionality sql/set_var.cc: remove unused parameter sql/sql_audit.h: two inline convenience functions sql/sql_parse.cc: use a simplified convenience call sql/sql_plugin.cc: unlock LOCK_plugin for plugin->init() call, add missing OOM check, issue "unknown variable" error in find_sys_var, not down the stack --- sql/sql_plugin.cc | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index bcaeb452894..9e8b8785d5a 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -229,7 +229,7 @@ static void reap_plugins(void); /* declared in set_var.cc */ -extern sys_var *intern_find_sys_var(const char *str, uint length, bool no_error); +extern sys_var *intern_find_sys_var(const char *str, uint length); extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd, const char *name, longlong val); @@ -1014,6 +1014,9 @@ static int plugin_initialize(struct st_plugin_int *plugin) DBUG_ENTER("plugin_initialize"); safe_mutex_assert_owner(&LOCK_plugin); + DBUG_ASSERT(plugin->state == PLUGIN_IS_UNINITIALIZED); + + pthread_mutex_unlock(&LOCK_plugin); if (plugin_type_initialize[plugin->plugin->type]) { if ((*plugin_type_initialize[plugin->plugin->type])(plugin)) @@ -1033,6 +1036,8 @@ static int plugin_initialize(struct st_plugin_int *plugin) } } + pthread_mutex_lock(&LOCK_plugin); + plugin->state= PLUGIN_IS_READY; if (plugin->plugin->status_vars) @@ -1050,9 +1055,10 @@ static int plugin_initialize(struct st_plugin_int *plugin) {0, 0, SHOW_UNDEF} }; if (add_status_vars(array)) // add_status_vars makes a copy - goto err; + goto err1; #else - add_status_vars(plugin->plugin->status_vars); // add_status_vars makes a copy + if (add_status_vars(plugin->plugin->status_vars)) + goto err1; #endif /* FIX_LATER */ } @@ -1074,6 +1080,8 @@ static int plugin_initialize(struct st_plugin_int *plugin) DBUG_RETURN(0); err: + pthread_mutex_lock(&LOCK_plugin); +err1: DBUG_RETURN(1); } @@ -1686,7 +1694,6 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl } else { - DBUG_ASSERT(tmp->state == PLUGIN_IS_UNINITIALIZED); if (plugin_initialize(tmp)) { my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str, @@ -2164,7 +2171,7 @@ sys_var *find_sys_var(THD *thd, const char *str, uint length) pthread_mutex_lock(&LOCK_plugin); rw_rdlock(&LOCK_system_variables_hash); - if ((var= intern_find_sys_var(str, length, false)) && + if ((var= intern_find_sys_var(str, length)) && (pi= var->cast_pluginvar())) { rw_unlock(&LOCK_system_variables_hash); @@ -2183,11 +2190,7 @@ sys_var *find_sys_var(THD *thd, const char *str, uint length) rw_unlock(&LOCK_system_variables_hash); pthread_mutex_unlock(&LOCK_plugin); - /* - If the variable exists but the plugin it is associated with is not ready - then the intern_plugin_lock did not raise an error, so we do it here. - */ - if (pi && !var) + if (!var) my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str); DBUG_RETURN(var); } @@ -2390,7 +2393,7 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) st_bookmark *v= (st_bookmark*) my_hash_element(&bookmark_hash,idx); if (v->version <= thd->variables.dynamic_variables_version || - !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) || + !(var= intern_find_sys_var(v->key + 1, v->name_len)) || !(pi= var->cast_pluginvar()) || v->key[0] != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK)) continue; @@ -2483,7 +2486,7 @@ static void cleanup_variables(THD *thd, struct system_variables *vars) { v= (st_bookmark*) my_hash_element(&bookmark_hash, idx); if (v->version > vars->dynamic_variables_version || - !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) || + !(var= intern_find_sys_var(v->key + 1, v->name_len)) || !(pivar= var->cast_pluginvar()) || v->key[0] != (pivar->plugin_var->flags & PLUGIN_VAR_TYPEMASK)) continue; -- cgit v1.2.1 From 6f262201f4eff966d6f6a5e7b6b7631fac92a4de Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 22 Dec 2009 10:35:56 +0100 Subject: WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies CMakeLists.txt: Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled client/mysql.cc: don't crash with --show-warnings when mysqld dies config/ac-macros/plugins.m4: Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled include/my_getopt.h: comments include/my_pthread.h: fix double #define mysql-test/mysql-test-run.pl: run sys_vars suite by default properly recognize envirinment variables (e.g. MTR_MAX_SAVE_CORE) set to 0 escape gdb command line arguments mysql-test/suite/sys_vars/r/rpl_init_slave_func.result: init_slave+utf8 bug mysql-test/suite/sys_vars/t/rpl_init_slave_func.test: init_slave+utf8 bug mysys/my_getopt.c: Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) mysys/typelib.c: support for flagset sql/ha_ndbcluster.cc: backport from telco tree sql/item_func.cc: Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters sql/sql_builtin.cc.in: Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled sql/sql_plugin.cc: Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#32902 plugin variables don't know their names Bug#44797 plugins w/o command-line options have no disabling option in --help sql/sys_vars.cc: all server variables are defined here storage/myisam/ft_parser.c: remove unnecessary updates of param->quot storage/myisam/ha_myisam.cc: myisam_* variables belong here strings/my_vsnprintf.c: %o and %llx unittest/mysys/my_vsnprintf-t.c: %o and %llx tests vio/viosocket.c: bugfix: fix @@wait_timeout to work with socket timeouts (vs. alarm thread) --- sql/sql_plugin.cc | 649 +++++++++++++++++++++++++++--------------------------- 1 file changed, 323 insertions(+), 326 deletions(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 4d60caf2931..953f0b3c680 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -13,13 +13,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sys_vars_shared.h" #include #include #define REPORT_TO_LOG 1 #define REPORT_TO_USER 2 -extern struct st_mysql_plugin *mysqld_builtins[]; +extern struct st_mysql_plugin *mysql_optional_plugins[]; +extern struct st_mysql_plugin *mysql_mandatory_plugins[]; /** @note The order of the enumeration is critical. @@ -164,6 +165,8 @@ struct st_mysql_sys_var MYSQL_PLUGIN_VAR_HEADER; }; +static SHOW_TYPE pluginvar_show_type(st_mysql_sys_var *plugin_var); + /* sys_var class for access to all plugin variables visible to the user @@ -173,28 +176,44 @@ class sys_var_pluginvar: public sys_var public: struct st_plugin_int *plugin; struct st_mysql_sys_var *plugin_var; + /** + variable name from whatever is hard-coded in the plugin source + and doesn't have pluginname- prefix is replaced by an allocated name + with a plugin prefix. When plugin is uninstalled we need to restore the + pointer to point to the hard-coded value, because plugin may be + installed/uninstalled many times without reloading the shared object. + */ + const char *orig_pluginvar_name; static void *operator new(size_t size, MEM_ROOT *mem_root) - { return (void*) alloc_root(mem_root, (uint) size); } + { return (void*) alloc_root(mem_root, size); } static void operator delete(void *ptr_arg,size_t size) { TRASH(ptr_arg, size); } - sys_var_pluginvar(const char *name_arg, + sys_var_pluginvar(sys_var_chain *chain, const char *name_arg, struct st_mysql_sys_var *plugin_var_arg) - :sys_var(name_arg), plugin_var(plugin_var_arg) {} + :sys_var(chain, name_arg, plugin_var_arg->comment, + (plugin_var_arg->flags & PLUGIN_VAR_THDLOCAL ? SESSION : GLOBAL) | + (plugin_var_arg->flags & PLUGIN_VAR_READONLY ? READONLY : 0), + 0, -1, NO_ARG, pluginvar_show_type(plugin_var_arg), 0, 0, + VARIABLE_NOT_IN_BINLOG, 0, 0, 0, 0), + plugin_var(plugin_var_arg), orig_pluginvar_name(plugin_var_arg->name) + { plugin_var->name= name_arg; } sys_var_pluginvar *cast_pluginvar() { return this; } - bool is_readonly() const { return plugin_var->flags & PLUGIN_VAR_READONLY; } - bool check_type(enum_var_type type) - { return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; } bool check_update_type(Item_result type); SHOW_TYPE show_type(); uchar* real_value_ptr(THD *thd, enum_var_type type); TYPELIB* plugin_var_typelib(void); - uchar* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); - bool check(THD *thd, set_var *var); - bool check_default(enum_var_type type) { return is_readonly(); } - void set_default(THD *thd, enum_var_type type); - bool update(THD *thd, set_var *var); + uchar* do_value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); + uchar* session_value_ptr(THD *thd, LEX_STRING *base) + { return do_value_ptr(thd, OPT_SESSION, base); } + uchar* global_value_ptr(THD *thd, LEX_STRING *base) + { return do_value_ptr(thd, OPT_GLOBAL, base); } + bool do_check(THD *thd, set_var *var); + virtual void session_save_default(THD *thd, set_var *var) {} + virtual void global_save_default(THD *thd, set_var *var) {} + bool session_update(THD *thd, set_var *var); + bool global_update(THD *thd, set_var *var); }; @@ -209,8 +228,9 @@ static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *, static void unlock_variables(THD *thd, struct system_variables *vars); static void cleanup_variables(THD *thd, struct system_variables *vars); static void plugin_vars_free_values(sys_var *vars); -static void plugin_opt_set_limits(struct my_option *options, - const struct st_mysql_sys_var *opt); +static void restore_pluginvar_names(sys_var *first); +static void plugin_opt_set_limits(struct my_option *, + const struct st_mysql_sys_var *); #define my_intern_plugin_lock(A,B) intern_plugin_lock(A,B CALLER_INFO) #define my_intern_plugin_lock_ci(A,B) intern_plugin_lock(A,B ORIG_CALLER_INFO) static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin @@ -218,12 +238,6 @@ static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin static void intern_plugin_unlock(LEX *lex, plugin_ref plugin); static void reap_plugins(void); - -/* declared in set_var.cc */ -extern sys_var *intern_find_sys_var(const char *str, uint length, bool no_error); -extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd, - const char *name, longlong val); - #ifdef EMBEDDED_LIBRARY /* declared in sql_base.cc */ extern bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists); @@ -289,6 +303,11 @@ static int item_val_int(struct st_mysql_value *value, long long *buf) return 0; } +static int item_is_unsigned(struct st_mysql_value *value) +{ + Item *item= ((st_item_value_holder*)value)->item; + return item->unsigned_flag; +} static int item_val_real(struct st_mysql_value *value, double *buf) { @@ -617,10 +636,10 @@ bool plugin_is_ready(const LEX_STRING *name, int type) } -SHOW_COMP_OPTION sys_var_have_plugin::get_option() +SHOW_COMP_OPTION plugin_status(const char *name, int len, size_t type) { - LEX_STRING plugin_name= { (char *) plugin_name_str, plugin_name_len }; - return plugin_status(&plugin_name, plugin_type); + LEX_STRING plugin_name= { (char *) name, len }; + return plugin_status(&plugin_name, type); } @@ -776,6 +795,7 @@ static bool plugin_add(MEM_ROOT *tmp_root, tmp_plugin_ptr->state= PLUGIN_IS_FREED; } mysql_del_sys_var_chain(tmp.system_vars); + restore_pluginvar_names(tmp.system_vars); goto err; /* plugin was disabled */ @@ -802,12 +822,12 @@ static void plugin_deinitialize(struct st_plugin_int *plugin, bool ref_check) if (plugin->plugin->status_vars) { #ifdef FIX_LATER - /* - We have a problem right now where we can not prepend without - breaking backwards compatibility. We will fix this shortly so - that engines have "use names" and we wil use those for - CREATE TABLE, and use the plugin name then for adding automatic - variable names. + /** + @todo + unfortunately, status variables were introduced without a + pluginname_ namespace, that is pluginname_ was not added automatically + to status variable names. It should be fixed together with the next + incompatible API change. */ SHOW_VAR array[2]= { {plugin->plugin->name, (char*)plugin->plugin->status_vars, SHOW_ARRAY}, @@ -847,21 +867,21 @@ static void plugin_deinitialize(struct st_plugin_int *plugin, bool ref_check) plugin->name.str, plugin->ref_count); } - static void plugin_del(struct st_plugin_int *plugin) { DBUG_ENTER("plugin_del(plugin)"); safe_mutex_assert_owner(&LOCK_plugin); /* Free allocated strings before deleting the plugin. */ + rw_wrlock(&LOCK_system_variables_hash); + mysql_del_sys_var_chain(plugin->system_vars); + rw_unlock(&LOCK_system_variables_hash); + restore_pluginvar_names(plugin->system_vars); plugin_vars_free_values(plugin->system_vars); my_hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin); if (plugin->plugin_dl) plugin_dl_del(&plugin->plugin_dl->dl); plugin->state= PLUGIN_IS_FREED; plugin_array_version++; - rw_wrlock(&LOCK_system_variables_hash); - mysql_del_sys_var_chain(plugin->system_vars); - rw_unlock(&LOCK_system_variables_hash); free_root(&plugin->mem_root, MYF(0)); DBUG_VOID_RETURN; } @@ -1002,6 +1022,7 @@ void plugin_unlock_list(THD *thd, plugin_ref *list, uint count) static int plugin_initialize(struct st_plugin_int *plugin) { + int ret= 1; DBUG_ENTER("plugin_initialize"); safe_mutex_assert_owner(&LOCK_plugin); @@ -1063,9 +1084,15 @@ static int plugin_initialize(struct st_plugin_int *plugin) } } - DBUG_RETURN(0); + ret= 0; + err: - DBUG_RETURN(1); + /* maintain the obsolete @@have_innodb variable */ + if (!my_strcasecmp(&my_charset_latin1, plugin->name.str, "InnoDB")) + have_innodb= plugin->state & PLUGIN_IS_READY ? SHOW_OPTION_YES + : SHOW_OPTION_DISABLED; + + DBUG_RETURN(ret); } @@ -1120,7 +1147,8 @@ int plugin_init(int *argc, char **argv, int flags) struct st_mysql_plugin *plugin; struct st_plugin_int tmp, *plugin_ptr, **reap; MEM_ROOT tmp_root; - bool reaped_mandatory_plugin= FALSE; + bool reaped_mandatory_plugin= false; + bool mandatory= true; DBUG_ENTER("plugin_init"); if (initialized) @@ -1156,8 +1184,15 @@ int plugin_init(int *argc, char **argv, int flags) /* First we register builtin plugins */ - for (builtins= mysqld_builtins; *builtins; builtins++) + for (builtins= mysql_mandatory_plugins; *builtins || mandatory; builtins++) { + if (!*builtins) + { + builtins= mysql_optional_plugins; + mandatory= false; + if (!*builtins) + break; + } for (plugin= *builtins; plugin->info; plugin++) { if (opt_ignore_builtin_innodb && @@ -1169,6 +1204,7 @@ int plugin_init(int *argc, char **argv, int flags) tmp.name.str= (char *)plugin->name; tmp.name.length= strlen(plugin->name); tmp.state= 0; + tmp.is_mandatory= mandatory; free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE)); if (test_plugin_options(&tmp_root, &tmp, argc, argv)) tmp.state= PLUGIN_IS_DISABLED; @@ -1183,7 +1219,7 @@ int plugin_init(int *argc, char **argv, int flags) my_strcasecmp(&my_charset_latin1, plugin->name, "CSV")) continue; - if (plugin_ptr->state == PLUGIN_IS_UNINITIALIZED && + if (plugin_ptr->state != PLUGIN_IS_UNINITIALIZED || plugin_initialize(plugin_ptr)) goto err_unlock; @@ -1292,7 +1328,6 @@ static bool register_builtin(struct st_mysql_plugin *plugin, DBUG_RETURN(0); } - #ifdef NOT_USED_YET /* Register a plugin at run time. (note, this doesn't initialize a plugin) @@ -1325,7 +1360,10 @@ bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin) goto end; tmp.state= PLUGIN_IS_UNINITIALIZED; if ((result= register_builtin(plugin, &tmp, &ptr))) + { mysql_del_sys_var_chain(tmp.system_vars); + restore_pluginvar_names(tmp.system_vars); + } end: rw_unlock(&LOCK_system_variables_hash); @@ -1900,7 +1938,7 @@ static int check_func_bool(THD *thd, struct st_mysql_sys_var *var, void *save, st_mysql_value *value) { char buff[STRING_BUFFER_USUAL_SIZE]; - const char *strvalue= "NULL", *str; + const char *str; int result, length; long long tmp; @@ -1909,28 +1947,19 @@ static int check_func_bool(THD *thd, struct st_mysql_sys_var *var, length= sizeof(buff); if (!(str= value->val_str(value, buff, &length)) || (result= find_type(&bool_typelib, str, length, 1)-1) < 0) - { - if (str) - strvalue= str; goto err; - } } else { if (value->val_int(value, &tmp) < 0) goto err; if (tmp > 1) - { - llstr(tmp, buff); - strvalue= buff; goto err; - } result= (int) tmp; } *(my_bool *) save= -result; return 0; err: - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue); return 1; } @@ -1938,60 +1967,87 @@ err: static int check_func_int(THD *thd, struct st_mysql_sys_var *var, void *save, st_mysql_value *value) { - my_bool fixed; - long long tmp; + my_bool fixed1, fixed2; + long long orig, val; struct my_option options; - value->val_int(value, &tmp); + value->val_int(value, &orig); + val= orig; plugin_opt_set_limits(&options, var); if (var->flags & PLUGIN_VAR_UNSIGNED) - *(uint *)save= (uint) getopt_ull_limit_value((ulonglong) tmp, &options, - &fixed); + { + if ((fixed1= (!value->is_unsigned(value) && val < 0))) + val=0; + *(uint *)save= (uint) getopt_ull_limit_value((ulonglong) val, &options, + &fixed2); + } else - *(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed); + { + if ((fixed1= (value->is_unsigned(value) && val < 0))) + val=LONGLONG_MAX; + *(int *)save= (int) getopt_ll_limit_value(val, &options, &fixed2); + } - return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED, - var->name, (longlong) tmp); + return throw_bounds_warning(thd, var->name, fixed1 || fixed2, + value->is_unsigned(value), (longlong) orig); } static int check_func_long(THD *thd, struct st_mysql_sys_var *var, void *save, st_mysql_value *value) { - my_bool fixed; - long long tmp; + my_bool fixed1, fixed2; + long long orig, val; struct my_option options; - value->val_int(value, &tmp); + value->val_int(value, &orig); + val= orig; plugin_opt_set_limits(&options, var); if (var->flags & PLUGIN_VAR_UNSIGNED) - *(ulong *)save= (ulong) getopt_ull_limit_value((ulonglong) tmp, &options, - &fixed); + { + if ((fixed1= (!value->is_unsigned(value) && val < 0))) + val=0; + *(ulong *)save= (ulong) getopt_ull_limit_value((ulonglong) val, &options, + &fixed2); + } else - *(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed); + { + if ((fixed1= (value->is_unsigned(value) && val < 0))) + val=LONGLONG_MAX; + *(long *)save= (long) getopt_ll_limit_value(val, &options, &fixed2); + } - return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED, - var->name, (longlong) tmp); + return throw_bounds_warning(thd, var->name, fixed1 || fixed2, + value->is_unsigned(value), (longlong) orig); } static int check_func_longlong(THD *thd, struct st_mysql_sys_var *var, void *save, st_mysql_value *value) { - my_bool fixed; - long long tmp; + my_bool fixed1, fixed2; + long long orig, val; struct my_option options; - value->val_int(value, &tmp); + value->val_int(value, &orig); + val= orig; plugin_opt_set_limits(&options, var); if (var->flags & PLUGIN_VAR_UNSIGNED) - *(ulonglong *)save= getopt_ull_limit_value((ulonglong) tmp, &options, - &fixed); + { + if ((fixed1= (!value->is_unsigned(value) && val < 0))) + val=0; + *(ulonglong *)save= getopt_ull_limit_value((ulonglong) val, &options, + &fixed2); + } else - *(longlong *)save= getopt_ll_limit_value(tmp, &options, &fixed); + { + if ((fixed1= (value->is_unsigned(value) && val < 0))) + val=LONGLONG_MAX; + *(longlong *)save= getopt_ll_limit_value(val, &options, &fixed2); + } - return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED, - var->name, (longlong) tmp); + return throw_bounds_warning(thd, var->name, fixed1 || fixed2, + value->is_unsigned(value), (longlong) orig); } static int check_func_str(THD *thd, struct st_mysql_sys_var *var, @@ -2013,7 +2069,7 @@ static int check_func_enum(THD *thd, struct st_mysql_sys_var *var, void *save, st_mysql_value *value) { char buff[STRING_BUFFER_USUAL_SIZE]; - const char *strvalue= "NULL", *str; + const char *str; TYPELIB *typelib; long long tmp; long result; @@ -2029,28 +2085,20 @@ static int check_func_enum(THD *thd, struct st_mysql_sys_var *var, length= sizeof(buff); if (!(str= value->val_str(value, buff, &length))) goto err; - if ((result= (long)find_type(typelib, str, length, 1)-1) < 0) - { - strvalue= str; + if ((result= (long)find_type(typelib, str, length, 0) - 1) < 0) goto err; - } } else { if (value->val_int(value, &tmp)) goto err; - if (tmp >= typelib->count) - { - llstr(tmp, buff); - strvalue= buff; + if (tmp < 0 || tmp >= typelib->count) goto err; - } result= (long) tmp; } *(long*)save= result; return 0; err: - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue); return 1; } @@ -2059,7 +2107,7 @@ static int check_func_set(THD *thd, struct st_mysql_sys_var *var, void *save, st_mysql_value *value) { char buff[STRING_BUFFER_USUAL_SIZE], *error= 0; - const char *strvalue= "NULL", *str; + const char *str; TYPELIB *typelib; ulonglong result; uint error_len= 0; // init as only set on error @@ -2079,11 +2127,7 @@ static int check_func_set(THD *thd, struct st_mysql_sys_var *var, result= find_set(typelib, str, length, NULL, &error, &error_len, ¬_used); if (error_len) - { - strmake(buff, error, min(sizeof(buff), error_len)); - strvalue= buff; goto err; - } } else { @@ -2091,16 +2135,11 @@ static int check_func_set(THD *thd, struct st_mysql_sys_var *var, goto err; if (unlikely((result >= (ULL(1) << typelib->count)) && (typelib->count < sizeof(long)*8))) - { - llstr(result, buff); - strvalue= buff; goto err; - } } *(ulonglong*)save= result; return 0; err: - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue); return 1; } @@ -2160,7 +2199,7 @@ sys_var *find_sys_var(THD *thd, const char *str, uint length) pthread_mutex_lock(&LOCK_plugin); rw_rdlock(&LOCK_system_variables_hash); - if ((var= intern_find_sys_var(str, length, false)) && + if ((var= intern_find_sys_var(str, length)) && (pi= var->cast_pluginvar())) { rw_unlock(&LOCK_system_variables_hash); @@ -2183,7 +2222,7 @@ sys_var *find_sys_var(THD *thd, const char *str, uint length) If the variable exists but the plugin it is associated with is not ready then the intern_plugin_lock did not raise an error, so we do it here. */ - if (pi && !var) + if (!var) my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str); DBUG_RETURN(var); } @@ -2333,6 +2372,15 @@ static st_bookmark *register_var(const char *plugin, const char *name, return result; } +static void restore_pluginvar_names(sys_var *first) +{ + for (sys_var *var= first; var; var= var->next) + { + sys_var_pluginvar *pv= var->cast_pluginvar(); + pv->plugin_var->name= pv->orig_pluginvar_name; + } +} + /* returns a pointer to the memory which holds the thd-local variable or @@ -2386,7 +2434,7 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) st_bookmark *v= (st_bookmark*) my_hash_element(&bookmark_hash,idx); if (v->version <= thd->variables.dynamic_variables_version || - !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) || + !(var= intern_find_sys_var(v->key + 1, v->name_len)) || !(pi= var->cast_pluginvar()) || v->key[0] != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK)) continue; @@ -2479,7 +2527,7 @@ static void cleanup_variables(THD *thd, struct system_variables *vars) { v= (st_bookmark*) my_hash_element(&bookmark_hash, idx); if (v->version > vars->dynamic_variables_version || - !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) || + !(var= intern_find_sys_var(v->key + 1, v->name_len)) || !(pivar= var->cast_pluginvar()) || v->key[0] != (pivar->plugin_var->flags & PLUGIN_VAR_TYPEMASK)) continue; @@ -2558,7 +2606,7 @@ static void plugin_vars_free_values(sys_var *vars) /* Free the string from global_system_variables. */ char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL); DBUG_PRINT("plugin", ("freeing value for: '%s' addr: 0x%lx", - var->name, (long) valptr)); + var->name.str, (long) valptr)); my_free(*valptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); *valptr= NULL; } @@ -2566,43 +2614,44 @@ static void plugin_vars_free_values(sys_var *vars) DBUG_VOID_RETURN; } - -bool sys_var_pluginvar::check_update_type(Item_result type) +static SHOW_TYPE pluginvar_show_type(st_mysql_sys_var *plugin_var) { - if (is_readonly()) - return 1; switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) { + case PLUGIN_VAR_BOOL: + return SHOW_MY_BOOL; case PLUGIN_VAR_INT: + return SHOW_INT; case PLUGIN_VAR_LONG: + return SHOW_LONG; case PLUGIN_VAR_LONGLONG: - return type != INT_RESULT; + return SHOW_LONGLONG; case PLUGIN_VAR_STR: - return type != STRING_RESULT; + return SHOW_CHAR_PTR; + case PLUGIN_VAR_ENUM: + case PLUGIN_VAR_SET: + return SHOW_CHAR; default: - return 0; + DBUG_ASSERT(0); + return SHOW_UNDEF; } } -SHOW_TYPE sys_var_pluginvar::show_type() +bool sys_var_pluginvar::check_update_type(Item_result type) { switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) { - case PLUGIN_VAR_BOOL: - return SHOW_MY_BOOL; case PLUGIN_VAR_INT: - return SHOW_INT; case PLUGIN_VAR_LONG: - return SHOW_LONG; case PLUGIN_VAR_LONGLONG: - return SHOW_LONGLONG; + return type != INT_RESULT; case PLUGIN_VAR_STR: - return SHOW_CHAR_PTR; + return type != STRING_RESULT; case PLUGIN_VAR_ENUM: + case PLUGIN_VAR_BOOL: case PLUGIN_VAR_SET: - return SHOW_CHAR; + return type != STRING_RESULT && type != INT_RESULT; default: - DBUG_ASSERT(0); - return SHOW_UNDEF; + return true; } } @@ -2639,8 +2688,8 @@ TYPELIB* sys_var_pluginvar::plugin_var_typelib(void) } -uchar* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type, - LEX_STRING *base) +uchar* sys_var_pluginvar::do_value_ptr(THD *thd, enum_var_type type, + LEX_STRING *base) { uchar* result; @@ -2649,139 +2698,104 @@ uchar* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type, if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM) result= (uchar*) get_type(plugin_var_typelib(), *(ulong*)result); else if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_SET) - { - char buffer[STRING_BUFFER_USUAL_SIZE]; - String str(buffer, sizeof(buffer), system_charset_info); - TYPELIB *typelib= plugin_var_typelib(); - ulonglong mask= 1, value= *(ulonglong*) result; - uint i; - - str.length(0); - for (i= 0; i < typelib->count; i++, mask<<=1) - { - if (!(value & mask)) - continue; - str.append(typelib->type_names[i], typelib->type_lengths - ? typelib->type_lengths[i] - : strlen(typelib->type_names[i])); - str.append(','); - } - - result= (uchar*) ""; - if (str.length()) - result= (uchar*) thd->strmake(str.ptr(), str.length()-1); - } + result= (uchar*) set_to_string(thd, 0, *(ulonglong*) result, + plugin_var_typelib()->type_names); return result; } - -bool sys_var_pluginvar::check(THD *thd, set_var *var) +bool sys_var_pluginvar::do_check(THD *thd, set_var *var) { st_item_value_holder value; - DBUG_ASSERT(is_readonly() || plugin_var->check); + DBUG_ASSERT(!is_readonly()); + DBUG_ASSERT(plugin_var->check); value.value_type= item_value_type; value.val_str= item_val_str; value.val_int= item_val_int; value.val_real= item_val_real; + value.is_unsigned= item_is_unsigned; value.item= var->value; - return is_readonly() || - plugin_var->check(thd, plugin_var, &var->save_result, &value); + return plugin_var->check(thd, plugin_var, &var->save_result, &value); } - -void sys_var_pluginvar::set_default(THD *thd, enum_var_type type) +bool sys_var_pluginvar::session_update(THD *thd, set_var *var) { - const void *src; - void *tgt; - - DBUG_ASSERT(is_readonly() || plugin_var->update); - - if (is_readonly()) - return; + DBUG_ASSERT(!is_readonly()); + DBUG_ASSERT(plugin_var->flags & PLUGIN_VAR_THDLOCAL); + DBUG_ASSERT(thd == current_thd); pthread_mutex_lock(&LOCK_global_system_variables); - tgt= real_value_ptr(thd, type); - src= ((void **) (plugin_var + 1) + 1); + void *tgt= real_value_ptr(thd, var->type); + const void *src= var->value ? (void*)&var->save_result + : (void*)real_value_ptr(thd, OPT_GLOBAL); + pthread_mutex_unlock(&LOCK_global_system_variables); + plugin_var->update(thd, plugin_var, tgt, src); - if (plugin_var->flags & PLUGIN_VAR_THDLOCAL) - { - if (type != OPT_GLOBAL) - src= real_value_ptr(thd, OPT_GLOBAL); - else - switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) { - case PLUGIN_VAR_INT: - src= &((thdvar_uint_t*) plugin_var)->def_val; - break; - case PLUGIN_VAR_LONG: - src= &((thdvar_ulong_t*) plugin_var)->def_val; - break; - case PLUGIN_VAR_LONGLONG: - src= &((thdvar_ulonglong_t*) plugin_var)->def_val; - break; - case PLUGIN_VAR_ENUM: - src= &((thdvar_enum_t*) plugin_var)->def_val; - break; - case PLUGIN_VAR_SET: - src= &((thdvar_set_t*) plugin_var)->def_val; - break; - case PLUGIN_VAR_BOOL: - src= &((thdvar_bool_t*) plugin_var)->def_val; - break; - case PLUGIN_VAR_STR: - src= &((thdvar_str_t*) plugin_var)->def_val; - break; - default: - DBUG_ASSERT(0); - } - } - - /* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */ - DBUG_ASSERT(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || - thd == current_thd); - - if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || type == OPT_GLOBAL) - { - plugin_var->update(thd, plugin_var, tgt, src); - pthread_mutex_unlock(&LOCK_global_system_variables); - } - else - { - pthread_mutex_unlock(&LOCK_global_system_variables); - plugin_var->update(thd, plugin_var, tgt, src); - } + return false; } - -bool sys_var_pluginvar::update(THD *thd, set_var *var) +bool sys_var_pluginvar::global_update(THD *thd, set_var *var) { - void *tgt; - - DBUG_ASSERT(is_readonly() || plugin_var->update); + DBUG_ASSERT(!is_readonly()); + safe_mutex_assert_owner(&LOCK_global_system_variables); - /* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */ - DBUG_ASSERT(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || - thd == current_thd); + void *tgt= real_value_ptr(thd, var->type); + const void *src= &var->save_result; - if (is_readonly()) - return 1; - - pthread_mutex_lock(&LOCK_global_system_variables); - tgt= real_value_ptr(thd, var->type); - - if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || var->type == OPT_GLOBAL) - { - /* variable we are updating has global scope, so we unlock after updating */ - plugin_var->update(thd, plugin_var, tgt, &var->save_result); - pthread_mutex_unlock(&LOCK_global_system_variables); - } - else + if (!var->value) { - pthread_mutex_unlock(&LOCK_global_system_variables); - plugin_var->update(thd, plugin_var, tgt, &var->save_result); + switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) { + case PLUGIN_VAR_INT: + src= &((sysvar_uint_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_LONG: + src= &((sysvar_ulong_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_LONGLONG: + src= &((sysvar_ulonglong_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_ENUM: + src= &((sysvar_enum_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_SET: + src= &((sysvar_set_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_BOOL: + src= &((sysvar_bool_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_STR: + src= &((sysvar_str_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL: + src= &((thdvar_uint_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL: + src= &((thdvar_ulong_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL: + src= &((thdvar_ulonglong_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL: + src= &((thdvar_enum_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL: + src= &((thdvar_set_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL: + src= &((thdvar_bool_t*) plugin_var)->def_val; + break; + case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL: + src= &((thdvar_str_t*) plugin_var)->def_val; + break; + default: + DBUG_ASSERT(0); + } } - return 0; + + plugin_var->update(thd, plugin_var, tgt, src); + + return false; } @@ -2944,40 +2958,48 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, DBUG_ENTER("construct_options"); - options[0].name= plugin_name_ptr= (char*) alloc_root(mem_root, - plugin_name_len + 1); + plugin_name_ptr= (char*) alloc_root(mem_root, plugin_name_len + 1); strcpy(plugin_name_ptr, plugin_name); my_casedn_str(&my_charset_latin1, plugin_name_ptr); convert_underscore_to_dash(plugin_name_ptr, plugin_name_len); - /* support --skip-plugin-foo syntax */ - options[1].name= plugin_name_with_prefix_ptr= (char*) alloc_root(mem_root, - plugin_name_len + - plugin_dash.length + 1); - strxmov(plugin_name_with_prefix_ptr, plugin_dash.str, options[0].name, NullS); - - options[0].id= options[1].id= 256; /* must be >255. dup id ok */ - options[0].var_type= options[1].var_type= GET_ENUM; - options[0].arg_type= options[1].arg_type= OPT_ARG; - options[0].def_value= options[1].def_value= 1; /* ON */ - options[0].typelib= options[1].typelib= &global_plugin_typelib; - - strxnmov(comment, max_comment_len, "Enable or disable ", plugin_name, - " plugin. Possible values are ON, OFF, FORCE (don't start " - "if the plugin fails to load).", NullS); - options[0].comment= comment; + plugin_name_with_prefix_ptr= (char*) alloc_root(mem_root, + plugin_name_len + + plugin_dash.length + 1); + strxmov(plugin_name_with_prefix_ptr, plugin_dash.str, plugin_name_ptr, NullS); + + if (!tmp->is_mandatory) + { + /* support --skip-plugin-foo syntax */ + options[0].name= plugin_name_ptr; + options[1].name= plugin_name_with_prefix_ptr; + options[0].id= options[1].id= 0; + options[0].var_type= options[1].var_type= GET_ENUM; + options[0].arg_type= options[1].arg_type= OPT_ARG; + options[0].def_value= options[1].def_value= 1; /* ON */ + options[0].typelib= options[1].typelib= &global_plugin_typelib; + + strxnmov(comment, max_comment_len, "Enable or disable ", plugin_name, + " plugin. Possible values are ON, OFF, FORCE (don't start " + "if the plugin fails to load).", NullS); + options[0].comment= comment; + /* + Allocate temporary space for the value of the tristate. + This option will have a limited lifetime and is not used beyond + server initialization. + GET_ENUM value is an unsigned integer. + */ + options[0].value= options[1].value= + (uchar **)alloc_root(mem_root, sizeof(uint)); + *((uint*) options[0].value)= (uint) options[0].def_value; - /* - Allocate temporary space for the value of the tristate. - This option will have a limited lifetime and is not used beyond - server initialization. - GET_ENUM value is an integer. - */ - options[0].value= options[1].value= (uchar **)alloc_root(mem_root, - sizeof(int)); - *((uint*) options[0].value)= *((uint*) options[1].value)= - (uint) options[0].def_value; + options+= 2; + } - options+= 2; + if (!my_strcasecmp(&my_charset_latin1, plugin_name_ptr, "NDBCLUSTER")) + { + plugin_name_ptr= const_cast("ndb"); // Use legacy "ndb" prefix + plugin_name_len= 3; + } /* Two passes as the 2nd pass will take pointer addresses for use @@ -3125,7 +3147,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, options->name= optname; options->comment= opt->comment; options->app_type= opt; - options->id= (options-1)->id + 1; + options->id= 0; plugin_opt_set_limits(options, opt); @@ -3166,13 +3188,20 @@ static my_option *construct_help_options(MEM_ROOT *mem_root, bzero(opts, sizeof(my_option) * count); + /** + some plugin variables (those that don't have PLUGIN_VAR_NOSYSVAR flag) + have their names prefixed with the plugin name. Restore the names here + to get the correct (not double-prefixed) help text. + We won't need @@sysvars anymore and don't care about their proper names. + */ + restore_pluginvar_names(p->system_vars); + if (construct_options(mem_root, p, opts)) DBUG_RETURN(NULL); DBUG_RETURN(opts); } - /** Create and register system variables supplied from the plugin and assigns initial values from corresponding command line arguments. @@ -3197,18 +3226,17 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, int *argc, char **argv) { struct sys_var_chain chain= { NULL, NULL }; - my_bool can_disable; bool disable_plugin; - enum_plugin_load_policy plugin_load_policy= PLUGIN_ON; + enum_plugin_load_policy plugin_load_policy= tmp->is_mandatory ? PLUGIN_FORCE : PLUGIN_ON; MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ? &tmp->mem_root : &plugin_mem_root; st_mysql_sys_var **opt; my_option *opts= NULL; + LEX_STRING plugin_name; char *varname; int error; - st_mysql_sys_var *o; - sys_var *v; + sys_var *v __attribute__((unused)); struct st_bookmark *var; uint len, count= EXTRA_OPTIONS; DBUG_ENTER("test_plugin_options"); @@ -3244,7 +3272,8 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, We adjust the default value to account for the hardcoded exceptions we have set for the federated and ndbcluster storage engines. */ - opts[0].def_value= opts[1].def_value= (int)plugin_load_policy; + if (!tmp->is_mandatory) + opts[0].def_value= opts[1].def_value= plugin_load_policy; error= handle_options(argc, &argv, opts, get_one_plugin_option); (*argc)++; /* add back one for the program name */ @@ -3259,24 +3288,12 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, Set plugin loading policy from option value. First element in the option list is always the option value. */ - plugin_load_policy= (enum_plugin_load_policy)*(uint*)opts[0].value; + if (!tmp->is_mandatory) + plugin_load_policy= (enum_plugin_load_policy)*(uint*)opts[0].value; } disable_plugin= (plugin_load_policy == PLUGIN_OFF); - /* - The 'MyISAM' and 'Memory' storage engines currently can't be disabled. - */ - can_disable= - my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") && - my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY"); - - tmp->is_mandatory= (plugin_load_policy == PLUGIN_FORCE) || !can_disable; - - if (disable_plugin && !can_disable) - { - sql_print_warning("Plugin '%s' cannot be disabled", tmp->name.str); - disable_plugin= FALSE; - } + tmp->is_mandatory= (plugin_load_policy == PLUGIN_FORCE); /* If the plugin is disabled it should not be initialized. @@ -3291,34 +3308,37 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, DBUG_RETURN(1); } + if (!my_strcasecmp(&my_charset_latin1, tmp->name.str, "NDBCLUSTER")) + { + plugin_name.str= const_cast("ndb"); // Use legacy "ndb" prefix + plugin_name.length= 3; + } + else + plugin_name= tmp->name; + error= 1; for (opt= tmp->plugin->system_vars; opt && *opt; opt++) { + st_mysql_sys_var *o; if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR)) continue; - if ((var= find_bookmark(tmp->name.str, o->name, o->flags))) - v= new (mem_root) sys_var_pluginvar(var->key + 1, o); + if ((var= find_bookmark(plugin_name.str, o->name, o->flags))) + v= new (mem_root) sys_var_pluginvar(&chain, var->key + 1, o); else { - len= tmp->name.length + strlen(o->name) + 2; + len= plugin_name.length + strlen(o->name) + 2; varname= (char*) alloc_root(mem_root, len); - strxmov(varname, tmp->name.str, "-", o->name, NullS); + strxmov(varname, plugin_name.str, "-", o->name, NullS); my_casedn_str(&my_charset_latin1, varname); convert_dash_to_underscore(varname, len-1); - v= new (mem_root) sys_var_pluginvar(varname, o); + v= new (mem_root) sys_var_pluginvar(&chain, varname, o); } DBUG_ASSERT(v); /* check that an object was actually constructed */ - /* - Add to the chain of variables. - Done like this for easier debugging so that the - pointer to v is not lost on optimized builds. - */ - v->chain_sys_var(&chain); } /* end for */ if (chain.first) { chain.last->next = NULL; - if (mysql_add_sys_var_chain(chain.first, NULL)) + if (mysql_add_sys_var_chain(chain.first)) { sql_print_error("Plugin '%s' has conflicting system variables", tmp->name.str); @@ -3339,49 +3359,26 @@ err: Help Verbose text with Plugin System Variables ****************************************************************************/ -static int option_cmp(my_option *a, my_option *b) -{ - return my_strcasecmp(&my_charset_latin1, a->name, b->name); -} - -void my_print_help_inc_plugins(my_option *main_options, uint size) +void add_plugin_options(DYNAMIC_ARRAY *options, MEM_ROOT *mem_root) { - DYNAMIC_ARRAY all_options; struct st_plugin_int *p; - MEM_ROOT mem_root; my_option *opt; - init_alloc_root(&mem_root, 4096, 4096); - my_init_dynamic_array(&all_options, sizeof(my_option), size, size/4); - - if (initialized) - for (uint idx= 0; idx < plugin_array.elements; idx++) - { - p= *dynamic_element(&plugin_array, idx, struct st_plugin_int **); - - if (!p->plugin->system_vars || - !(opt= construct_help_options(&mem_root, p))) - continue; - - /* Only options with a non-NULL comment are displayed in help text */ - for (;opt->id; opt++) - if (opt->comment) - insert_dynamic(&all_options, (uchar*) opt); - } - - for (;main_options->id; main_options++) - insert_dynamic(&all_options, (uchar*) main_options); - - sort_dynamic(&all_options, (qsort_cmp) option_cmp); + if (!initialized) + return; - /* main_options now points to the empty option terminator */ - insert_dynamic(&all_options, (uchar*) main_options); + for (uint idx= 0; idx < plugin_array.elements; idx++) + { + p= *dynamic_element(&plugin_array, idx, struct st_plugin_int **); - my_print_help((my_option*) all_options.buffer); - my_print_variables((my_option*) all_options.buffer); + if (!(opt= construct_help_options(mem_root, p))) + continue; - delete_dynamic(&all_options); - free_root(&mem_root, MYF(0)); + /* Only options with a non-NULL comment are displayed in help text */ + for (;opt->name; opt++) + if (opt->comment) + insert_dynamic(options, (uchar*) opt); + } } -- cgit v1.2.1 From dae9a0fe1ff6a7568933e832f56398c10f788d58 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 23 Dec 2009 17:51:03 +0100 Subject: backport typos found --- sql/sql_plugin.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 953f0b3c680..c5f737434be 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -440,7 +440,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report) (plugin_dl.version >> 8) > (MYSQL_PLUGIN_INTERFACE_VERSION >> 8)) { free_plugin_mem(&plugin_dl); - report_error(report, ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, 0, + report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, 0, "plugin interface version mismatch"); DBUG_RETURN(0); } @@ -469,8 +469,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report) if (!(sym= dlsym(plugin_dl.handle, plugin_declarations_sym))) { free_plugin_mem(&plugin_dl); - report_error(report, ER_CANT_FIND_DL_ENTRY, MYF(0), - plugin_declarations_sym); + report_error(report, ER_CANT_FIND_DL_ENTRY, plugin_declarations_sym); DBUG_RETURN(0); } -- cgit v1.2.1 From 97b8f8cf641de6df006bbae506130152fa273686 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 6 Jan 2010 22:42:07 -0700 Subject: WL#2360 Performance schema Part IV: sql instrumentation --- sql/sql_plugin.cc | 206 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 125 insertions(+), 81 deletions(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index c5f737434be..0a7864631ae 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -109,7 +109,7 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= following variables/structures. We are always manipulating ref count, so a rwlock here is unneccessary. */ -pthread_mutex_t LOCK_plugin; +mysql_mutex_t LOCK_plugin; static DYNAMIC_ARRAY plugin_dl_array; static DYNAMIC_ARRAY plugin_array; static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM]; @@ -196,7 +196,7 @@ public: (plugin_var_arg->flags & PLUGIN_VAR_THDLOCAL ? SESSION : GLOBAL) | (plugin_var_arg->flags & PLUGIN_VAR_READONLY ? READONLY : 0), 0, -1, NO_ARG, pluginvar_show_type(plugin_var_arg), 0, 0, - VARIABLE_NOT_IN_BINLOG, 0, 0, 0, 0), + VARIABLE_NOT_IN_BINLOG, 0, 0, 0, 0, PARSE_NORMAL), plugin_var(plugin_var_arg), orig_pluginvar_name(plugin_var_arg->name) { plugin_var->name= name_arg; } sys_var_pluginvar *cast_pluginvar() { return this; } @@ -557,7 +557,7 @@ static void plugin_dl_del(const LEX_STRING *dl) uint i; DBUG_ENTER("plugin_dl_del"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); for (i= 0; i < plugin_dl_array.elements; i++) { @@ -589,7 +589,7 @@ static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int ty if (! initialized) DBUG_RETURN(0); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (type == MYSQL_ANY_PLUGIN) { @@ -614,14 +614,14 @@ static SHOW_COMP_OPTION plugin_status(const LEX_STRING *name, int type) SHOW_COMP_OPTION rc= SHOW_OPTION_NO; struct st_plugin_int *plugin; DBUG_ENTER("plugin_is_ready"); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if ((plugin= plugin_find_internal(name, type))) { rc= SHOW_OPTION_DISABLED; if (plugin->state == PLUGIN_IS_READY) rc= SHOW_OPTION_YES; } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(rc); } @@ -647,7 +647,7 @@ static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO) st_plugin_int *pi= plugin_ref_to_int(rc); DBUG_ENTER("intern_plugin_lock"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (pi->state & (PLUGIN_IS_READY | PLUGIN_IS_UNINITIALIZED)) { @@ -686,9 +686,9 @@ plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO) LEX *lex= thd ? thd->lex : 0; plugin_ref rc; DBUG_ENTER("plugin_lock"); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); rc= my_intern_plugin_lock_ci(lex, *ptr); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(rc); } @@ -700,10 +700,10 @@ plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type plugin_ref rc= NULL; st_plugin_int *plugin; DBUG_ENTER("plugin_lock_by_name"); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if ((plugin= plugin_find_internal(name, type))) rc= my_intern_plugin_lock_ci(lex, plugin_int_to_ref(plugin)); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(rc); } @@ -816,7 +816,7 @@ static void plugin_deinitialize(struct st_plugin_int *plugin, bool ref_check) deinitialization to deadlock if plugins have worker threads with plugin locks */ - safe_mutex_assert_not_owner(&LOCK_plugin); + mysql_mutex_assert_not_owner(&LOCK_plugin); if (plugin->plugin->status_vars) { @@ -869,11 +869,11 @@ static void plugin_deinitialize(struct st_plugin_int *plugin, bool ref_check) static void plugin_del(struct st_plugin_int *plugin) { DBUG_ENTER("plugin_del(plugin)"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); /* Free allocated strings before deleting the plugin. */ - rw_wrlock(&LOCK_system_variables_hash); + mysql_rwlock_wrlock(&LOCK_system_variables_hash); mysql_del_sys_var_chain(plugin->system_vars); - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); restore_pluginvar_names(plugin->system_vars); plugin_vars_free_values(plugin->system_vars); my_hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin); @@ -903,7 +903,7 @@ static void reap_plugins(void) uint count, idx; struct st_plugin_int *plugin, **reap, **list; - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (!reap_needed) return; @@ -924,13 +924,13 @@ static void reap_plugins(void) } } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); list= reap; while ((plugin= *(--list))) plugin_deinitialize(plugin, true); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); while ((plugin= *(--reap))) plugin_del(plugin); @@ -944,7 +944,7 @@ static void intern_plugin_unlock(LEX *lex, plugin_ref plugin) st_plugin_int *pi; DBUG_ENTER("intern_plugin_unlock"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (!plugin) DBUG_VOID_RETURN; @@ -997,10 +997,10 @@ void plugin_unlock(THD *thd, plugin_ref plugin) if (!plugin_dlib(plugin)) DBUG_VOID_RETURN; #endif - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); intern_plugin_unlock(lex, plugin); reap_plugins(); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_VOID_RETURN; } @@ -1010,11 +1010,11 @@ void plugin_unlock_list(THD *thd, plugin_ref *list, uint count) LEX *lex= thd ? thd->lex : 0; DBUG_ENTER("plugin_unlock_list"); DBUG_ASSERT(list); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); while (count--) intern_plugin_unlock(lex, *list++); reap_plugins(); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_VOID_RETURN; } @@ -1024,7 +1024,7 @@ static int plugin_initialize(struct st_plugin_int *plugin) int ret= 1; DBUG_ENTER("plugin_initialize"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (plugin_type_initialize[plugin->plugin->type]) { if ((*plugin_type_initialize[plugin->plugin->type])(plugin)) @@ -1130,6 +1130,26 @@ static inline void convert_underscore_to_dash(char *str, int len) *p= '-'; } +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key key_LOCK_plugin; + +static PSI_mutex_info all_plugin_mutexes[]= +{ + { &key_LOCK_plugin, "LOCK_plugin", PSI_FLAG_GLOBAL} +}; + +static void init_plugin_psi_keys(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_plugin_mutexes); + PSI_server->register_mutex(category, all_plugin_mutexes, count); +} +#endif /* HAVE_PSI_INTERFACE */ /* The logic is that we first load and initialize all compiled in plugins. @@ -1153,6 +1173,10 @@ int plugin_init(int *argc, char **argv, int flags) if (initialized) DBUG_RETURN(0); +#ifdef HAVE_PSI_INTERFACE + init_plugin_psi_keys(); +#endif + init_alloc_root(&plugin_mem_root, 4096, 4096); init_alloc_root(&tmp_root, 4096, 4096); @@ -1161,7 +1185,7 @@ int plugin_init(int *argc, char **argv, int flags) goto err; - pthread_mutex_init(&LOCK_plugin, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_plugin, &LOCK_plugin, MY_MUTEX_INIT_FAST); if (my_init_dynamic_array(&plugin_dl_array, sizeof(struct st_plugin_dl *),16,16) || @@ -1176,7 +1200,7 @@ int plugin_init(int *argc, char **argv, int flags) goto err; } - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); initialized= 1; @@ -1204,6 +1228,26 @@ int plugin_init(int *argc, char **argv, int flags) tmp.name.length= strlen(plugin->name); tmp.state= 0; tmp.is_mandatory= mandatory; + + /* + If the performance schema is compiled in, + treat the storage engine plugin as 'mandatory', + to suppress any plugin-level options such as '--performance-schema'. + This is specific to the performance schema, and is done on purpose: + the server-level option '--performance-schema' controls the overall + performance schema initialization, which consists of much more that + the underlying storage engine initialization. + See mysqld.cc, set_vars.cc. + Suppressing ways to interfere directly with the storage engine alone + prevents awkward situations where: + - the user wants the performance schema functionality, by using + '--enable-performance-schema' (the server option), + - yet disable explicitly a component needed for the functionality + to work, by using '--skip-performance-schema' (the plugin) + */ + if (!my_strcasecmp(&my_charset_latin1, plugin->name, "PERFORMANCE_SCHEMA")) + tmp.is_mandatory= true; + free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE)); if (test_plugin_options(&tmp_root, &tmp, argc, argv)) tmp.state= PLUGIN_IS_DISABLED; @@ -1239,7 +1283,7 @@ int plugin_init(int *argc, char **argv, int flags) /* should now be set to MyISAM storage engine */ DBUG_ASSERT(global_system_variables.table_plugin); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); /* Register all dynamic plugins */ if (!(flags & PLUGIN_INIT_SKIP_DYNAMIC_LOADING)) @@ -1257,7 +1301,7 @@ int plugin_init(int *argc, char **argv, int flags) Now we initialize all remaining plugins */ - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); reap= (st_plugin_int **) my_alloca((plugin_array.elements+1) * sizeof(void*)); *(reap++)= NULL; @@ -1279,15 +1323,15 @@ int plugin_init(int *argc, char **argv, int flags) */ while ((plugin_ptr= *(--reap))) { - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); if (plugin_ptr->is_mandatory) reaped_mandatory_plugin= TRUE; plugin_deinitialize(plugin_ptr, true); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); plugin_del(plugin_ptr); } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); my_afree(reap); if (reaped_mandatory_plugin) goto err; @@ -1298,7 +1342,7 @@ end: DBUG_RETURN(0); err_unlock: - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); err: free_root(&tmp_root, MYF(0)); DBUG_RETURN(1); @@ -1352,8 +1396,8 @@ bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin) tmp.name.str= (char *)plugin->name; tmp.name.length= strlen(plugin->name); - pthread_mutex_lock(&LOCK_plugin); - rw_wrlock(&LOCK_system_variables_hash); + mysql_mutex_lock(&LOCK_plugin); + mysql_rwlock_wrlock(&LOCK_system_variables_hash); if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL)) goto end; @@ -1365,8 +1409,8 @@ bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin) } end: - rw_unlock(&LOCK_system_variables_hash); - pthread_mutex_unlock(&LOCK_plugin); + mysql_rwlock_unlock(&LOCK_system_variables_hash); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(result);; } @@ -1429,10 +1473,10 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) /* there're no other threads running yet, so we don't need a mutex. but plugin_add() before is designed to work in multi-threaded - environment, and it uses safe_mutex_assert_owner(), so we lock + environment, and it uses mysql_mutex_assert_owner(), so we lock the mutex here to satisfy the assert */ - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); while (!(error= read_record_info.read_record(&read_record_info))) { DBUG_PRINT("info", ("init plugin record")); @@ -1448,7 +1492,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) str_name.c_ptr(), str_dl.c_ptr()); free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE)); } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); if (error > 0) sql_print_error(ER(ER_GET_ERRNO), my_errno); end_read_record(&read_record_info); @@ -1500,7 +1544,7 @@ static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv, } dl= name; - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if ((plugin_dl= plugin_dl_add(&dl, REPORT_TO_LOG))) { for (plugin= plugin_dl->plugins; plugin->info; plugin++) @@ -1518,11 +1562,11 @@ static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv, else { free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE)); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG)) goto error; } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); name.length= dl.length= 0; dl.str= NULL; name.str= p= buffer; str= &name; @@ -1543,7 +1587,7 @@ static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv, } DBUG_RETURN(FALSE); error: - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); sql_print_error("Couldn't load plugin named '%s' with soname '%s'.", name.str, dl.str); DBUG_RETURN(TRUE); @@ -1559,7 +1603,7 @@ void plugin_shutdown(void) if (initialized) { - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); reap_needed= true; @@ -1604,7 +1648,7 @@ void plugin_shutdown(void) if (plugins[i]->state == PLUGIN_IS_DELETED) plugins[i]->state= PLUGIN_IS_DYING; } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); /* We loop through all plugins and call deinit() if they have one. @@ -1625,9 +1669,9 @@ void plugin_shutdown(void) /* It's perfectly safe not to lock LOCK_plugin, as there're no concurrent threads anymore. But some functions called from here - use safe_mutex_assert_owner(), so we lock the mutex to satisfy it + use mysql_mutex_assert_owner(), so we lock the mutex to satisfy it */ - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); /* We defer checking ref_counts until after all plugins are deinitialized @@ -1648,10 +1692,10 @@ void plugin_shutdown(void) cleanup_variables(NULL, &global_system_variables); cleanup_variables(NULL, &max_system_variables); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); initialized= 0; - pthread_mutex_destroy(&LOCK_plugin); + mysql_mutex_destroy(&LOCK_plugin); my_afree(plugins); } @@ -1699,14 +1743,14 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl if (! (table = open_ltable(thd, &tables, TL_WRITE, 0))) DBUG_RETURN(TRUE); - pthread_mutex_lock(&LOCK_plugin); - rw_wrlock(&LOCK_system_variables_hash); + mysql_mutex_lock(&LOCK_plugin); + mysql_rwlock_wrlock(&LOCK_system_variables_hash); my_load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv, NULL); error= plugin_add(thd->mem_root, name, dl, &argc, argv, REPORT_TO_USER); if (argv) free_defaults(argv); - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); if (error || !(tmp= plugin_find_internal(name, MYSQL_ANY_PLUGIN))) goto err; @@ -1746,14 +1790,14 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl goto deinit; } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(FALSE); deinit: tmp->state= PLUGIN_IS_DELETED; reap_needed= true; reap_plugins(); err: - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(TRUE); } @@ -1773,7 +1817,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) if (! (table= open_ltable(thd, &tables, TL_WRITE, 0))) DBUG_RETURN(TRUE); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if (!(plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN))) { my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str); @@ -1794,7 +1838,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) else reap_needed= true; reap_plugins(); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); uchar user_key[MAX_KEY_LENGTH]; table->use_all_columns(); @@ -1821,7 +1865,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) } DBUG_RETURN(FALSE); err: - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(TRUE); } @@ -1839,7 +1883,7 @@ bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, state_mask= ~state_mask; // do it only once - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); total= type == MYSQL_ANY_PLUGIN ? plugin_array.elements : plugin_hash[type].records; /* @@ -1864,17 +1908,17 @@ bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, plugins[idx]= !(plugin->state & state_mask) ? plugin : NULL; } } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); for (idx= 0; idx < total; idx++) { if (unlikely(version != plugin_array_version)) { - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); for (uint i=idx; i < total; i++) if (plugins[i] && plugins[i]->state & state_mask) plugins[i]=0; - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); } plugin= plugins[idx]; /* It will stop iterating on first engine error when "func" returns TRUE */ @@ -2196,12 +2240,12 @@ sys_var *find_sys_var(THD *thd, const char *str, uint length) plugin_ref plugin; DBUG_ENTER("find_sys_var"); - pthread_mutex_lock(&LOCK_plugin); - rw_rdlock(&LOCK_system_variables_hash); + mysql_mutex_lock(&LOCK_plugin); + mysql_rwlock_rdlock(&LOCK_system_variables_hash); if ((var= intern_find_sys_var(str, length)) && (pi= var->cast_pluginvar())) { - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); LEX *lex= thd ? thd->lex : 0; if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin)))) var= NULL; /* failed to lock it, it must be uninstalling */ @@ -2214,8 +2258,8 @@ sys_var *find_sys_var(THD *thd, const char *str, uint length) } } else - rw_unlock(&LOCK_system_variables_hash); - pthread_mutex_unlock(&LOCK_plugin); + mysql_rwlock_unlock(&LOCK_system_variables_hash); + mysql_mutex_unlock(&LOCK_plugin); /* If the variable exists but the plugin it is associated with is not ready @@ -2403,7 +2447,7 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) { uint idx; - rw_rdlock(&LOCK_system_variables_hash); + mysql_rwlock_rdlock(&LOCK_system_variables_hash); thd->variables.dynamic_variables_ptr= (char*) my_realloc(thd->variables.dynamic_variables_ptr, @@ -2411,9 +2455,9 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); if (global_lock) - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); - safe_mutex_assert_owner(&LOCK_global_system_variables); + mysql_mutex_assert_owner(&LOCK_global_system_variables); memcpy(thd->variables.dynamic_variables_ptr + thd->variables.dynamic_variables_size, @@ -2452,7 +2496,7 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) } if (global_lock) - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); thd->variables.dynamic_variables_version= global_system_variables.dynamic_variables_version; @@ -2461,7 +2505,7 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) thd->variables.dynamic_variables_size= global_system_variables.dynamic_variables_size; - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); } return (uchar*)thd->variables.dynamic_variables_ptr + offset; } @@ -2488,11 +2532,11 @@ void plugin_thdvar_init(THD *thd) thd->variables.dynamic_variables_size= 0; thd->variables.dynamic_variables_ptr= 0; - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); thd->variables.table_plugin= my_intern_plugin_lock(NULL, global_system_variables.table_plugin); intern_plugin_unlock(NULL, old_table_plugin); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_VOID_RETURN; } @@ -2521,7 +2565,7 @@ static void cleanup_variables(THD *thd, struct system_variables *vars) int flags; uint idx; - rw_rdlock(&LOCK_system_variables_hash); + mysql_rwlock_rdlock(&LOCK_system_variables_hash); for (idx= 0; idx < bookmark_hash.records; idx++) { v= (st_bookmark*) my_hash_element(&bookmark_hash, idx); @@ -2541,7 +2585,7 @@ static void cleanup_variables(THD *thd, struct system_variables *vars) *ptr= NULL; } } - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); DBUG_ASSERT(vars->table_plugin == NULL); @@ -2558,7 +2602,7 @@ void plugin_thdvar_cleanup(THD *thd) plugin_ref *list; DBUG_ENTER("plugin_thdvar_cleanup"); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); unlock_variables(thd, &thd->variables); cleanup_variables(thd, &thd->variables); @@ -2572,7 +2616,7 @@ void plugin_thdvar_cleanup(THD *thd) } reap_plugins(); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); reset_dynamic(&thd->lex->plugins); @@ -2724,11 +2768,11 @@ bool sys_var_pluginvar::session_update(THD *thd, set_var *var) DBUG_ASSERT(plugin_var->flags & PLUGIN_VAR_THDLOCAL); DBUG_ASSERT(thd == current_thd); - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); void *tgt= real_value_ptr(thd, var->type); const void *src= var->value ? (void*)&var->save_result : (void*)real_value_ptr(thd, OPT_GLOBAL); - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); plugin_var->update(thd, plugin_var, tgt, src); return false; @@ -2737,7 +2781,7 @@ bool sys_var_pluginvar::session_update(THD *thd, set_var *var) bool sys_var_pluginvar::global_update(THD *thd, set_var *var) { DBUG_ASSERT(!is_readonly()); - safe_mutex_assert_owner(&LOCK_global_system_variables); + mysql_mutex_assert_owner(&LOCK_global_system_variables); void *tgt= real_value_ptr(thd, var->type); const void *src= &var->save_result; @@ -3274,7 +3318,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, if (!tmp->is_mandatory) opts[0].def_value= opts[1].def_value= plugin_load_policy; - error= handle_options(argc, &argv, opts, get_one_plugin_option); + error= handle_options(argc, &argv, opts, NULL); (*argc)++; /* add back one for the program name */ if (error) -- cgit v1.2.1 From 0043c04eac1cef43eb0e5431ce3855536ddb7240 Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Wed, 24 Feb 2010 18:04:00 +0100 Subject: Followup to Bug#45225 Locking: hang if drop table with no timeout This patch prevents system threads and system table accesses from using user-specified values for "lock_wait_timeout". Instead all such accesses are done using the default value (1 year). This prevents background tasks (such as replication, events, accessing stored function definitions, logging, reading time-zone information, etc.) from failing in cases where the global value of "lock_wait_timeout" is set very low. The patch also simplifies the open tables API. Rather than adding another convenience function for opening and locking system tables, this patch removes most of the existing convenience functions for open_and_lock_tables_derived(). Before, open_and_lock_tables() was a convenience function that enforced derived tables handling, while open_and_lock_tables_derived() was the main function where derived tables handling was optional. Now, this convencience function is gone and the main function is renamed to open_and_lock_tables(). No test case added as it would have required the use of --sleep to check that system threads and system tables have a different timeout value from the user-specified "lock_wait_timeout" system variable. --- sql/sql_plugin.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'sql/sql_plugin.cc') diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index f0d9560dff4..3d1380d46f3 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1469,7 +1469,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) goto end; #endif /* EMBEDDED_LIBRARY */ - if (simple_open_n_lock_tables(new_thd, &tables)) + if (open_and_lock_tables(new_thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT)) { DBUG_PRINT("error",("Can't open plugin table")); sql_print_error("Can't open the mysql.plugin table. Please " @@ -1746,7 +1746,8 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl DBUG_RETURN(TRUE); /* need to open before acquiring LOCK_plugin or it will deadlock */ - if (! (table = open_ltable(thd, &tables, TL_WRITE, 0))) + if (! (table = open_ltable(thd, &tables, TL_WRITE, + MYSQL_LOCK_IGNORE_TIMEOUT))) DBUG_RETURN(TRUE); mysql_mutex_lock(&LOCK_plugin); @@ -1817,7 +1818,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_WRITE); /* need to open before acquiring LOCK_plugin or it will deadlock */ - if (! (table= open_ltable(thd, &tables, TL_WRITE, 0))) + if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT))) DBUG_RETURN(TRUE); mysql_mutex_lock(&LOCK_plugin); -- cgit v1.2.1