summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/suite/perfschema/r/show_coverage.result20
-rw-r--r--mysql-test/suite/perfschema/r/show_plugin.result32
-rw-r--r--mysql-test/suite/perfschema/r/variables_by_thread.result154
-rw-r--r--mysql-test/suite/perfschema/t/show_coverage.test22
-rw-r--r--mysql-test/suite/perfschema/t/show_plugin.test8
-rw-r--r--mysql-test/suite/perfschema/t/variables_by_thread.combinations4
-rw-r--r--mysql-test/suite/perfschema/t/variables_by_thread.test157
-rw-r--r--sql/my_apc.cc2
-rw-r--r--sql/sql_class.cc1
-rw-r--r--sql/sql_parse.cc5
-rw-r--r--storage/perfschema/pfs_variable.cc5
11 files changed, 357 insertions, 53 deletions
diff --git a/mysql-test/suite/perfschema/r/show_coverage.result b/mysql-test/suite/perfschema/r/show_coverage.result
index a0841fc3714..47eeb732126 100644
--- a/mysql-test/suite/perfschema/r/show_coverage.result
+++ b/mysql-test/suite/perfschema/r/show_coverage.result
@@ -96,23 +96,3 @@ FLUSH STATUS;
#
include/assert.inc [Global value requested from the default session after FLUSH must remain the same]
include/assert.inc [Default session value after FLUSH must remain zero]
-# BUG: results from inactive connections are not shown
-SET time_zone= '+2:00';
-connect con1, localhost, root,,;
-set time_zone= '+10:00';
-SELECT THREAD_ID INTO @con1_thread_id FROM performance_schema.threads
-WHERE PROCESSLIST_ID = CONNECTION_ID();
-SELECT thread_id = @con1_thread_id as current, variable_value
-FROM performance_schema.variables_by_thread
-WHERE variable_name = "time_zone";
-current variable_value
-1 +10:00
-disconnect con1;
-connection default;
-SELECT THREAD_ID INTO @def_thread_id FROM performance_schema.threads
-WHERE PROCESSLIST_ID = CONNECTION_ID();
-SELECT thread_id = @def_thread_id as current, variable_value
-FROM performance_schema.variables_by_thread
-WHERE variable_name = "time_zone";
-current variable_value
-1 +02:00
diff --git a/mysql-test/suite/perfschema/r/show_plugin.result b/mysql-test/suite/perfschema/r/show_plugin.result
index 15175bd21b9..9e510ed97ff 100644
--- a/mysql-test/suite/perfschema/r/show_plugin.result
+++ b/mysql-test/suite/perfschema/r/show_plugin.result
@@ -411,11 +411,23 @@ example_varopt_default 5
#
# Variables by thread
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
-WHERE variable_name LIKE "example_%" ORDER BY variable_value;
+WHERE variable_name LIKE "example_%" ORDER BY variable_value, variable_name;
variable_name variable_value
example_deprecated_var 0
+example_deprecated_var 0
+example_deprecated_var 0
+example_deprecated_var 0
+example_int_var 0
+example_int_var 0
+example_int_var 0
example_int_var 0
example_double_thdvar 300.000000
+example_double_thdvar 300.111100
+example_double_thdvar 300.222200
+example_double_thdvar 300.333300
+example_varopt_default 5
+example_varopt_default 5
+example_varopt_default 5
example_varopt_default 5
#
# ================================================================================
@@ -489,7 +501,7 @@ example_varopt_default 5
#
# Variables by thread
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
-WHERE variable_name LIKE "example_%" ORDER BY variable_value;
+WHERE variable_name LIKE "example_%" ORDER BY variable_value, variable_name;
variable_name variable_value
example_deprecated_var 0
example_int_var 0
@@ -570,11 +582,23 @@ example_varopt_default 5
#
# Variables by thread
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
-WHERE variable_name LIKE "example_%" ORDER BY variable_value;
+WHERE variable_name LIKE "example_%" ORDER BY variable_value, variable_name;
variable_name variable_value
example_deprecated_var 0
+example_deprecated_var 0
+example_deprecated_var 0
+example_deprecated_var 0
+example_int_var 0
+example_int_var 0
+example_int_var 0
example_int_var 0
example_double_thdvar 300.000000
+example_double_thdvar 311.111100
+example_double_thdvar 322.222200
+example_double_thdvar 333.333300
+example_varopt_default 5
+example_varopt_default 5
+example_varopt_default 5
example_varopt_default 5
#
# ================================================================================
@@ -612,7 +636,7 @@ variable_name variable_value
#
# VARIABLES BY THREAD
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
-WHERE variable_name LIKE "example_%" ORDER BY variable_value;
+WHERE variable_name LIKE "example_%" ORDER BY variable_value, variable_name;
variable_name variable_value
#
# ================================================================================
diff --git a/mysql-test/suite/perfschema/r/variables_by_thread.result b/mysql-test/suite/perfschema/r/variables_by_thread.result
new file mode 100644
index 00000000000..afb4976eb20
--- /dev/null
+++ b/mysql-test/suite/perfschema/r/variables_by_thread.result
@@ -0,0 +1,154 @@
+#
+# Results from inactive connections are shown
+#
+SET time_zone= '+2:00';
+SELECT THREAD_ID INTO @def_thread_id FROM performance_schema.threads
+WHERE PROCESSLIST_ID = CONNECTION_ID();
+connect con2, localhost, root,,;
+connect con1, localhost, root,,;
+set time_zone= '+10:00';
+SELECT THREAD_ID INTO @con1_thread_id FROM performance_schema.threads
+WHERE PROCESSLIST_ID = CONNECTION_ID();
+SELECT thread_id = @con1_thread_id as current, variable_value
+FROM performance_schema.variables_by_thread
+WHERE variable_name = "time_zone";
+current variable_value
+0 +02:00
+0 SYSTEM
+1 +10:00
+connection con2;
+connection default;
+SELECT thread_id = @def_thread_id as current, variable_value
+FROM performance_schema.variables_by_thread
+WHERE variable_name = "time_zone";
+current variable_value
+1 +02:00
+0 SYSTEM
+0 +10:00
+#
+# Notify APC before net_read
+#
+connection con2;
+select "good";
+good
+good
+connection con1;
+set debug_sync= "before_do_command_net_read SIGNAL net WAIT_FOR pass";
+connection default;
+set debug_sync= "now WAIT_FOR net";
+set debug_sync= "apc_after_notify SIGNAL pass";
+SELECT thread_id = @def_thread_id as current, variable_value
+FROM performance_schema.variables_by_thread
+WHERE variable_name = "time_zone";
+current variable_value
+1 +02:00
+0 SYSTEM
+0 +10:00
+set debug_sync= "now SIGNAL pass";
+connection con1;
+connection default;
+#
+# Test timeout
+#
+set @old_dbug= @@global.debug_dbug;
+set global debug_dbug= "+d,apc_timeout";
+connection con2;
+select "good";
+good
+good
+connection con1;
+set debug_sync= "now SIGNAL waiting WAIT_FOR pass";
+connection default;
+set debug_sync= "now WAIT_FOR waiting";
+# Should timeout in 1ms.
+SELECT thread_id = @def_thread_id as current, variable_value
+FROM performance_schema.variables_by_thread
+WHERE variable_name = "time_zone"
+and thread_id in (@def_thread_id,
+@con1_thread_id);
+current variable_value
+1 +02:00
+set debug_sync= "now SIGNAL pass";
+connection con1;
+SELECT "ok";
+ok
+ok
+connection con2;
+select "good";
+good
+good
+connection default;
+set global debug_dbug= @old_dbug;
+#
+# Two requests
+#
+connection con1;
+set debug_sync= "before_do_command_net_read SIGNAL net WAIT_FOR pass";
+SELECT "work";
+connection con2;
+set debug_sync= "now WAIT_FOR net";
+set debug_sync= "apc_after_notify SIGNAL con2_hangs";
+SELECT thread_id = @con1_thread_id as `con1's`, variable_value
+FROM performance_schema.variables_by_thread
+WHERE variable_name = "time_zone";
+connection default;
+set debug_sync= "now WAIT_FOR con2_hangs";
+set debug_sync= "apc_after_notify SIGNAL pass";
+SELECT thread_id = @def_thread_id as current, variable_value
+FROM performance_schema.variables_by_thread
+WHERE variable_name = "time_zone";
+current variable_value
+1 +02:00
+0 SYSTEM
+0 +10:00
+connection con1;
+work
+work
+connection con2;
+con1's variable_value
+0 +02:00
+0 SYSTEM
+1 +10:00
+select "good";
+good
+good
+#
+# Result from the killed query is shown.
+#
+connection con1;
+set debug_sync= "after_dispatch_command SIGNAL dispatched WAIT_FOR pass";
+SELECT "work";
+connection default;
+set debug_sync= "now WAIT_FOR dispatched";
+KILL QUERY @con1_kill_thread_id;
+connection default;
+SELECT thread_id = @def_thread_id as current, variable_value
+FROM performance_schema.variables_by_thread
+WHERE variable_name = "time_zone";
+current variable_value
+1 +02:00
+0 SYSTEM
+0 +10:00
+set debug_sync= "now SIGNAL pass";
+#
+# Result from the killed connection is ignored.
+#
+connection con1;
+work
+work
+set debug_sync= "after_dispatch_command SIGNAL dispatched WAIT_FOR pass";
+SELECT "work";
+connection default;
+set debug_sync= "now WAIT_FOR dispatched";
+KILL CONNECTION @con1_kill_thread_id;
+SELECT thread_id = @def_thread_id as current, variable_value
+FROM performance_schema.variables_by_thread
+WHERE variable_name = "time_zone";
+current variable_value
+1 +02:00
+0 SYSTEM
+# Cleanup
+connection default;
+set debug_sync= "reset";
+disconnect con1;
+disconnect con2;
diff --git a/mysql-test/suite/perfschema/t/show_coverage.test b/mysql-test/suite/perfschema/t/show_coverage.test
index 78c59ea101f..84a6f27113e 100644
--- a/mysql-test/suite/perfschema/t/show_coverage.test
+++ b/mysql-test/suite/perfschema/t/show_coverage.test
@@ -143,25 +143,3 @@ FLUSH STATUS;
--let $assert_text = Default session value after FLUSH must remain zero
--source include/assert.inc
-
---echo # BUG: results from inactive connections are not shown
-SET time_zone= '+2:00';
-
---connect (con1, localhost, root,,)
-set time_zone= '+10:00';
-
-SELECT THREAD_ID INTO @con1_thread_id FROM performance_schema.threads
- WHERE PROCESSLIST_ID = CONNECTION_ID();
-
-SELECT thread_id = @con1_thread_id as current, variable_value
- FROM performance_schema.variables_by_thread
- WHERE variable_name = "time_zone";
-
---disconnect con1
---connection default
-
-SELECT THREAD_ID INTO @def_thread_id FROM performance_schema.threads
- WHERE PROCESSLIST_ID = CONNECTION_ID();
-SELECT thread_id = @def_thread_id as current, variable_value
- FROM performance_schema.variables_by_thread
- WHERE variable_name = "time_zone";
diff --git a/mysql-test/suite/perfschema/t/show_plugin.test b/mysql-test/suite/perfschema/t/show_plugin.test
index 7109c3140c6..084b62ac297 100644
--- a/mysql-test/suite/perfschema/t/show_plugin.test
+++ b/mysql-test/suite/perfschema/t/show_plugin.test
@@ -175,7 +175,7 @@ SET SESSION example_double_thdvar = 300.3333;
--echo #
--echo # Variables by thread
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
-WHERE variable_name LIKE "example_%" ORDER BY variable_value;
+WHERE variable_name LIKE "example_%" ORDER BY variable_value, variable_name;
--echo #
--echo # ================================================================================
@@ -203,7 +203,7 @@ WHERE variable_name LIKE "example_%" ORDER BY variable_value;
--echo #
--echo # Variables by thread
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
-WHERE variable_name LIKE "example_%" ORDER BY variable_value;
+WHERE variable_name LIKE "example_%" ORDER BY variable_value, variable_name;
--echo #
--echo # ================================================================================
@@ -228,7 +228,7 @@ SET SESSION example_double_thdvar = 333.3333;
--echo #
--echo # Variables by thread
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
-WHERE variable_name LIKE "example_%" ORDER BY variable_value;
+WHERE variable_name LIKE "example_%" ORDER BY variable_value, variable_name;
--echo #
--echo # ================================================================================
@@ -244,7 +244,7 @@ UNINSTALL PLUGIN example;
--echo #
--echo # VARIABLES BY THREAD
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
-WHERE variable_name LIKE "example_%" ORDER BY variable_value;
+WHERE variable_name LIKE "example_%" ORDER BY variable_value, variable_name;
--echo #
--echo # ================================================================================
diff --git a/mysql-test/suite/perfschema/t/variables_by_thread.combinations b/mysql-test/suite/perfschema/t/variables_by_thread.combinations
new file mode 100644
index 00000000000..103ffffed90
--- /dev/null
+++ b/mysql-test/suite/perfschema/t/variables_by_thread.combinations
@@ -0,0 +1,4 @@
+[thread-per-connection]
+thread-handling=one-thread-per-connection
+[tpool]
+thread-handling=pool-of-threads
diff --git a/mysql-test/suite/perfschema/t/variables_by_thread.test b/mysql-test/suite/perfschema/t/variables_by_thread.test
new file mode 100644
index 00000000000..e63b3363fa4
--- /dev/null
+++ b/mysql-test/suite/perfschema/t/variables_by_thread.test
@@ -0,0 +1,157 @@
+--source include/have_perfschema.inc
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+
+--echo #
+--echo # Results from inactive connections are shown
+--echo #
+SET time_zone= '+2:00';
+
+SELECT THREAD_ID INTO @def_thread_id FROM performance_schema.threads
+ WHERE PROCESSLIST_ID = CONNECTION_ID();
+
+--connect (con2, localhost, root,,)
+--connect (con1, localhost, root,,)
+set time_zone= '+10:00';
+
+SELECT THREAD_ID INTO @con1_thread_id FROM performance_schema.threads
+ WHERE PROCESSLIST_ID = CONNECTION_ID();
+
+let $con1_thread_id= `select @con1_thread_id`;
+let $con1_kill_thread_id= `select CONNECTION_ID()`;
+
+SELECT thread_id = @con1_thread_id as current, variable_value
+ FROM performance_schema.variables_by_thread
+ WHERE variable_name = "time_zone";
+
+--connection con2
+--disable_query_log
+eval set @con1_thread_id= $con1_thread_id;
+eval set @con1_kill_thread_id= $con1_kill_thread_id;
+--enable_query_log
+
+--connection default
+--disable_query_log
+eval set @con1_thread_id= $con1_thread_id;
+eval set @con1_kill_thread_id= $con1_kill_thread_id;
+--enable_query_log
+
+SELECT thread_id = @def_thread_id as current, variable_value
+ FROM performance_schema.variables_by_thread
+ WHERE variable_name = "time_zone";
+
+--echo #
+--echo # Notify APC before net_read
+--echo #
+--connection con2
+select "good";
+--connection con1
+--send
+set debug_sync= "before_do_command_net_read SIGNAL net WAIT_FOR pass";
+--connection default
+set debug_sync= "now WAIT_FOR net";
+set debug_sync= "apc_after_notify SIGNAL pass";
+SELECT thread_id = @def_thread_id as current, variable_value
+ FROM performance_schema.variables_by_thread
+ WHERE variable_name = "time_zone";
+
+set debug_sync= "now SIGNAL pass";
+--connection con1
+--reap
+--connection default
+
+--echo #
+--echo # Test timeout
+--echo #
+set @old_dbug= @@global.debug_dbug;
+set global debug_dbug= "+d,apc_timeout";
+--connection con2
+select "good";
+--connection con1
+--send
+set debug_sync= "now SIGNAL waiting WAIT_FOR pass";
+--connection default
+set debug_sync= "now WAIT_FOR waiting";
+--echo # Should timeout in 1ms.
+SELECT thread_id = @def_thread_id as current, variable_value
+ FROM performance_schema.variables_by_thread
+ WHERE variable_name = "time_zone"
+ and thread_id in (@def_thread_id,
+ @con1_thread_id); # con2 can be nondeterministically skipped
+set debug_sync= "now SIGNAL pass";
+--connection con1
+--reap
+SELECT "ok";
+--connection con2
+select "good";
+--connection default
+set global debug_dbug= @old_dbug;
+
+--echo #
+--echo # Two requests
+--echo #
+
+--connection con1
+set debug_sync= "before_do_command_net_read SIGNAL net WAIT_FOR pass";
+--send
+SELECT "work";
+--connection con2
+set debug_sync= "now WAIT_FOR net";
+set debug_sync= "apc_after_notify SIGNAL con2_hangs";
+--send
+SELECT thread_id = @con1_thread_id as `con1's`, variable_value
+ FROM performance_schema.variables_by_thread
+ WHERE variable_name = "time_zone";
+--connection default
+set debug_sync= "now WAIT_FOR con2_hangs";
+set debug_sync= "apc_after_notify SIGNAL pass";
+SELECT thread_id = @def_thread_id as current, variable_value
+ FROM performance_schema.variables_by_thread
+ WHERE variable_name = "time_zone";
+
+--connection con1
+--reap
+--connection con2
+--reap
+select "good";
+
+--echo #
+--echo # Result from the killed query is shown.
+--echo #
+
+--connection con1
+set debug_sync= "after_dispatch_command SIGNAL dispatched WAIT_FOR pass";
+--send
+SELECT "work";
+--connection default
+set debug_sync= "now WAIT_FOR dispatched";
+KILL QUERY @con1_kill_thread_id;
+--connection default
+SELECT thread_id = @def_thread_id as current, variable_value
+ FROM performance_schema.variables_by_thread
+ WHERE variable_name = "time_zone";
+
+set debug_sync= "now SIGNAL pass";
+
+--echo #
+--echo # Result from the killed connection is ignored.
+--echo #
+
+--connection con1
+--reap
+set debug_sync= "after_dispatch_command SIGNAL dispatched WAIT_FOR pass";
+--send
+SELECT "work";
+--connection default
+set debug_sync= "now WAIT_FOR dispatched";
+KILL CONNECTION @con1_kill_thread_id;
+SELECT thread_id = @def_thread_id as current, variable_value
+ FROM performance_schema.variables_by_thread
+ WHERE variable_name = "time_zone";
+
+
+--echo # Cleanup
+--connection default
+set debug_sync= "reset";
+--disconnect con1
+--disconnect con2
diff --git a/sql/my_apc.cc b/sql/my_apc.cc
index 06e4fdac9a3..a5c3d2a2822 100644
--- a/sql/my_apc.cc
+++ b/sql/my_apc.cc
@@ -132,6 +132,8 @@ int Apc_target::wait_for_completion(THD *caller_thd, Call_request *apc_request,
struct timespec abstime;
const int timeout= timeout_sec;
set_timespec(abstime, timeout);
+
+ DBUG_EXECUTE_IF("apc_timeout", set_timespec_nsec(abstime, 1000000););
int res = 1;
int wait_res= 0;
PSI_stage_info old_stage;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 00af11862bb..b0c23269233 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -4383,6 +4383,7 @@ void thd_net_process_apc_requests(THD *thd)
#endif
if (unlikely(thd->apc_target.have_apc_requests()))
thd->apc_target.process_apc_requests();
+ DEBUG_SYNC(thd, "net_after_apc");
#ifdef WIN32
SetLastError(last_error);
#else
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index eb2b52dbc18..ec86389d08f 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1296,7 +1296,8 @@ dispatch_command_return do_command(THD *thd, bool blocking)
goto out;
}
- thd->apc_target.process_apc_requests();
+ if (unlikely(thd->apc_target.have_apc_requests()))
+ thd->apc_target.process_apc_requests();
packet= (char*) net->read_pos;
/*
@@ -1408,6 +1409,8 @@ dispatch_command_return do_command(THD *thd, bool blocking)
resume:
return_value= dispatch_command(command, thd, packet+1,
(uint) (packet_length-1), blocking);
+ DEBUG_SYNC(thd, "after_dispatch_command");
+
if (return_value == DISPATCH_COMMAND_WOULDBLOCK)
{
/* Save current state, and resume later.*/
diff --git a/storage/perfschema/pfs_variable.cc b/storage/perfschema/pfs_variable.cc
index bc3227da16a..656a8610362 100644
--- a/storage/perfschema/pfs_variable.cc
+++ b/storage/perfschema/pfs_variable.cc
@@ -384,7 +384,7 @@ void PFS_system_variable_cache::refresh_one_var(uint index)
int PFS_system_variable_cache::make_call(Request_func func, uint param)
{
int ret= 0;
- THD *requestor_thd= current_thd;
+ THD *requestor_thd= m_current_thd;
if (requestor_thd == m_safe_thd)
{
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
@@ -404,8 +404,9 @@ int PFS_system_variable_cache::make_call(Request_func func, uint param)
return 1;
}
}
+ DEBUG_SYNC(requestor_thd, "apc_after_notify");
ret= m_safe_thd->apc_target.wait_for_completion(requestor_thd, request,
- 30);
+ 10);
if (ret == 0)
delete request;
}