#At file:///home/malff/BZR-TREE/mysql-6.0-perf/ based on revid:marc.alff@stripped
2868 Marc Alff 2009-04-15
Fixed race conditions in the --pool-of-threads instrumentation
Fixed broken unit test
modified:
sql/scheduler.cc
storage/perfschema/unittest/pfs-t.cc
=== modified file 'sql/scheduler.cc'
--- a/sql/scheduler.cc 2009-04-14 21:37:16 +0000
+++ b/sql/scheduler.cc 2009-04-15 09:35:58 +0000
@@ -24,6 +24,9 @@
#include <mysql_priv.h>
#include "sql_audit.h"
+#ifdef HAVE_PSI_INTERFACE
+pthread_key(PSI_thread*, THR_PSI_backup);
+#endif
/*
'Dummy' functions to be used when we don't need any handling for a scheduler
@@ -196,6 +199,19 @@ bool thd_scheduler::init(THD *parent_thd
bool thd_scheduler::thread_attach()
{
DBUG_ASSERT(!thread_attached);
+
+#ifdef HAVE_PSI_INTERFACE
+ {
+ /*
+ Until now, this thread is running under the libevent instrumentation.
+ Save this instrumentation before binding to the job instrumentation,
+ THD::m_psi, in setup_connection_thread_globals().
+ */
+ PSI_thread *psi= (PSI_server ? PSI_server->get_thread() : NULL);
+ my_pthread_setspecific_ptr(THR_PSI_backup, psi);
+ }
+#endif
+
THD* thd = (THD*)list.data;
if (libevent_should_close_connection(thd) ||
setup_connection_thread_globals(thd))
@@ -226,6 +242,21 @@ void thd_scheduler::thread_detach()
{
if (thread_attached)
{
+#ifdef HAVE_PSI_INTERFACE
+ {
+ /*
+ Until now, this thread is running under the job instrumentation.
+ Restore the libevent instrumentation before giving up the job,
+ so that from now on:
+ - waits are properly counted against libevent,
+ - race conditions are not generated in the job THD::m_psi,
+ which might be picked up by another thread.
+ */
+ PSI_thread *psi= my_pthread_getspecific_ptr(PSI_thread*, THR_PSI_backup);
+ if (PSI_server)
+ PSI_server->set_thread(psi);
+ }
+#endif
THD* thd = (THD*)list.data;
MYSQL_MUTEX_LOCK(&thd->LOCK_delete);
thd->mysys_var= NULL;
@@ -274,6 +305,14 @@ static bool libevent_init(void)
killed_threads= 0;
kill_pool_threads= FALSE;
+#ifdef HAVE_PSI_INTERFACE
+ if (pthread_key_create(&THR_PSI_backup, NULL))
+ {
+ sql_print_error("Can't create thread key THR_PSI_backup");
+ DBUG_RETURN(1);
+ }
+#endif
+
MYSQL_MUTEX_INIT(key_LOCK_event_loop, &LOCK_event_loop, NULL);
MYSQL_MUTEX_INIT(key_LOCK_thd_add, &LOCK_thd_add, NULL);
@@ -732,6 +771,11 @@ static void libevent_end()
(void) MYSQL_MUTEX_DESTROY(&LOCK_event_loop);
(void) MYSQL_MUTEX_DESTROY(&LOCK_thd_add);
+
+#ifdef HAVE_PSI_INTERFACE
+ pthread_key_delete(THR_PSI_backup);
+#endif
+
DBUG_VOID_RETURN;
}
=== modified file 'storage/perfschema/unittest/pfs-t.cc'
--- a/storage/perfschema/unittest/pfs-t.cc 2009-03-31 22:26:14 +0000
+++ b/storage/perfschema/unittest/pfs-t.cc 2009-04-15 09:35:58 +0000
@@ -671,7 +671,7 @@ void test_init_disabled()
/* enabled F-A + out-of-descriptors + enabled T-1: no instrumentation */
file_info_A->m_instr.m_enabled= true;
- psi->create_file(file_key_A, "foo", (File) 1024);
+ psi->create_file(file_key_A, "foo", (File) 65000);
file_A1= lookup_file_by_name("foo");
ok(file_A1 == NULL, "not instrumented");
ok(file_lost == 1, "lost a file");
| Thread |
|---|
| • bzr commit into mysql-6.0-perf branch (marc.alff:2868) | Marc Alff | 15 Apr |