From a2d5dcea70613e631f14f512576c3ef0bd9ab63b Mon Sep 17 00:00:00 2001
From: marko <Unknown>
Date: Tue, 22 Dec 2009 08:54:55 +0000
Subject: [PATCH] branches/5.1: Merge a change from MySQL:
 ------------------------------------------------------------ revno: 3236
 committer: Satya B <satya.bn@sun.com> branch nick: mysql-5.1-bugteam
 timestamp: Tue 2009-12-01 17:48:57 +0530 message:   merge to
 mysql-5.1-bugteam    
 ------------------------------------------------------------     revno:
 3234.1.1     committer: Gleb Shchepa <gshchepa@mysql.com>     branch nick:
 mysql-5.1-bugteam     timestamp: Tue 2009-12-01 14:38:40 +0400     message:  
     Bug #38883 (reopened): thd_security_context is not thread safe, crashes?

      manual merge 5.0-->5.1, updating InnoDB plugin.
    ------------------------------------------------------------
    revno: 1810.3968.13
    committer: Gleb Shchepa <gshchepa@mysql.com>
    branch nick: mysql-5.0-bugteam
    timestamp: Tue 2009-12-01 14:24:44 +0400
    message:
      Bug #38883 (reopened): thd_security_context is not thread safe, crashes?

      The bug 38816 changed the lock that protects THD::query from
      LOCK_thread_count to LOCK_thd_data, but didn't update the associated
      InnoDB functions.

      1. The innobase_mysql_prepare_print_arbitrary_thd and the
      innobase_mysql_end_print_arbitrary_thd InnoDB functions have been
      removed, since now we have a per-thread mutex: now we don't need to wrap
      several inter-thread access tries to THD::query with a single global
      LOCK_thread_count lock, so we can simplify the code.

      2. The innobase_mysql_print_thd function has been modified to lock
      LOCK_thd_data in direct way.
---
 handler/ha_innodb.cc | 29 -----------------------------
 include/trx0trx.h    |  4 +---
 lock/lock0lock.c     | 33 ---------------------------------
 trx/trx0trx.c        |  4 +---
 4 files changed, 2 insertions(+), 68 deletions(-)

diff --git a/handler/ha_innodb.cc b/handler/ha_innodb.cc
index da571a53c36..e8af2892ee6 100644
--- a/handler/ha_innodb.cc
+++ b/handler/ha_innodb.cc
@@ -770,35 +770,6 @@ convert_error_code_to_mysql(
     	}
 }
 
-/*****************************************************************
-If you want to print a thd that is not associated with the current thread,
-you must call this function before reserving the InnoDB kernel_mutex, to
-protect MySQL from setting thd->query NULL. If you print a thd of the current
-thread, we know that MySQL cannot modify thd->query, and it is not necessary
-to call this. Call innobase_mysql_end_print_arbitrary_thd() after you release
-the kernel_mutex.
-NOTE that /mysql/innobase/lock/lock0lock.c must contain the prototype for this
-function! */
-extern "C"
-void
-innobase_mysql_prepare_print_arbitrary_thd(void)
-/*============================================*/
-{
-	VOID(pthread_mutex_lock(&LOCK_thread_count));
-}
-
-/*****************************************************************
-Releases the mutex reserved by innobase_mysql_prepare_print_arbitrary_thd().
-NOTE that /mysql/innobase/lock/lock0lock.c must contain the prototype for this
-function! */
-extern "C"
-void
-innobase_mysql_end_print_arbitrary_thd(void)
-/*========================================*/
-{
-	VOID(pthread_mutex_unlock(&LOCK_thread_count));
-}
-
 /*****************************************************************
 Prints info of a THD object (== user session thread) to the given file.
 NOTE that /mysql/innobase/trx/trx0trx.c must contain the prototype for
diff --git a/include/trx0trx.h b/include/trx0trx.h
index f0833bc6f21..cdbf1970715 100644
--- a/include/trx0trx.h
+++ b/include/trx0trx.h
@@ -318,9 +318,7 @@ trx_commit_step(
 
 /**************************************************************************
 Prints info about a transaction to the given file. The caller must own the
-kernel mutex and must have called
-innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL
-or InnoDB cannot meanwhile change the info printed here. */
+kernel mutex. */
 
 void
 trx_print(
diff --git a/lock/lock0lock.c b/lock/lock0lock.c
index 59bb6728ed3..6654585721b 100644
--- a/lock/lock0lock.c
+++ b/lock/lock0lock.c
@@ -22,31 +22,6 @@ Created 5/7/1996 Heikki Tuuri
 #include "trx0sys.h"
 
 
-/* 2 function prototypes copied from ha_innodb.cc: */
-
-/*****************************************************************
-If you want to print a thd that is not associated with the current thread,
-you must call this function before reserving the InnoDB kernel_mutex, to
-protect MySQL from setting thd->query NULL. If you print a thd of the current
-thread, we know that MySQL cannot modify thd->query, and it is not necessary
-to call this. Call innobase_mysql_end_print_arbitrary_thd() after you release
-the kernel_mutex.
-NOTE that /mysql/innobase/lock/lock0lock.c must contain the prototype for this
-function! */
-
-void
-innobase_mysql_prepare_print_arbitrary_thd(void);
-/*============================================*/
-
-/*****************************************************************
-Relases the mutex reserved by innobase_mysql_prepare_print_arbitrary_thd().
-NOTE that /mysql/innobase/lock/lock0lock.c must contain the prototype for this
-function! */
-
-void
-innobase_mysql_end_print_arbitrary_thd(void);
-/*========================================*/
-
 /* Restricts the length of search we will do in the waits-for
 graph of transactions */
 #define LOCK_MAX_N_STEPS_IN_DEADLOCK_CHECK 1000000
@@ -4227,11 +4202,6 @@ lock_print_info_summary(
 	ibool	nowait)	/* in: whether to wait for the kernel
 			mutex */
 {
-	/* We must protect the MySQL thd->query field with a MySQL mutex, and
-	because the MySQL mutex must be reserved before the kernel_mutex of
-	InnoDB, we call innobase_mysql_prepare_print_arbitrary_thd() here. */
-
-	innobase_mysql_prepare_print_arbitrary_thd();
 
 	/* if nowait is FALSE, wait on the kernel mutex,
 	otherwise return immediately if fail to obtain the
@@ -4331,7 +4301,6 @@ lock_print_info_all_transactions(
 
 	if (trx == NULL) {
 		lock_mutex_exit_kernel();
-		innobase_mysql_end_print_arbitrary_thd();
 
 		ut_ad(lock_validate());
 
@@ -4403,7 +4372,6 @@ lock_print_info_all_transactions(
 
 		if (load_page_first) {
 			lock_mutex_exit_kernel();
-			innobase_mysql_end_print_arbitrary_thd();
 
 			mtr_start(&mtr);
 
@@ -4414,7 +4382,6 @@ lock_print_info_all_transactions(
 
 			load_page_first = FALSE;
 
-			innobase_mysql_prepare_print_arbitrary_thd();
 			lock_mutex_enter_kernel();
 
 			goto loop;
diff --git a/trx/trx0trx.c b/trx/trx0trx.c
index 8ada38845c5..fae479feddc 100644
--- a/trx/trx0trx.c
+++ b/trx/trx0trx.c
@@ -1652,9 +1652,7 @@ trx_mark_sql_stat_end(
 
 /**************************************************************************
 Prints info about a transaction to the given file. The caller must own the
-kernel mutex and must have called
-innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL
-or InnoDB cannot meanwhile change the info printed here. */
+kernel mutex. */
 
 void
 trx_print(
-- 
2.30.9