List:Commits« Previous MessageNext Message »
From:Marc Alff Date:January 7 2010 6:16pm
Subject:bzr commit into mysql-trunk-perfschema branch (marc.alff:2998) Bug#50148
View as plain text  
#At file:///home/malff/BZR_TREE/mysql-trunk-perfschema/ based on revid:marc.alff@stripped

 2998 Marc Alff	2010-01-07
      Bug#50148 "Error in my_thread_global_end(): 1 threads didn't exit" with perfschema
      
      When compiling a server with the performance schema, spurious messages
      like "Error in my_thread_global_end(): 1 threads didn't exit" could sometime
      be seen during shutdown.
      
      The root cause for this issue is as follows (found by analysis):
      - initialize_performance_schema(), depending on the startup parameters,
        would sometime not create the THR_PFS key with pthread_key_create().
      - shutdown_performance_schema() would execute
        my_pthread_setspecific_ptr(THR_PFS, NULL);
        pthread_key_delete(THR_PFS);THR_PFS
        for an uninitialized key.
      
      On a linux box in debug, the value of a non initialized THR_PFS key
      is 0, which matches the value of the first key created by the server,
      THR_KEY_mysys.
      
      The net effect of this code is:
      - shutdown_performance_schema() would knock down the thread local storage
      used by mysys during shutdown, causing unexpected failures.
      
      The fix is to ensure that cleanup in thread local storage for the
      performance schema is only executed when initialization was done.
      
      No test case provided (no repeatable test case).

    modified:
      storage/perfschema/pfs.cc
      storage/perfschema/pfs.h
      storage/perfschema/pfs_server.cc
=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc	2009-12-09 15:37:43 +0000
+++ b/storage/perfschema/pfs.cc	2010-01-07 18:16:40 +0000
@@ -674,6 +674,7 @@ static inline int mysql_mutex_lock(...)
 */
 
 pthread_key(PFS_thread*, THR_PFS);
+bool THR_PFS_initialized= false;
 
 static enum_operation_type mutex_operation_map[]=
 {

=== modified file 'storage/perfschema/pfs.h'
--- a/storage/perfschema/pfs.h	2009-09-21 09:35:17 +0000
+++ b/storage/perfschema/pfs.h	2010-01-07 18:16:40 +0000
@@ -28,6 +28,7 @@
 
 extern struct PSI_bootstrap PFS_bootstrap;
 extern pthread_key(PFS_thread*, THR_PFS);
+extern bool THR_PFS_initialized;
 
 #endif
 

=== modified file 'storage/perfschema/pfs_server.cc'
--- a/storage/perfschema/pfs_server.cc	2009-10-17 01:29:55 +0000
+++ b/storage/perfschema/pfs_server.cc	2010-01-07 18:16:40 +0000
@@ -52,6 +52,11 @@ initialize_performance_schema(const PFS_
   init_timers();
   PFS_atomic::init();
 
+  if (pthread_key_create(&THR_PFS, destroy_pfs_thread))
+    return NULL;
+
+  THR_PFS_initialized= true;
+
   if (init_sync_class(param->m_mutex_class_sizing,
                       param->m_rwlock_class_sizing,
                       param->m_cond_class_sizing) ||
@@ -61,7 +66,6 @@ initialize_performance_schema(const PFS_
       init_instruments(param) ||
       init_events_waits_history_long(
         param->m_events_waits_history_long_sizing) ||
-      pthread_key_create(&THR_PFS, destroy_pfs_thread) ||
       init_file_hash() ||
       init_table_share_hash())
   {
@@ -113,7 +117,15 @@ void shutdown_performance_schema(void)
 {
   pfs_initialized= false;
   cleanup_performance_schema();
-  my_pthread_setspecific_ptr(THR_PFS, NULL);
-  pthread_key_delete(THR_PFS);
+  /*
+    Be careful to not delete un-initialized keys,
+    this would affect key 0, which is THR_KEY_mysys,
+  */
+  if (THR_PFS_initialized)
+  {
+    my_pthread_setspecific_ptr(THR_PFS, NULL);
+    pthread_key_delete(THR_PFS);
+    THR_PFS_initialized= false;
+  }
 }
 


Attachment: [text/bzr-bundle] bzr/marc.alff@sun.com-20100107181640-l2t5moekisod8xbv.bundle
Thread
bzr commit into mysql-trunk-perfschema branch (marc.alff:2998) Bug#50148Marc Alff7 Jan