From 819eb3e01a8a11835a0e3cb5a51862677d150b77 Mon Sep 17 00:00:00 2001 From: Thayumanavar Date: Mon, 13 Jan 2014 12:04:16 +0530 Subject: BUG#18054998 - BACKPORT FIX FOR BUG#11765785 to 5.5 This is a backport of the patch of bug#11765785. Commit message by Prabakaran Thirumalai from bug#11765785 is reproduced below: Description: ------------ Global Query ID (global_query_id ) is not incremented for PING and statistics command. These two query types are filtered before incrementing the global query id. This causes race condition and results in duplicate query id for different queries originating from different connections. Analysis: --------- sqlparse.cc::dispath_command() is the only place in code which sets thd->query_ id to global_query_id and then increments it based on the query type. In all other places it is incremented first and then assigned to thd->query_id. This is done such that global_query_id is not incremented for PING and statistics commands in dispatch_command() function. Fix: ---- As per suggestion from Serg, "There is no reason to skip query_id for the PING and STATISTICS command.", removing the check which filters PING and statistics commands. Instead of using get_query_id() and next_query_id() which can still cause race condition if context switch happens soon after executing get_query_id(), changing the code to use next_query_id() instead of get_query_id() as it is done in other parts of code which deals with global_query_id. Removed get_query_id() function and forced next_query_id() caller to use the return value by specifying warn_unused_result attribute. --- sql/sql_parse.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 6e2b422bd44..fe9f564672a 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -237,8 +237,8 @@ void init_update_queries(void) /* Initialize the server command flags array. */ memset(server_command_flags, 0, sizeof(server_command_flags)); - server_command_flags[COM_STATISTICS]= CF_SKIP_QUERY_ID | CF_SKIP_QUESTIONS; - server_command_flags[COM_PING]= CF_SKIP_QUERY_ID | CF_SKIP_QUESTIONS; + server_command_flags[COM_STATISTICS]= CF_SKIP_QUESTIONS; + server_command_flags[COM_PING]= CF_SKIP_QUESTIONS; server_command_flags[COM_STMT_PREPARE]= CF_SKIP_QUESTIONS; server_command_flags[COM_STMT_CLOSE]= CF_SKIP_QUESTIONS; server_command_flags[COM_STMT_RESET]= CF_SKIP_QUESTIONS; @@ -901,9 +901,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->security_ctx->master_access|= SHUTDOWN_ACL; command= COM_SHUTDOWN; } - thd->set_query_id(get_query_id()); - if (!(server_command_flags[command] & CF_SKIP_QUERY_ID)) - next_query_id(); + thd->set_query_id(next_query_id()); inc_thread_running(); if (!(server_command_flags[command] & CF_SKIP_QUESTIONS)) -- cgit v1.2.1 From a10a9448b0902ca2e677f3274c06b6bf697ba3b5 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sat, 3 May 2014 19:12:17 +0300 Subject: Added new states to be able to better diagnose where server hangs. - Table locks now ends with state "After table lock" - Open table now ends with state "After opening tables" - All calls to close_thread_tables(), not only from mysql_execute_command(), has state "closing tables" - Added state "executing" for mysql admin commands, like CACHE INDEX, REPAIR TABLE etc. - Added state "Finding key cache" for CACHE INDEX - Added state "Filling schema table" when we generate temporary table for SHOW commands and information schema. Other things: Add limit from innobase for thread_sleep_delay. This fixed a failing tests case. Added db.opt to support-files to make 'make package' work mysql-test/suite/funcs_1/datadict/processlist_val.inc: Use new state mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated test result because of new state mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated test result because of new state sql/CMakeLists.txt: Have option files in support-files sql/lock.cc: Added new state 'After table lock' sql/sql_admin.cc: Added state "executing" and "Sending data" for mysql admin commands, like CACHE INDEX, REPAIR TABLE etc. Added state "Finding key cache" sql/sql_base.cc: open tables now ends with state "After table lock", instead of NULL sql/sql_parse.cc: Moved state "closing tables" to close_thread_tables() sql/sql_show.cc: Added state "Filling schema table" when we generate temporary table for SHOW commands and information schema. storage/xtradb/buf/buf0buf.c: Removed compiler warning storage/xtradb/handler/ha_innodb.cc: Add limit from innobase for thread_sleep_delay. This fixed a failing tests case. support-files/db.opt: cmakes needs this to create data/test directory --- sql/sql_parse.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 61c822f0d69..d6aebf50a70 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4579,7 +4579,6 @@ finish: } /* Free tables */ - thd_proc_info(thd, "closing tables"); close_thread_tables(thd); thd_proc_info(thd, 0); -- cgit v1.2.1