Bug #41680 calls to trx_allocate_for_mysql are not consistent
Submitted: 22 Dec 2008 20:20 Modified: 19 Jun 2010 0:28
Reporter: Mark Callaghan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB Plugin storage engine Severity:S3 (Non-critical)
Version:5.1.30 OS:Any
Assigned to: Marko Mäkelä CPU Architecture:Any
Tags: innodb, plugin, trx_allocate_for_mysql
Triage: Triaged: D4 (Minor) / R3 (Medium)

[22 Dec 2008 20:20] Mark Callaghan
Description:
This is for the InnoDB 1.0.2 plugin, which is different than the InnoDB source distributed with 5.1.30.

Calls to trx_allocate_for_mysql from ha_innodb.cc are not consistent.

check_trx_exists:
  * may set support_xa, check_foreigns, check_unique_secondary
  * does not check if thd == NULL, always sets mysql_query_str

::create, ::delete_table
  * may set check_foreigns, check_unique_secondary
  * does not check if thd == NULL, always sets mysql_query_str

::innobase_drop_database
  * may set check_foreigns
  * checks if thd == NULL, sets mysql_query_str when thd != NULL

How to repeat:
read the source

Suggested fix:
Put redundant code in a shared function
[23 Dec 2008 16:02] Mikhail Izioumtchenko
Marko, could you review Mark's findings and if necessary set the bug to Verified state and compute the triage values for Risk/Effort. Regarding the latter
my impression from the mysql_query_str story and my own little bit of work
on support_xa was that shuffling that code isn't quite risk free and not
quite so trivial. I wonder though if we need a debugging assert 
in some places on thd not being NULL. The variable value retrieval as 
you know can handle THD being null, setting mysql_query_str could be a different matter.
[5 Jan 2009 13:46] Marko Mäkelä
Thank you for your review, Mark.

The MySQL thread object (thd, ha_innobase::user_thd, handler::ha_thd(), current_thd) should never be NULL in code that is being executed by a MySQL connection thread.

The only exception is the function innobase_drop_database() in the InnoDB plugin compiled for Windows. The reason for this is that the macro current_thd does not work across a Windows DLL boundary. We were able to eliminate all other instances of current_thd in the InnoDB plugin 1.0.2.

I agree that InnoDB should call trx_allocate_for_mysql() only through one function that copies the session parameters from MySQL.
[6 Jan 2009 17:50] Mikhail Izioumtchenko
assigning back to Marko then. I'm not sure if I completely understand
the last part of Marko's note, though. Copying all MySQL's variables
in the beginning of each session, roughly speaking,could be costly
whereas reading them like we do now, when we need them and only those
we need is prone to deadlocks as in bug #41163 which appears
to be MySQL's problem. Even a single variable read appears to be unnecessarily
costly in it's MySQL part but this is a different story.
[7 Jan 2009 14:17] Marko Mäkelä
The fix will be included in InnoDB Plugin 1.0.3, due some time later.
[9 Jan 2009 6:51] Marko Mäkelä
Michael, just a small clarification. With "the session parameters", I was not referring to all THDVAR() but just those variables that were already being copied to trx_t. Thanks for the reference to Bug #41163. I wanted to refer to that bug report myself, but was unable to find it.
[21 May 2009 7:30] Calvin Sun
The InnoDB Plugin was released in March 2009.
[5 May 2010 15:23] Bugs System
Pushed into 5.1.47 (revid:joro@sun.com-20100505145753-ivlt4hclbrjy8eye) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[6 May 2010 16:58] Paul Dubois
Push resulted from incorporation of InnoDB tree. No changes pertinent to this bug.
Re-closing.
[28 May 2010 5:59] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100524190136-egaq7e8zgkwb9aqi) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (pib:16)
[28 May 2010 6:27] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100524190941-nuudpx60if25wsvx) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[28 May 2010 6:55] Bugs System
Pushed into 5.5.5-m3 (revid:alik@sun.com-20100524185725-c8k5q7v60i5nix3t) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[30 May 2010 0:14] Paul Dubois
Push resulted from incorporation of InnoDB tree. No changes pertinent to this bug.
Re-closing.
[15 Jun 2010 8:21] Bugs System
Pushed into 5.5.5-m3 (revid:alik@sun.com-20100615080459-smuswd9ooeywcxuc) (version source revid:mmakela@bk-internal.mysql.com-20100415070122-1nxji8ym4mao13ao) (merge vers: 5.1.47) (pib:16)
[15 Jun 2010 8:38] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100615080558-cw01bzdqr1bdmmec) (version source revid:mmakela@bk-internal.mysql.com-20100415070122-1nxji8ym4mao13ao) (pib:16)
[17 Jun 2010 12:01] Bugs System
Pushed into 5.1.47-ndb-7.0.16 (revid:martin.skold@mysql.com-20100617114014-bva0dy24yyd67697) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[17 Jun 2010 12:43] Bugs System
Pushed into 5.1.47-ndb-6.2.19 (revid:martin.skold@mysql.com-20100617115448-idrbic6gbki37h1c) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[17 Jun 2010 13:29] Bugs System
Pushed into 5.1.47-ndb-6.3.35 (revid:martin.skold@mysql.com-20100617114611-61aqbb52j752y116) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)