From: Mikael Ronstrom Date: May 4 2011 10:29am Subject: bzr commit into mysql-trunk branch (mikael.ronstrom:3364) List-Archive: http://lists.mysql.com/commits/136630 Message-Id: <201105041030.p44AUkkd023338@dator6> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit #At file:///home/mikael/mysql_clones/mysql-trunk-wl5136/ based on revid:alexander.nozdrin@stripped 3364 Mikael Ronstrom 2011-05-04 [merge] merge added: include/mysql/thread_pool_priv.h mysql-test/include/not_threadpool.inc mysql-test/r/status_bug17954.result mysql-test/t/status_bug17954.test modified: BUILD/build_mccge.sh include/my_compiler.h include/my_sys.h include/mysql/plugin_audit.h.pp include/mysql/plugin_auth.h.pp include/mysql/plugin_ftparser.h.pp include/mysql/service_thd_wait.h mysql-test/include/have_archive_plugin.inc mysql-test/include/have_blackhole_plugin.inc mysql-test/include/plugin.defs mysql-test/r/status.result mysql-test/suite/perfschema/t/no_threads.test mysql-test/suite/perfschema/t/one_thread_per_con.test mysql-test/suite/sys_vars/t/all_vars.test mysql-test/suite/sys_vars/t/slow_launch_time_func.test mysql-test/suite/sys_vars/t/thread_cache_size_func.test mysql-test/suite/sys_vars/t/wait_timeout_func.test mysql-test/t/information_schema.test mysql-test/t/information_schema_db.test mysql-test/t/kill.test mysql-test/t/mysqlshow.test mysql-test/t/named_pipe.test mysql-test/t/no-threads.test mysql-test/t/shm.test mysql-test/t/status.test mysys/my_sync.c sql/debug_sync.cc sql/debug_sync.h sql/item_func.cc sql/log.cc sql/log.h sql/mdl.cc sql/mysqld.cc sql/mysqld.h sql/rpl_rli.cc sql/scheduler.cc sql/scheduler.h sql/sp_head.cc sql/sp_head.h sql/sql_class.cc sql/sql_class.h sql/sql_connect.cc sql/sql_connect.h sql/sql_cursor.h sql/sql_prepare.cc sql/table.cc === modified file 'BUILD/build_mccge.sh' --- a/BUILD/build_mccge.sh revid:alexander.nozdrin@stripped +++ b/BUILD/build_mccge.sh revid:mikael.ronstrom@stripped @@ -293,7 +293,8 @@ extended_usage() version string suffix: [none] All packages except Classic include support for user-defined - partitioning. + partitioning. All packages include support for Performance + Schema. If --with-debug is used, an additional "-debug" is appended to the version string. === modified file 'include/my_compiler.h' --- a/include/my_compiler.h revid:alexander.nozdrin@stripped +++ b/include/my_compiler.h revid:mikael.ronstrom@stripped @@ -140,6 +140,14 @@ struct my_aligned_storage #endif /* __cplusplus */ +# ifndef MY_ALIGNED +/* + Make sure MY_ALIGNED can be used also on platforms where we don't + have a way of aligning data structures. +*/ +#define MY_ALIGNED(size) +#endif + #include #endif /* MY_COMPILER_INCLUDED */ === modified file 'include/my_sys.h' --- a/include/my_sys.h revid:alexander.nozdrin@stripped +++ b/include/my_sys.h revid:mikael.ronstrom@stripped @@ -625,6 +625,8 @@ extern FILE *my_freopen(const char *path extern int my_fclose(FILE *fd,myf MyFlags); extern File my_fileno(FILE *fd); extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags); +extern void thr_set_sync_wait_callback(void (*before_sync)(void), + void (*after_sync)(void)); extern int my_sync(File fd, myf my_flags); extern int my_sync_dir(const char *dir_name, myf my_flags); extern int my_sync_dir_by_file(const char *file_name, myf my_flags); === modified file 'include/mysql/plugin_audit.h.pp' --- a/include/mysql/plugin_audit.h.pp revid:alexander.nozdrin@stripped +++ b/include/mysql/plugin_audit.h.pp revid:mikael.ronstrom@stripped @@ -34,16 +34,23 @@ MYSQL_LEX_STRING *thd_make_lex_string(vo int allocate_lex_string); #include typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_LAST= 11 } thd_wait_type; extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(void*, thd_wait_type); + void (*thd_wait_begin_func)(void*, int); void (*thd_wait_end_func)(void*); } *thd_wait_service; -void thd_wait_begin(void* thd, thd_wait_type wait_type); +void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); #include struct scheduler_functions; === modified file 'include/mysql/plugin_auth.h.pp' --- a/include/mysql/plugin_auth.h.pp revid:alexander.nozdrin@stripped +++ b/include/mysql/plugin_auth.h.pp revid:mikael.ronstrom@stripped @@ -34,16 +34,23 @@ MYSQL_LEX_STRING *thd_make_lex_string(vo int allocate_lex_string); #include typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_LAST= 11 } thd_wait_type; extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(void*, thd_wait_type); + void (*thd_wait_begin_func)(void*, int); void (*thd_wait_end_func)(void*); } *thd_wait_service; -void thd_wait_begin(void* thd, thd_wait_type wait_type); +void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); #include struct scheduler_functions; === modified file 'include/mysql/plugin_ftparser.h.pp' --- a/include/mysql/plugin_ftparser.h.pp revid:alexander.nozdrin@stripped +++ b/include/mysql/plugin_ftparser.h.pp revid:mikael.ronstrom@stripped @@ -34,16 +34,23 @@ MYSQL_LEX_STRING *thd_make_lex_string(vo int allocate_lex_string); #include typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_LAST= 11 } thd_wait_type; extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(void*, thd_wait_type); + void (*thd_wait_begin_func)(void*, int); void (*thd_wait_end_func)(void*); } *thd_wait_service; -void thd_wait_begin(void* thd, thd_wait_type wait_type); +void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); #include struct scheduler_functions; === modified file 'include/mysql/service_thd_wait.h' --- a/include/mysql/service_thd_wait.h revid:alexander.nozdrin@stripped +++ b/include/mysql/service_thd_wait.h revid:mikael.ronstrom@stripped @@ -50,15 +50,35 @@ extern "C" { #endif +/* + One should only report wait events that could potentially block for a + long time. A mutex wait is too short of an event to report. The reason + is that an event which is reported leads to a new thread starts + executing a query and this has a negative impact of usage of CPU caches + and thus the expected gain of starting a new thread must be higher than + the expected cost of lost performance due to starting a new thread. + + Good examples of events that should be reported are waiting for row locks + that could easily be for many milliseconds or even seconds and the same + holds true for global read locks, table locks and other meta data locks. + Another event of interest is going to sleep for an extended time. +*/ typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_LAST= 11 } thd_wait_type; extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(MYSQL_THD, thd_wait_type); + void (*thd_wait_begin_func)(MYSQL_THD, int); void (*thd_wait_end_func)(MYSQL_THD); } *thd_wait_service; @@ -70,7 +90,7 @@ extern struct thd_wait_service_st { #else -void thd_wait_begin(MYSQL_THD thd, thd_wait_type wait_type); +void thd_wait_begin(MYSQL_THD thd, int wait_type); void thd_wait_end(MYSQL_THD thd); #endif === added file 'include/mysql/thread_pool_priv.h' --- a/include/mysql/thread_pool_priv.h 1970-01-01 00:00:00 +0000 +++ b/include/mysql/thread_pool_priv.h revid:mikael.ronstrom@stripped @@ -0,0 +1,117 @@ +/* + Copyright (C) 2010, 2011 Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef THREAD_POOL_PRIV_INCLUDED +#define THREAD_POOL_PRIV_INCLUDED + +/* + The thread pool requires access to some MySQL server error codes, this is + accessed from mysqld_error.h. + We need access to the struct that defines the thread pool plugin interface + which is accessed through scheduler.h. + All accesses to THD variables and functions are defined in this header file. + A thread pool can also use DEBUG_SYNC and must thus include + debug_sync.h + To handle definitions of Information Schema plugins it is also required + to include sql_profile.h and table.h. +*/ +#include /* To get ER_ERROR_ON_READ */ +#define MYSQL_SERVER 1 +#include +#include +#include +#include + +/* Needed to get access to scheduler variables */ +void* thd_get_scheduler_data(THD *thd); +void thd_set_scheduler_data(THD *thd, void *data); +PSI_thread* thd_get_psi(THD *thd); +void thd_set_psi(THD *thd, PSI_thread *psi); + +/* Interface to THD variables and functions */ +void thd_set_killed(THD *thd); +void thd_clear_errors(THD *thd); +void thd_set_thread_stack(THD *thd, char *stack_start); +void thd_lock_thread_count(THD *thd); +void thd_unlock_thread_count(THD *thd); +void thd_close_connection(THD *thd); +THD *thd_get_current_thd(); +void thd_new_connection_setup(THD *thd, char *stack_start); +void thd_lock_data(THD *thd); +void thd_unlock_data(THD *thd); +bool thd_is_transaction_active(THD *thd); +int thd_connection_has_data(THD *thd); +void thd_set_net_read_write(THD *thd, uint val); +void thd_set_mysys_var(THD *thd, st_my_thread_var *mysys_var); +my_socket thd_get_fd(THD *thd); + +/* Print to the MySQL error log */ +void sql_print_error(const char *format, ...); + +/* Store a table record */ +bool schema_table_store_record(THD *thd, TABLE *table); + +/* + The thread pool must be able to execute statements using the connection + state in THD object. This is the main objective of the thread pool to + schedule the start of these commands. +*/ +bool do_command(THD *thd); + +/* + The thread pool requires an interface to the connection logic in the + MySQL Server since the thread pool will maintain the event logic on + the TCP connection of the MySQL Server. Thus new connections, dropped + connections will be discovered by the thread pool and it needs to + ensure that the proper MySQL Server logic attached to these events is + executed. +*/ +/* Initialise a new connection handler thread */ +bool init_new_connection_handler_thread(); +/* Set up connection thread before use as execution thread */ +bool setup_connection_thread_globals(THD *thd); +/* Prepare connection as part of connection set-up */ +bool thd_prepare_connection(THD *thd); +/* Release auditing before executing statement */ +void mysql_audit_release(THD *thd); +/* Check if connection is still alive */ +bool thd_is_connection_alive(THD *thd); +/* Close connection with possible error code */ +void close_connection(THD *thd, uint errcode); +/* End the connection before closing it */ +void end_connection(THD *thd); +/* Destroy THD object */ +void unlink_thd(THD *thd); + +/* + thread_created is maintained by thread pool when activated since + user threads are created by the thread pool (and also special + threads to maintain the thread pool). This is done through + inc_thread_created. + + max_connections is needed to calculate the maximum number of threads + that is allowed to be started by the thread pool. The method + get_max_connections() gets reference to this variable. + + connection_attrib is the thread attributes for connection threads, + the method get_connection_attrib provides a reference to these + attributes. +*/ +void inc_thread_created(void); +ulong get_max_connections(void); +pthread_attr_t *get_connection_attrib(void); +#endif === modified file 'mysql-test/include/have_archive_plugin.inc' --- a/mysql-test/include/have_archive_plugin.inc revid:alexander.nozdrin@stripped +++ b/mysql-test/include/have_archive_plugin.inc revid:mikael.ronstrom@stripped @@ -1,5 +1,10 @@ +disable_query_log; if (`select plugin_library IS NULL from information_schema.plugins where plugin_name LIKE '%archive%'`) { --skip archive plugin not available } +if (`SELECT @@plugin_dir != '$ARCHIVE_PLUGIN_DIR'`) { + --skip Archive plugin requires that --plugin-dir is set to the archive plugin dir (either the .opt file does not contain \$ARCHIVE_PLUGIN_OPT or another plugin is in use) +} +enable_query_log; \ No newline at end of file === modified file 'mysql-test/include/have_blackhole_plugin.inc' --- a/mysql-test/include/have_blackhole_plugin.inc revid:alexander.nozdrin@stripped +++ b/mysql-test/include/have_blackhole_plugin.inc revid:mikael.ronstrom@stripped @@ -1,5 +1,11 @@ +disable_query_log; if (`select plugin_library IS NULL from information_schema.plugins where plugin_name LIKE '%blackhole%'`) { --skip blackhole plugin not available; } +if (`SELECT @@plugin_dir != '$BLACKHOLE_PLUGIN_DIR'`) { + --skip Blackhole plugin requires that --plugin-dir is set to the blackhole plugin dir (either the .opt file does not contain \$BLACKHOLE_PLUGIN_OPT or another plugin is in use) +} +enable_query_log; + === added file 'mysql-test/include/not_threadpool.inc' --- a/mysql-test/include/not_threadpool.inc 1970-01-01 00:00:00 +0000 +++ b/mysql-test/include/not_threadpool.inc revid:mikael.ronstrom@stripped @@ -0,0 +1,5 @@ +if (`SELECT count(*) FROM information_schema.GLOBAL_VARIABLES WHERE + VARIABLE_NAME = 'THREAD_HANDLING' AND + VARIABLE_VALUE = 'loaded-dynamically'`){ + skip Test requires: 'not_threadpool'; +} === modified file 'mysql-test/include/plugin.defs' --- a/mysql-test/include/plugin.defs revid:alexander.nozdrin@stripped +++ b/mysql-test/include/plugin.defs revid:mikael.ronstrom@stripped @@ -39,3 +39,4 @@ ha_archive storage/archive AR ha_blackhole storage/blackhole BLACKHOLE_PLUGIN ha_federated storage/federated FEDERATED_PLUGIN mypluglib plugin/fulltext SIMPLE_PARSER +thread_pool plugin/thread_pool THREADPOOL_PLUGIN thread_pool,TP_THREAD_STATE,TP_THREAD_GROUP_STATE,TP_THREAD_GROUP_STATS === modified file 'mysql-test/r/status.result' --- a/mysql-test/r/status.result revid:alexander.nozdrin@stripped +++ b/mysql-test/r/status.result revid:mikael.ronstrom@stripped @@ -238,11 +238,5 @@ SELECT 9; 9 DROP PROCEDURE p1; DROP FUNCTION f1; -DROP VIEW IF EXISTS v1; -CREATE VIEW v1 AS SELECT VARIABLE_NAME AS NAME, CONVERT(VARIABLE_VALUE, UNSIGNED) AS VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS; -SELECT VALUE INTO @tc FROM v1 WHERE NAME = 'Threads_connected'; -SELECT NAME FROM v1 WHERE NAME = 'Threads_created' AND VALUE < @tc; -NAME -DROP VIEW v1; set @@global.concurrent_insert= @old_concurrent_insert; SET GLOBAL log_output = @old_log_output; === added file 'mysql-test/r/status_bug17954.result' --- a/mysql-test/r/status_bug17954.result 1970-01-01 00:00:00 +0000 +++ b/mysql-test/r/status_bug17954.result revid:mikael.ronstrom@stripped @@ -0,0 +1,13 @@ +set @old_concurrent_insert= @@global.concurrent_insert; +set @@global.concurrent_insert= 0; +SET @old_log_output = @@global.log_output; +SET GLOBAL LOG_OUTPUT = 'FILE'; +flush status; +DROP VIEW IF EXISTS v1; +CREATE VIEW v1 AS SELECT VARIABLE_NAME AS NAME, CONVERT(VARIABLE_VALUE, UNSIGNED) AS VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS; +SELECT VALUE INTO @tc FROM v1 WHERE NAME = 'Threads_connected'; +SELECT NAME FROM v1 WHERE NAME = 'Threads_created' AND VALUE < @tc; +NAME +DROP VIEW v1; +set @@global.concurrent_insert= @old_concurrent_insert; +SET GLOBAL log_output = @old_log_output; === modified file 'mysql-test/suite/perfschema/t/no_threads.test' --- a/mysql-test/suite/perfschema/t/no_threads.test revid:alexander.nozdrin@stripped +++ b/mysql-test/suite/perfschema/t/no_threads.test revid:mikael.ronstrom@stripped @@ -17,6 +17,7 @@ --source include/not_embedded.inc --source include/have_perfschema.inc +--source include/not_threadpool.inc # Setup : in this main thread === modified file 'mysql-test/suite/perfschema/t/one_thread_per_con.test' --- a/mysql-test/suite/perfschema/t/one_thread_per_con.test revid:alexander.nozdrin@stripped +++ b/mysql-test/suite/perfschema/t/one_thread_per_con.test revid:mikael.ronstrom@stripped @@ -17,6 +17,7 @@ --source include/not_embedded.inc --source include/have_perfschema.inc +--source include/not_threadpool.inc # Setup === modified file 'mysql-test/suite/sys_vars/t/all_vars.test' --- a/mysql-test/suite/sys_vars/t/all_vars.test revid:alexander.nozdrin@stripped +++ b/mysql-test/suite/sys_vars/t/all_vars.test revid:mikael.ronstrom@stripped @@ -14,6 +14,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --source include/not_embedded.inc +--source include/not_threadpool.inc # 2010-01-28 OBN Added support to load 'innodb' and 'semisync' if possible. # As we need to have there variables loaded if the components exist but do === modified file 'mysql-test/suite/sys_vars/t/slow_launch_time_func.test' --- a/mysql-test/suite/sys_vars/t/slow_launch_time_func.test revid:alexander.nozdrin@stripped +++ b/mysql-test/suite/sys_vars/t/slow_launch_time_func.test revid:mikael.ronstrom@stripped @@ -31,6 +31,7 @@ # --source include/not_embedded.inc +--source include/not_threadpool.inc SET @global_slow_launch_time = @@GLOBAL.slow_launch_time; === modified file 'mysql-test/suite/sys_vars/t/thread_cache_size_func.test' --- a/mysql-test/suite/sys_vars/t/thread_cache_size_func.test revid:alexander.nozdrin@stripped +++ b/mysql-test/suite/sys_vars/t/thread_cache_size_func.test revid:mikael.ronstrom@stripped @@ -28,6 +28,7 @@ # --source include/not_embedded.inc +--source include/not_threadpool.inc SET @global_thread_cache_size = @@GLOBAL.thread_cache_size; === modified file 'mysql-test/suite/sys_vars/t/wait_timeout_func.test' --- a/mysql-test/suite/sys_vars/t/wait_timeout_func.test revid:alexander.nozdrin@stripped +++ b/mysql-test/suite/sys_vars/t/wait_timeout_func.test revid:mikael.ronstrom@stripped @@ -22,6 +22,7 @@ ############################################################################### --source include/not_embedded.inc +--source include/not_threadpool.inc SET @start_value= @@global.wait_timeout; === modified file 'mysql-test/t/information_schema.test' --- a/mysql-test/t/information_schema.test revid:alexander.nozdrin@stripped +++ b/mysql-test/t/information_schema.test revid:mikael.ronstrom@stripped @@ -1,6 +1,9 @@ # This test uses grants, which can't get tested for embedded server -- source include/not_embedded.inc +#Don't run this test when thread_pool active +--source include/not_threadpool.inc + # check that CSV engine was compiled in, as the result of the test depends # on the presence of the log tables (which are CSV-based). --source include/have_csv.inc === modified file 'mysql-test/t/information_schema_db.test' --- a/mysql-test/t/information_schema_db.test revid:alexander.nozdrin@stripped +++ b/mysql-test/t/information_schema_db.test revid:mikael.ronstrom@stripped @@ -2,6 +2,9 @@ # in the embedded server by default). So skip the test in embedded-server mode. -- source include/not_embedded.inc +#Don't run this test when thread_pool active +--source include/not_threadpool.inc + -- source include/testdb_only.inc --disable_warnings === modified file 'mysql-test/t/kill.test' --- a/mysql-test/t/kill.test revid:alexander.nozdrin@stripped +++ b/mysql-test/t/kill.test revid:mikael.ronstrom@stripped @@ -9,6 +9,7 @@ -- source include/not_embedded.inc -- source include/have_debug_sync.inc +-- source include/not_threadpool.inc --disable_warnings SET DEBUG_SYNC = 'RESET'; === modified file 'mysql-test/t/mysqlshow.test' --- a/mysql-test/t/mysqlshow.test revid:alexander.nozdrin@stripped +++ b/mysql-test/t/mysqlshow.test revid:mikael.ronstrom@stripped @@ -2,6 +2,8 @@ -- source include/not_embedded.inc # Test lists tables in Information_schema, and InnoDB adds some -- source include/have_innodb.inc +# Don't test when thread_pool active +--source include/not_threadpool.inc --disable_warnings DROP TABLE IF EXISTS t1,t2,test1,test2; === modified file 'mysql-test/t/named_pipe.test' --- a/mysql-test/t/named_pipe.test revid:alexander.nozdrin@stripped +++ b/mysql-test/t/named_pipe.test revid:mikael.ronstrom@stripped @@ -3,6 +3,9 @@ # other platforms --source include/windows.inc +# thread pool causes different results +-- source include/not_threadpool.inc + # Only run this test if named pipe is avaliable let $nmp= query_get_value("SHOW VARIABLES LIKE 'named_pipe'", Value, 1); if ($nmp != ON){ === modified file 'mysql-test/t/no-threads.test' --- a/mysql-test/t/no-threads.test revid:alexander.nozdrin@stripped +++ b/mysql-test/t/no-threads.test revid:mikael.ronstrom@stripped @@ -1,3 +1,4 @@ +--source include/not_threadpool.inc # # Test the --thread-handler=no-threads option # === modified file 'mysql-test/t/shm.test' --- a/mysql-test/t/shm.test revid:alexander.nozdrin@stripped +++ b/mysql-test/t/shm.test revid:mikael.ronstrom@stripped @@ -2,6 +2,9 @@ # to optimize things we skip this test on all other platforms --source include/windows.inc +# thread pool causes different results +-- source include/not_threadpool.inc + # Only run this test if shared memory is avaliable let $shm= query_get_value("SHOW VARIABLES LIKE 'shared_memory'", Value, 1); if ($shm != ON){ === modified file 'mysql-test/t/status.test' --- a/mysql-test/t/status.test revid:alexander.nozdrin@stripped +++ b/mysql-test/t/status.test revid:mikael.ronstrom@stripped @@ -354,21 +354,6 @@ DROP FUNCTION f1; # End of 5.1 tests -# -# Bug#17954 Threads_connected > Threads_created -# - ---disable_warnings -DROP VIEW IF EXISTS v1; ---enable_warnings - -CREATE VIEW v1 AS SELECT VARIABLE_NAME AS NAME, CONVERT(VARIABLE_VALUE, UNSIGNED) AS VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS; - -SELECT VALUE INTO @tc FROM v1 WHERE NAME = 'Threads_connected'; -SELECT NAME FROM v1 WHERE NAME = 'Threads_created' AND VALUE < @tc; - -DROP VIEW v1; - # Restore global concurrent_insert value. Keep in the end of the test file. --connection default set @@global.concurrent_insert= @old_concurrent_insert; === added file 'mysql-test/t/status_bug17954.test' --- a/mysql-test/t/status_bug17954.test 1970-01-01 00:00:00 +0000 +++ b/mysql-test/t/status_bug17954.test revid:mikael.ronstrom@stripped @@ -0,0 +1,54 @@ +# This test requires that --log-output includes 'table', and the general +# log is on + +# embedded server causes different stat +-- source include/not_embedded.inc + +# thread pool causes different results +-- source include/not_threadpool.inc + +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + +# Disable concurrent inserts to avoid sporadic test failures as it might +# affect the the value of variables used throughout the test case. +set @old_concurrent_insert= @@global.concurrent_insert; +set @@global.concurrent_insert= 0; + +# Disable logging to table, since this will also cause table locking and unlocking, which will +# show up in SHOW STATUS and may cause sporadic failures + +SET @old_log_output = @@global.log_output; +SET GLOBAL LOG_OUTPUT = 'FILE'; + +# PS causes different statistics +--disable_ps_protocol + +flush status; + +# +# Bug#17954 Threads_connected > Threads_created +# + +--disable_warnings +DROP VIEW IF EXISTS v1; +--enable_warnings + +CREATE VIEW v1 AS SELECT VARIABLE_NAME AS NAME, CONVERT(VARIABLE_VALUE, UNSIGNED) AS VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS; + +SELECT VALUE INTO @tc FROM v1 WHERE NAME = 'Threads_connected'; +SELECT NAME FROM v1 WHERE NAME = 'Threads_created' AND VALUE < @tc; +#SELECT * FROM INFORMATION_SCHEMA.GLOBAL_STATUS where variable_name like '%thread%'; +#SELECT * FROM INFORMATION_SCHEMA.GLOBAL_STATUS; +#SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES; + +DROP VIEW v1; + +# Restore global concurrent_insert value. Keep in the end of the test file. +--connection default +set @@global.concurrent_insert= @old_concurrent_insert; +SET GLOBAL log_output = @old_log_output; + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc + === modified file 'mysys/my_sync.c' --- a/mysys/my_sync.c revid:alexander.nozdrin@stripped +++ b/mysys/my_sync.c revid:mikael.ronstrom@stripped @@ -17,6 +17,16 @@ #include "mysys_err.h" #include +static void (*before_sync_wait)(void)= 0; +static void (*after_sync_wait)(void)= 0; + +void thr_set_sync_wait_callback(void (*before_wait)(void), + void (*after_wait)(void)) +{ + before_sync_wait= before_wait; + after_sync_wait= after_wait; +} + /* Sync data in file to disk @@ -46,6 +56,8 @@ int my_sync(File fd, myf my_flags) DBUG_ENTER("my_sync"); DBUG_PRINT("my",("Fd: %d my_flags: %d", fd, my_flags)); + if (before_sync_wait) + (*before_sync_wait)(); do { #if defined(F_FULLFSYNC) @@ -75,6 +87,8 @@ int my_sync(File fd, myf my_flags) int er= errno; if (!(my_errno= er)) my_errno= -1; /* Unknown error */ + if (after_sync_wait) + (*after_sync_wait)(); if ((my_flags & MY_IGNORE_BADFD) && (er == EBADF || er == EINVAL || er == EROFS)) { @@ -84,6 +98,11 @@ int my_sync(File fd, myf my_flags) else if (my_flags & MY_WME) my_error(EE_SYNC, MYF(ME_BELL+ME_WAITTANG), my_filename(fd), my_errno); } + else + { + if (after_sync_wait) + (*after_sync_wait)(); + } DBUG_RETURN(res); } /* my_sync */ === modified file 'sql/debug_sync.cc' --- a/sql/debug_sync.cc revid:alexander.nozdrin@stripped +++ b/sql/debug_sync.cc revid:mikael.ronstrom@stripped @@ -1742,11 +1742,20 @@ static void debug_sync_execute(THD *thd, We don't use enter_cond()/exit_cond(). They do not save old mutex and cond. This would prohibit the use of DEBUG_SYNC between other places of enter_cond() and exit_cond(). + + We need to check for existence of thd->mysys_var to also make + it possible to use DEBUG_SYNC framework in scheduler when this + variable has been set to NULL. */ - old_mutex= thd->mysys_var->current_mutex; - old_cond= thd->mysys_var->current_cond; - thd->mysys_var->current_mutex= &debug_sync_global.ds_mutex; - thd->mysys_var->current_cond= &debug_sync_global.ds_cond; + if (thd->mysys_var) + { + old_mutex= thd->mysys_var->current_mutex; + old_cond= thd->mysys_var->current_cond; + thd->mysys_var->current_mutex= &debug_sync_global.ds_mutex; + thd->mysys_var->current_cond= &debug_sync_global.ds_cond; + } + else + old_mutex= NULL; set_timespec(abstime, action->timeout); DBUG_EXECUTE("debug_sync_exec", { @@ -1801,11 +1810,16 @@ static void debug_sync_execute(THD *thd, is locked. (See comment in THD::exit_cond().) */ mysql_mutex_unlock(&debug_sync_global.ds_mutex); - mysql_mutex_lock(&thd->mysys_var->mutex); - thd->mysys_var->current_mutex= old_mutex; - thd->mysys_var->current_cond= old_cond; - thd_proc_info(thd, old_proc_info); - mysql_mutex_unlock(&thd->mysys_var->mutex); + if (old_mutex) + { + mysql_mutex_lock(&thd->mysys_var->mutex); + thd->mysys_var->current_mutex= old_mutex; + thd->mysys_var->current_cond= old_cond; + thd_proc_info(thd, old_proc_info); + mysql_mutex_unlock(&thd->mysys_var->mutex); + } + else + thd_proc_info(thd, old_proc_info); } else { === modified file 'sql/debug_sync.h' --- a/sql/debug_sync.h revid:alexander.nozdrin@stripped +++ b/sql/debug_sync.h revid:mikael.ronstrom@stripped @@ -35,7 +35,7 @@ class THD; } while (0) /* Command line option --debug-sync-timeout. See mysqld.cc. */ -extern uint opt_debug_sync_timeout; +extern MYSQL_PLUGIN_IMPORT uint opt_debug_sync_timeout; /* Default WAIT_FOR timeout if command line option is given without argument. */ #define DEBUG_SYNC_DEFAULT_WAIT_TIMEOUT 300 === modified file 'sql/item_func.cc' --- a/sql/item_func.cc revid:alexander.nozdrin@stripped +++ b/sql/item_func.cc revid:mikael.ronstrom@stripped @@ -47,6 +47,8 @@ #include "sp.h" #include "set_var.h" #include "debug_sync.h" +#include +#include #ifdef NO_EMBEDDED_ACCESS_CHECKS #define sp_restore_security_context(A,B) while (0) {} @@ -3899,6 +3901,7 @@ longlong Item_func_get_lock::val_int() timed_cond.set_timeout(timeout * ULL(1000000000)); error= 0; + thd_wait_begin(thd, THD_WAIT_USER_LOCK); while (ull->locked && !thd->killed) { DBUG_PRINT("info", ("waiting on lock")); @@ -3910,6 +3913,7 @@ longlong Item_func_get_lock::val_int() } error= 0; } + thd_wait_end(thd); if (ull->locked) { @@ -4126,6 +4130,7 @@ longlong Item_func_sleep::val_int() thd->mysys_var->current_cond= &cond; error= 0; + thd_wait_begin(thd, THD_WAIT_SLEEP); while (!thd->killed) { error= timed_cond.wait(&cond, &LOCK_user_locks); @@ -4133,6 +4138,7 @@ longlong Item_func_sleep::val_int() break; error= 0; } + thd_wait_end(thd); mysql_mutex_unlock(&LOCK_user_locks); mysql_mutex_lock(&thd->mysys_var->mutex); thd->mysys_var->current_mutex= 0; === modified file 'sql/log.cc' --- a/sql/log.cc revid:alexander.nozdrin@stripped +++ b/sql/log.cc revid:mikael.ronstrom@stripped @@ -2485,7 +2485,7 @@ int TC_LOG_MMAP::open(const char *opt_na { pg->next=pg+1; pg->waiters=0; - pg->state=POOL; + pg->state=PS_POOL; mysql_mutex_init(key_PAGE_lock, &pg->lock, MY_MUTEX_INIT_FAST); mysql_cond_init(key_PAGE_cond, &pg->cond, 0); pg->start=(my_xid *)(data + i*tc_log_page_size); @@ -2659,7 +2659,7 @@ int TC_LOG_MMAP::log_xid(THD *thd, my_xi cookie= (ulong)((uchar *)p->ptr - data); // can never be zero *p->ptr++= xid; p->free--; - p->state= DIRTY; + p->state= PS_DIRTY; /* to sync or not to sync - this is the question */ mysql_mutex_unlock(&LOCK_active); @@ -2671,13 +2671,13 @@ int TC_LOG_MMAP::log_xid(THD *thd, my_xi p->waiters++; /* note - it must be while (), not do ... while () here - as p->state may be not DIRTY when we come here + as p->state may be not PS_DIRTY when we come here */ - while (p->state == DIRTY && syncing) + while (p->state == PS_DIRTY && syncing) mysql_cond_wait(&p->cond, &LOCK_sync); p->waiters--; - err= p->state == ERROR; - if (p->state != DIRTY) // page was synced + err= p->state == PS_ERROR; + if (p->state != PS_DIRTY) // page was synced { if (p->waiters == 0) mysql_cond_signal(&COND_pool); // in case somebody's waiting @@ -2715,7 +2715,7 @@ int TC_LOG_MMAP::sync() pool_last->next=syncing; pool_last=syncing; syncing->next=0; - syncing->state= err ? ERROR : POOL; + syncing->state= err ? PS_ERROR : PS_POOL; mysql_cond_broadcast(&syncing->cond); // signal "sync done" mysql_cond_signal(&COND_pool); // in case somebody's waiting mysql_mutex_unlock(&LOCK_pool); === modified file 'sql/log.h' --- a/sql/log.h revid:alexander.nozdrin@stripped +++ b/sql/log.h revid:mikael.ronstrom@stripped @@ -51,9 +51,9 @@ class TC_LOG_MMAP: public TC_LOG { public: // only to keep Sun Forte on sol9x86 happy typedef enum { - POOL, // page is in pool - ERROR, // last sync failed - DIRTY // new xids added since last sync + PS_POOL, // page is in pool + PS_ERROR, // last sync failed + PS_DIRTY // new xids added since last sync } PAGE_STATE; private: === modified file 'sql/mdl.cc' --- a/sql/mdl.cc revid:alexander.nozdrin@stripped +++ b/sql/mdl.cc revid:mikael.ronstrom@stripped @@ -18,6 +18,8 @@ #include "debug_sync.h" #include #include +#include +#include #ifdef HAVE_PSI_INTERFACE static PSI_mutex_key key_MDL_map_mutex; @@ -970,10 +972,14 @@ MDL_wait::timed_wait(MDL_context_owner * old_msg= owner->enter_cond(&m_COND_wait_status, &m_LOCK_wait_status, wait_state_name); + thd_wait_begin(thd, THD_WAIT_META_DATA_LOCK); while (!m_wait_status && !owner->is_killed() && wait_result != ETIMEDOUT && wait_result != ETIME) + { wait_result= mysql_cond_timedwait(&m_COND_wait_status, &m_LOCK_wait_status, abs_timeout); + } + thd_wait_end(thd); if (m_wait_status == EMPTY) { === modified file 'sql/mysqld.cc' --- a/sql/mysqld.cc revid:alexander.nozdrin@stripped +++ b/sql/mysqld.cc revid:mikael.ronstrom@stripped @@ -417,7 +417,7 @@ my_bool opt_super_large_pages= 0; my_bool opt_myisam_use_mmap= 0; uint opt_large_page_size= 0; #if defined(ENABLED_DEBUG_SYNC) -uint opt_debug_sync_timeout= 0; +MYSQL_PLUGIN_IMPORT uint opt_debug_sync_timeout= 0; #endif /* defined(ENABLED_DEBUG_SYNC) */ my_bool opt_old_style_user_limits= 0, trust_function_creators= 0; /* @@ -446,7 +446,7 @@ uint lower_case_table_names; ulong tc_heuristic_recover= 0; uint volatile thread_count; int32 thread_running; -ulong thread_created; +MYSQL_PLUGIN_IMPORT ulong thread_created; ulong back_log, connect_timeout, concurrency, server_id; ulong table_cache_size, table_def_size; ulong what_to_log; @@ -473,7 +473,8 @@ ulong delayed_insert_errors,flush_time; ulong specialflag=0; ulong binlog_cache_use= 0, binlog_cache_disk_use= 0; ulong binlog_stmt_cache_use= 0, binlog_stmt_cache_disk_use= 0; -ulong max_connections, max_connect_errors; +MYSQL_PLUGIN_IMPORT ulong max_connections; +ulong max_connect_errors; /** Limit of the total number of prepared statements in the server. Is necessary to protect the server against out-of-memory attacks. @@ -577,7 +578,7 @@ Le_creator le_creator; MYSQL_FILE *bootstrap_file; int bootstrap_error; -I_List threads; +MYSQL_PLUGIN_IMPORT I_List threads; Rpl_filter* rpl_filter; Rpl_filter* binlog_filter; @@ -626,9 +627,9 @@ mysql_mutex_t LOCK_des_key_file; #endif mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; mysql_rwlock_t LOCK_system_variables_hash; -mysql_cond_t COND_thread_count; +MYSQL_PLUGIN_IMPORT mysql_cond_t COND_thread_count; pthread_t signal_thread; -pthread_attr_t connection_attrib; +MYSQL_PLUGIN_IMPORT pthread_attr_t connection_attrib; mysql_mutex_t LOCK_server_started; mysql_cond_t COND_server_started; @@ -5250,6 +5251,14 @@ static bool read_init_file(char *file_na } +/** + Increment number of created threads +*/ +void inc_thread_created(void) +{ + thread_created++; +} + #ifndef EMBEDDED_LIBRARY /* @@ -8260,7 +8269,9 @@ static PSI_cond_info all_server_conds[]= PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, key_thread_handle_manager, key_thread_main, - key_thread_one_connection, key_thread_signal_hand; + key_thread_signal_hand; + +MYSQL_PLUGIN_IMPORT PSI_thread_key key_thread_one_connection; static PSI_thread_info all_server_threads[]= { === modified file 'sql/mysqld.h' --- a/sql/mysqld.h revid:alexander.nozdrin@stripped +++ b/sql/mysqld.h revid:mikael.ronstrom@stripped @@ -221,12 +221,12 @@ extern struct my_option my_long_options[ extern int mysqld_server_started; extern "C" MYSQL_PLUGIN_IMPORT int orig_argc; extern "C" MYSQL_PLUGIN_IMPORT char **orig_argv; -extern pthread_attr_t connection_attrib; +extern MYSQL_PLUGIN_IMPORT pthread_attr_t connection_attrib; extern MYSQL_FILE *bootstrap_file; extern my_bool old_mode; extern LEX_STRING opt_init_connect, opt_init_slave; extern int bootstrap_error; -extern I_List threads; +extern MYSQL_PLUGIN_IMPORT I_List threads; extern char err_shared_dir[]; extern TYPELIB thread_handling_typelib; extern my_decimal decimal_zero; @@ -286,7 +286,9 @@ extern PSI_cond_key key_RELAYLOG_update_ extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, key_thread_handle_manager, key_thread_kill_server, key_thread_main, - key_thread_one_connection, key_thread_signal_hand; + key_thread_signal_hand; + +extern MYSQL_PLUGIN_IMPORT PSI_thread_key key_thread_one_connection; #ifdef HAVE_MMAP extern PSI_file_key key_file_map; @@ -464,7 +466,7 @@ extern mysql_mutex_t LOCK_server_started extern mysql_cond_t COND_server_started; extern mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; extern mysql_rwlock_t LOCK_system_variables_hash; -extern mysql_cond_t COND_thread_count; +extern MYSQL_PLUGIN_IMPORT mysql_cond_t COND_thread_count; extern mysql_cond_t COND_manager; extern int32 thread_running; extern my_atomic_rwlock_t thread_running_lock; === modified file 'sql/rpl_rli.cc' --- a/sql/rpl_rli.cc revid:alexander.nozdrin@stripped +++ b/sql/rpl_rli.cc revid:mikael.ronstrom@stripped @@ -27,6 +27,8 @@ #include "transaction.h" #include "sql_parse.h" // end_trans, ROLLBACK #include "rpl_slave.h" +#include +#include /* Please every time you add a new field to the relay log info, update @@ -536,6 +538,7 @@ int Relay_log_info::wait_for_pos(THD* th We are going to mysql_cond_(timed)wait(); if the SQL thread stops it will wake us up. */ + thd_wait_begin(thd, THD_WAIT_BINLOG); if (timeout > 0) { /* @@ -553,6 +556,7 @@ int Relay_log_info::wait_for_pos(THD* th } else mysql_cond_wait(&data_cond, &data_lock); + thd_wait_end(thd); DBUG_PRINT("info",("Got signal of master update or timed out")); if (error == ETIMEDOUT || error == ETIME) { === modified file 'sql/scheduler.cc' --- a/sql/scheduler.cc revid:alexander.nozdrin@stripped +++ b/sql/scheduler.cc revid:mikael.ronstrom@stripped @@ -76,14 +76,26 @@ scheduler_functions *thread_scheduler= N */ /**@{*/ -static void scheduler_wait_begin(void) { +extern "C" +{ +static void scheduler_wait_lock_begin(void) { MYSQL_CALLBACK(thread_scheduler, - thd_wait_begin, (current_thd, THD_WAIT_ROW_TABLE_LOCK)); + thd_wait_begin, (current_thd, THD_WAIT_TABLE_LOCK)); } -static void scheduler_wait_end(void) { +static void scheduler_wait_lock_end(void) { MYSQL_CALLBACK(thread_scheduler, thd_wait_end, (current_thd)); } + +static void scheduler_wait_sync_begin(void) { + MYSQL_CALLBACK(thread_scheduler, + thd_wait_begin, (current_thd, THD_WAIT_TABLE_LOCK)); +} + +static void scheduler_wait_sync_end(void) { + MYSQL_CALLBACK(thread_scheduler, thd_wait_end, (current_thd)); +} +}; /**@}*/ /** @@ -94,7 +106,10 @@ static void scheduler_wait_end(void) { mysqld.cc, so this init function will always be called. */ static void scheduler_init() { - thr_set_lock_wait_callback(scheduler_wait_begin, scheduler_wait_end); + thr_set_lock_wait_callback(scheduler_wait_lock_begin, + scheduler_wait_lock_end); + thr_set_sync_wait_callback(scheduler_wait_sync_begin, + scheduler_wait_sync_end); } /* @@ -133,10 +148,6 @@ void one_thread_scheduler() thd_scheduler::thd_scheduler() : m_psi(NULL), data(NULL) { -#ifndef DBUG_OFF - dbug_explain[0]= '\0'; - set_explain= FALSE; -#endif } === modified file 'sql/scheduler.h' --- a/sql/scheduler.h revid:alexander.nozdrin@stripped +++ b/sql/scheduler.h revid:mikael.ronstrom@stripped @@ -68,11 +68,6 @@ enum scheduler_types void one_thread_per_connection_scheduler(); void one_thread_scheduler(); -enum pool_command_op -{ - NOT_IN_USE_OP= 0, NORMAL_OP= 1, CONNECT_OP, KILL_OP, DIE_OP -}; - /* To be used for pool-of-threads (implemeneted differently on various OSs) */ @@ -93,15 +88,15 @@ public: void *data; /* scheduler-specific data structure */ -# ifndef DBUG_OFF - char dbug_explain[512]; - bool set_explain; -# endif - thd_scheduler(); ~thd_scheduler(); }; +void *thd_get_scheduler_data(THD *thd); +void thd_set_scheduler_data(THD *thd, void *data); +PSI_thread* thd_get_psi(THD *thd); +void thd_set_psi(THD *thd, PSI_thread *psi); + extern scheduler_functions *thread_scheduler; #endif === modified file 'sql/sp_head.cc' --- a/sql/sp_head.cc revid:alexander.nozdrin@stripped +++ b/sql/sp_head.cc revid:mikael.ronstrom@stripped @@ -547,7 +547,7 @@ sp_head::operator delete(void *ptr, size sp_head::sp_head() - :Query_arena(&main_mem_root, INITIALIZED_FOR_SP), + :Query_arena(&main_mem_root, STMT_INITIALIZED_FOR_SP), m_flags(0), m_sp_cache_version(0), unsafe_flags(0), @@ -1205,7 +1205,7 @@ sp_head::execute(THD *thd, bool merge_da Query_arena *old_arena; /* per-instruction arena */ MEM_ROOT execute_mem_root; - Query_arena execute_arena(&execute_mem_root, INITIALIZED_FOR_SP), + Query_arena execute_arena(&execute_mem_root, STMT_INITIALIZED_FOR_SP), backup_arena; query_id_t old_query_id; TABLE *old_derived_tables; @@ -1486,7 +1486,7 @@ sp_head::execute(THD *thd, bool merge_da thd->m_reprepare_observer= save_reprepare_observer; thd->stmt_arena= old_arena; - state= EXECUTED; + state= STMT_EXECUTED; /* Restore the caller's original warning information area: @@ -1644,7 +1644,7 @@ sp_head::execute_trigger(THD *thd, sp_rcontext *nctx = NULL; bool err_status= FALSE; MEM_ROOT call_mem_root; - Query_arena call_arena(&call_mem_root, Query_arena::INITIALIZED_FOR_SP); + Query_arena call_arena(&call_mem_root, Query_arena::STMT_INITIALIZED_FOR_SP); Query_arena backup_arena; DBUG_ENTER("sp_head::execute_trigger"); @@ -1785,7 +1785,7 @@ sp_head::execute_function(THD *thd, Item String binlog_buf(buf, sizeof(buf), &my_charset_bin); bool err_status= FALSE; MEM_ROOT call_mem_root; - Query_arena call_arena(&call_mem_root, Query_arena::INITIALIZED_FOR_SP); + Query_arena call_arena(&call_mem_root, Query_arena::STMT_INITIALIZED_FOR_SP); Query_arena backup_arena; DBUG_ENTER("sp_head::execute_function"); DBUG_PRINT("info", ("function %s", m_name.str)); @@ -2542,7 +2542,7 @@ sp_head::restore_thd_mem_root(THD *thd) DBUG_ENTER("sp_head::restore_thd_mem_root"); Item *flist= free_list; // The old list set_query_arena(thd); // Get new free_list and mem_root - state= INITIALIZED_FOR_SP; + state= STMT_INITIALIZED_FOR_SP; DBUG_PRINT("info", ("mem_root 0x%lx returned from thd mem root 0x%lx", (ulong) &mem_root, (ulong) &thd->mem_root)); @@ -3006,7 +3006,7 @@ sp_lex_keeper::reset_lex_and_exec_core(T (thd->stmt_da->sql_errno() != ER_CANT_REOPEN_TABLE && thd->stmt_da->sql_errno() != ER_NO_SUCH_TABLE && thd->stmt_da->sql_errno() != ER_UPDATE_TABLE_USED)) - thd->stmt_arena->state= Query_arena::EXECUTED; + thd->stmt_arena->state= Query_arena::STMT_EXECUTED; /* Merge here with the saved parent's values === modified file 'sql/sp_head.h' --- a/sql/sp_head.h revid:alexander.nozdrin@stripped +++ b/sql/sp_head.h revid:mikael.ronstrom@stripped @@ -556,7 +556,7 @@ public: /// Should give each a name or type code for debugging purposes? sp_instr(uint ip, sp_pcontext *ctx) - :Query_arena(0, INITIALIZED_FOR_SP), marked(0), m_ip(ip), m_ctx(ctx) + :Query_arena(0, STMT_INITIALIZED_FOR_SP), marked(0), m_ip(ip), m_ctx(ctx) {} virtual ~sp_instr() === modified file 'sql/sql_class.cc' --- a/sql/sql_class.cc revid:alexander.nozdrin@stripped +++ b/sql/sql_class.cc revid:mikael.ronstrom@stripped @@ -198,6 +198,252 @@ bool foreign_key_prefix(Key *a, Key *b) ** Thread specific functions ****************************************************************************/ +/** + Get reference to scheduler data object + + @param thd THD object + + @retval Scheduler data object on THD +*/ +void *thd_get_scheduler_data(THD *thd) +{ + return thd->scheduler.data; +} + +/** + Set reference to Scheduler data object for THD object + + @param thd THD object + @param psi Scheduler data object to set on THD +*/ +void thd_set_scheduler_data(THD *thd, void *data) +{ + thd->scheduler.data= data; +} + +/** + Get reference to Performance Schema object for THD object + + @param thd THD object + + @retval Performance schema object for thread on THD +*/ +PSI_thread *thd_get_psi(THD *thd) +{ + return thd->scheduler.m_psi; +} + +/** + Set reference to Performance Schema object for THD object + + @param thd THD object + @param psi Performance schema object for thread +*/ +void thd_set_psi(THD *thd, PSI_thread *psi) +{ + thd->scheduler.m_psi= psi; +} + +/** + Set the state on connection to killed + + @param thd THD object +*/ +void thd_set_killed(THD *thd) +{ + thd->killed= THD::KILL_CONNECTION; +} + +/** + Clear errors from the previous THD + + @param thd THD object +*/ +void thd_clear_errors(THD *thd) +{ + my_errno= 0; + thd->mysys_var->abort= 0; +} + +/** + Set thread stack in THD object + + @param thd Thread object + @param stack_start Start of stack to set in THD object +*/ +void thd_set_thread_stack(THD *thd, char *stack_start) +{ + thd->thread_stack= stack_start; +} + +/** + Lock connection data for the set of connections this connection + belongs to + + @param thd THD object +*/ +void thd_lock_thread_count(THD *) +{ + mysql_mutex_lock(&LOCK_thread_count); +} + +/** + Lock connection data for the set of connections this connection + belongs to + + @param thd THD object +*/ +void thd_unlock_thread_count(THD *) +{ + mysql_cond_broadcast(&COND_thread_count); + mysql_mutex_unlock(&LOCK_thread_count); +} + +/** + Close the socket used by this connection + + @param thd THD object +*/ +void thd_close_connection(THD *thd) +{ + if (thd->net.vio) + vio_close(thd->net.vio); +} + +/** + Get current THD object from thread local data + + @retval The THD object for the thread, NULL if not connection thread +*/ +THD *thd_get_current_thd() +{ + return current_thd; +} + +/** + Set up various THD data for a new connection + + thd_new_connection_setup + + @param thd THD object + @param stack_start Start of stack for connection +*/ +void thd_new_connection_setup(THD *thd, char *stack_start) +{ +#ifdef HAVE_PSI_INTERFACE + if (PSI_server) + thd_set_psi(thd, + PSI_server->new_thread(key_thread_one_connection, + thd, + thd_get_thread_id((MYSQL_THD)thd))); +#endif + thd->set_time(); + thd->prior_thr_create_utime= thd->thr_create_utime= thd->start_utime= + my_micro_time(); + threads.append(thd); + thd_unlock_thread_count(thd); + DBUG_PRINT("info", ("init new connection. thd: 0x%lx fd: %d", + (ulong)thd, thd->net.vio->sd)); + thd_set_thread_stack(thd, stack_start); +} + +/** + Lock data that needs protection in THD object + + @param thd THD object +*/ +void thd_lock_data(THD *thd) +{ + mysql_mutex_lock(&thd->LOCK_thd_data); +} + +/** + Unlock data that needs protection in THD object + + @param thd THD object +*/ +void thd_unlock_data(THD *thd) +{ + mysql_mutex_unlock(&thd->LOCK_thd_data); +} + +/** + Support method to check if connection has already started transcaction + + @param client_cntx Low level client context + + @retval TRUE if connection already started transaction +*/ +bool thd_is_transaction_active(THD *thd) +{ + return thd->transaction.is_active(); +} + +/** + Check if there is buffered data on the socket representing the connection + + @param thd THD object +*/ +int thd_connection_has_data(THD *thd) +{ + Vio *vio= thd->net.vio; + return vio->has_data(vio); +} + +/** + Set reading/writing on socket, used by SHOW PROCESSLIST + + @param thd THD object + @param val Value to set it to (0 or 1) +*/ +void thd_set_net_read_write(THD *thd, uint val) +{ + thd->net.reading_or_writing= val; +} + +/** + Set reference to mysys variable in THD object + + @param thd THD object + @param mysys_var Reference to set +*/ +void thd_set_mysys_var(THD *thd, st_my_thread_var *mysys_var) +{ + thd->set_mysys_var(mysys_var); +} + +/** + Get socket file descriptor for this connection + + @param thd THD object + + @retval Socket of the connection +*/ +my_socket thd_get_fd(THD *thd) +{ + return thd->net.vio->sd; +} + +/** + Get thread attributes for connection threads + + @retval Reference to thread attribute for connection threads +*/ +pthread_attr_t *get_connection_attrib(void) +{ + return &connection_attrib; +} + +/** + Get max number of connections + + @retval Max number of connections for MySQL Server +*/ +ulong get_max_connections(void) +{ + return max_connections; +} + /* The following functions form part of the C plugin API */ @@ -479,7 +725,7 @@ bool Drop_table_error_handler::handle_co THD::THD(bool enable_plugins) - :Statement(&main_lex, &main_mem_root, CONVENTIONAL_EXECUTION, + :Statement(&main_lex, &main_mem_root, STMT_CONVENTIONAL_EXECUTION, /* statement id */ 0), rli_fake(0), user_time(0), in_sub_stmt(0), @@ -3332,7 +3578,7 @@ extern "C" void thd_pool_wait_end(MYSQL_ thd_wait_end MUST be called immediately after waking up again. */ -extern "C" void thd_wait_begin(MYSQL_THD thd, thd_wait_type wait_type) +extern "C" void thd_wait_begin(MYSQL_THD thd, int wait_type) { MYSQL_CALLBACK(thread_scheduler, thd_wait_begin, (thd, wait_type)); } @@ -3348,7 +3594,7 @@ extern "C" void thd_wait_end(MYSQL_THD t MYSQL_CALLBACK(thread_scheduler, thd_wait_end, (thd)); } #else -extern "C" void thd_wait_begin(MYSQL_THD thd, thd_wait_type wait_type) +extern "C" void thd_wait_begin(MYSQL_THD thd, int wait_type) { /* do NOTHING for the embedded library */ return; === modified file 'sql/sql_class.h' --- a/sql/sql_class.h revid:alexander.nozdrin@stripped +++ b/sql/sql_class.h revid:mikael.ronstrom@stripped @@ -665,14 +665,14 @@ public: /* The states relfects three diffrent life cycles for three different types of statements: - Prepared statement: INITIALIZED -> PREPARED -> EXECUTED. - Stored procedure: INITIALIZED_FOR_SP -> EXECUTED. - Other statements: CONVENTIONAL_EXECUTION never changes. + Prepared statement: STMT_INITIALIZED -> STMT_PREPARED -> STMT_EXECUTED. + Stored procedure: STMT_INITIALIZED_FOR_SP -> STMT_EXECUTED. + Other statements: STMT_CONVENTIONAL_EXECUTION never changes. */ enum enum_state { - INITIALIZED= 0, INITIALIZED_FOR_SP= 1, PREPARED= 2, - CONVENTIONAL_EXECUTION= 3, EXECUTED= 4, ERROR= -1 + STMT_INITIALIZED= 0, STMT_INITIALIZED_FOR_SP= 1, STMT_PREPARED= 2, + STMT_CONVENTIONAL_EXECUTION= 3, STMT_EXECUTED= 4, STMT_ERROR= -1 }; enum_state state; @@ -695,18 +695,18 @@ public: virtual Type type() const; virtual ~Query_arena() {}; - inline bool is_stmt_prepare() const { return state == INITIALIZED; } + inline bool is_stmt_prepare() const { return state == STMT_INITIALIZED; } inline bool is_first_sp_execute() const - { return state == INITIALIZED_FOR_SP; } + { return state == STMT_INITIALIZED_FOR_SP; } inline bool is_stmt_prepare_or_first_sp_execute() const - { return (int)state < (int)PREPARED; } + { return (int)state < (int)STMT_PREPARED; } inline bool is_stmt_prepare_or_first_stmt_execute() const - { return (int)state <= (int)PREPARED; } - inline bool is_first_stmt_execute() const { return state == PREPARED; } + { return (int)state <= (int)STMT_PREPARED; } + inline bool is_first_stmt_execute() const { return state == STMT_PREPARED; } inline bool is_stmt_execute() const - { return state == PREPARED || state == EXECUTED; } + { return state == STMT_PREPARED || state == STMT_EXECUTED; } inline bool is_conventional() const - { return state == CONVENTIONAL_EXECUTION; } + { return state == STMT_CONVENTIONAL_EXECUTION; } inline void* alloc(size_t size) { return alloc_root(mem_root,size); } inline void* calloc(size_t size) === modified file 'sql/sql_connect.cc' --- a/sql/sql_connect.cc revid:alexander.nozdrin@stripped +++ b/sql/sql_connect.cc revid:mikael.ronstrom@stripped @@ -705,6 +705,32 @@ pthread_handler_t handle_one_connection( return 0; } +bool thd_prepare_connection(THD *thd) +{ + bool rc; + lex_start(thd); + rc= login_connection(thd); + MYSQL_AUDIT_NOTIFY_CONNECTION_CONNECT(thd); + if (rc) + return rc; + + MYSQL_CONNECTION_START(thd->thread_id, &thd->security_ctx->priv_user[0], + (char *) thd->security_ctx->host_or_ip); + + prepare_new_connection_state(thd); + return FALSE; +} + +bool thd_is_connection_alive(THD *thd) +{ + NET *net= &thd->net; + if (!net->error && + net->vio != 0 && + !(thd->killed == THD::KILL_CONNECTION)) + return TRUE; + return FALSE; +} + void do_handle_one_connection(THD *thd_arg) { THD *thd= thd_arg; @@ -747,22 +773,13 @@ void do_handle_one_connection(THD *thd_a for (;;) { - NET *net= &thd->net; bool rc; - lex_start(thd); - rc= login_connection(thd); - MYSQL_AUDIT_NOTIFY_CONNECTION_CONNECT(thd); + rc= thd_prepare_connection(thd); if (rc) goto end_thread; - MYSQL_CONNECTION_START(thd->thread_id, &thd->security_ctx->priv_user[0], - (char *) thd->security_ctx->host_or_ip); - - prepare_new_connection_state(thd); - - while (!net->error && net->vio != 0 && - !(thd->killed == THD::KILL_CONNECTION)) + while (thd_is_connection_alive(thd)) { mysql_audit_release(thd); if (do_command(thd)) === modified file 'sql/sql_connect.h' --- a/sql/sql_connect.h revid:alexander.nozdrin@stripped +++ b/sql/sql_connect.h revid:mikael.ronstrom@stripped @@ -35,6 +35,8 @@ void time_out_user_resource_limits(THD * void decrease_user_connections(USER_CONN *uc); bool thd_init_client_charset(THD *thd, uint cs_number); bool setup_connection_thread_globals(THD *thd); +bool thd_prepare_connection(THD *thd); +bool thd_is_connection_alive(THD *thd); int check_user(THD *thd, enum enum_server_command command, const char *passwd, uint passwd_len, const char *db, === modified file 'sql/sql_cursor.h' --- a/sql/sql_cursor.h revid:alexander.nozdrin@stripped +++ b/sql/sql_cursor.h revid:mikael.ronstrom@stripped @@ -42,7 +42,7 @@ protected: select_result *result; public: Server_side_cursor(MEM_ROOT *mem_root_arg, select_result *result_arg) - :Query_arena(mem_root_arg, INITIALIZED), result(result_arg) + :Query_arena(mem_root_arg, STMT_INITIALIZED), result(result_arg) {} virtual bool is_open() const= 0; === modified file 'sql/sql_prepare.cc' --- a/sql/sql_prepare.cc revid:alexander.nozdrin@stripped +++ b/sql/sql_prepare.cc revid:mikael.ronstrom@stripped @@ -2713,7 +2713,7 @@ void mysqld_stmt_reset(THD *thd, char *p */ reset_stmt_params(stmt); - stmt->state= Query_arena::PREPARED; + stmt->state= Query_arena::STMT_PREPARED; general_log_print(thd, thd->get_command(), NullS); @@ -2832,7 +2832,7 @@ void mysql_stmt_get_longdata(THD *thd, c if (param_number >= stmt->param_count) { /* Error will be sent in execute call */ - stmt->state= Query_arena::ERROR; + stmt->state= Query_arena::STMT_ERROR; stmt->last_errno= ER_WRONG_ARGUMENTS; sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS), "mysqld_stmt_send_long_data"); @@ -2856,7 +2856,7 @@ void mysql_stmt_get_longdata(THD *thd, c #endif if (thd->stmt_da->is_error()) { - stmt->state= Query_arena::ERROR; + stmt->state= Query_arena::STMT_ERROR; stmt->last_errno= thd->stmt_da->sql_errno(); strncpy(stmt->last_error, thd->stmt_da->message(), MYSQL_ERRMSG_SIZE); } @@ -3015,7 +3015,7 @@ end: Prepared_statement::Prepared_statement(THD *thd_arg) :Statement(NULL, &main_mem_root, - INITIALIZED, ++thd_arg->statement_id_counter), + STMT_INITIALIZED, ++thd_arg->statement_id_counter), thd(thd_arg), result(thd_arg), param_array(0), @@ -3288,7 +3288,7 @@ bool Prepared_statement::prepare(const c { setup_set_params(); lex->context_analysis_only&= ~CONTEXT_ANALYSIS_ONLY_PREPARE; - state= Query_arena::PREPARED; + state= Query_arena::STMT_PREPARED; flags&= ~ (uint) IS_IN_USE; /* @@ -3406,7 +3406,7 @@ Prepared_statement::execute_loop(String int reprepare_attempt= 0; /* Check if we got an error when sending long data */ - if (state == Query_arena::ERROR) + if (state == Query_arena::STMT_ERROR) { my_message(last_errno, last_error, MYF(0)); return TRUE; @@ -3469,7 +3469,7 @@ Prepared_statement::execute_server_runna Item_change_list save_change_list; thd->change_list.move_elements_to(&save_change_list); - state= CONVENTIONAL_EXECUTION; + state= STMT_CONVENTIONAL_EXECUTION; if (!(lex= new (mem_root) st_lex_local)) return TRUE; @@ -3808,8 +3808,8 @@ bool Prepared_statement::execute(String thd->set_statement(&stmt_backup); thd->stmt_arena= old_stmt_arena; - if (state == Query_arena::PREPARED) - state= Query_arena::EXECUTED; + if (state == Query_arena::STMT_PREPARED) + state= Query_arena::STMT_EXECUTED; if (error == 0 && this->lex->sql_command == SQLCOM_CALL) { === modified file 'sql/table.cc' --- a/sql/table.cc revid:alexander.nozdrin@stripped +++ b/sql/table.cc revid:mikael.ronstrom@stripped @@ -2026,7 +2026,8 @@ int open_table_from_share(THD *thd, TABL Query_arena *backup_stmt_arena_ptr= thd->stmt_arena; Query_arena backup_arena; - Query_arena part_func_arena(&outparam->mem_root, Query_arena::INITIALIZED); + Query_arena part_func_arena(&outparam->mem_root, + Query_arena::STMT_INITIALIZED); thd->set_n_backup_active_arena(&part_func_arena, &backup_arena); thd->stmt_arena= &part_func_arena; bool tmp; No bundle (reason: revision is a merge (you can force generation of a bundle with env var BZR_FORCE_BUNDLE=1)).