<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Pitfalls of converting to InnoDB</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:23:57 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Andrew McCombe</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-326412</link>
		<dc:creator>Andrew McCombe</dc:creator>
		<pubDate>Fri, 11 Jul 2008 11:47:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-326412</guid>
		<description>Hi.

MySQL Version:	5.0.54-enterprise-gpl-log MySQL Enterprise Server (GPL)

I have just had an issue with Innodb and transactions where i would get a &#039;[1205] Lock wait timeout exceeded; try restarting transaction&#039;.

To resolve it I had to mysql dump the offending table, add an index to it and then re-import it.</description>
		<content:encoded><![CDATA[<p>Hi.</p>
<p>MySQL Version:	5.0.54-enterprise-gpl-log MySQL Enterprise Server (GPL)</p>
<p>I have just had an issue with Innodb and transactions where i would get a &#8216;[1205] Lock wait timeout exceeded; try restarting transaction&#8217;.</p>
<p>To resolve it I had to mysql dump the offending table, add an index to it and then re-import it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Marlowe</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-221506</link>
		<dc:creator>Scott Marlowe</dc:creator>
		<pubDate>Fri, 21 Dec 2007 06:18:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-221506</guid>
		<description>Glenn, are you saying PHP itself crashes, or your php script has a bug and it gets an error and dies?  Those are two very different things.

If php crashes, it kills the parent apache child along with it, and there&#039;s no process to close the socket to the database.  In this case your server&#039;s tcp_keepalive timeouts will have to come along and harvest the connection for you, and the default timeout for tcp_keepalive is 2 hours...  lowering it to 5 minutes or something might help.

But the real issue is why is php itself crashing.  Generally speaking, php shouldn&#039;t crash, and if it is, you might want to look at bug reports and try upgrading to see if you can get it to stop crashing.

OTOH, it could be the persistant connection thing if php itself isn&#039;t crashing and it&#039;s just your script hanging.</description>
		<content:encoded><![CDATA[<p>Glenn, are you saying PHP itself crashes, or your php script has a bug and it gets an error and dies?  Those are two very different things.</p>
<p>If php crashes, it kills the parent apache child along with it, and there&#8217;s no process to close the socket to the database.  In this case your server&#8217;s tcp_keepalive timeouts will have to come along and harvest the connection for you, and the default timeout for tcp_keepalive is 2 hours&#8230;  lowering it to 5 minutes or something might help.</p>
<p>But the real issue is why is php itself crashing.  Generally speaking, php shouldn&#8217;t crash, and if it is, you might want to look at bug reports and try upgrading to see if you can get it to stop crashing.</p>
<p>OTOH, it could be the persistant connection thing if php itself isn&#8217;t crashing and it&#8217;s just your script hanging.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ed</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-97044</link>
		<dc:creator>Ed</dc:creator>
		<pubDate>Wed, 28 Mar 2007 18:55:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-97044</guid>
		<description>ER_LOCK_WAIT_TIMEOUT will also pop up with transactions that are open for long periods of time.  For instance, assume 2 clients (A, B) and the following sequence of statements.

A - create table ed (id int unsigned, name varchar(10)) engine=innodb;
A - begin;
A - insert into ed set id = 1, name = &#039;one&#039;;
B - begin;
B - update ed set name = &#039;two&#039; where id = 1;

B will hang until A commits/rollsback.  If enough time goes by, you get ER_LOCK_WAIT_TIMEOUT.  

Moral: keep transactions as short as possible.


ER_LOCK_DEADLOCK can be exacerbated by triggers since triggers can increase the length of the implicit transaction of an insert/update as well as the index locks (especially foreign keys) acquired.  Also, don&#039;t forget that summary triggers like &quot;update parent set column = column + 1 where primary_key = ##&quot; lock parent&#039;s row until the original statement is completed.  

Moral: make update/insert statements (including triggers) as quick as possible</description>
		<content:encoded><![CDATA[<p>ER_LOCK_WAIT_TIMEOUT will also pop up with transactions that are open for long periods of time.  For instance, assume 2 clients (A, B) and the following sequence of statements.</p>
<p>A &#8211; create table ed (id int unsigned, name varchar(10)) engine=innodb;<br />
A &#8211; begin;<br />
A &#8211; insert into ed set id = 1, name = &#8216;one&#8217;;<br />
B &#8211; begin;<br />
B &#8211; update ed set name = &#8216;two&#8217; where id = 1;</p>
<p>B will hang until A commits/rollsback.  If enough time goes by, you get ER_LOCK_WAIT_TIMEOUT.  </p>
<p>Moral: keep transactions as short as possible.</p>
<p>ER_LOCK_DEADLOCK can be exacerbated by triggers since triggers can increase the length of the implicit transaction of an insert/update as well as the index locks (especially foreign keys) acquired.  Also, don&#8217;t forget that summary triggers like &#8220;update parent set column = column + 1 where primary_key = ##&#8221; lock parent&#8217;s row until the original statement is completed.  </p>
<p>Moral: make update/insert statements (including triggers) as quick as possible</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-93814</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Sat, 24 Mar 2007 09:37:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-93814</guid>
		<description>Glen, could it be that you are using persistant mysql connections? If so, mysql probably doesn&#039;t know your php code has bombed out, all it knows is the apache child is still connected, so maybe it&#039;s only choice is to wait and see if the client/apache completes the transaction</description>
		<content:encoded><![CDATA[<p>Glen, could it be that you are using persistant mysql connections? If so, mysql probably doesn&#8217;t know your php code has bombed out, all it knows is the apache child is still connected, so maybe it&#8217;s only choice is to wait and see if the client/apache completes the transaction</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vadim</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-74814</link>
		<dc:creator>Vadim</dc:creator>
		<pubDate>Thu, 08 Mar 2007 21:34:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-74814</guid>
		<description>Glen,

Yes, that is really strange.

Also I agree that 1205 for web site should be handled in different way, I showed part of code for batch-process.</description>
		<content:encoded><![CDATA[<p>Glen,</p>
<p>Yes, that is really strange.</p>
<p>Also I agree that 1205 for web site should be handled in different way, I showed part of code for batch-process.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glen</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-74062</link>
		<dc:creator>Glen</dc:creator>
		<pubDate>Thu, 08 Mar 2007 08:48:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-74062</guid>
		<description>I stumbled across this website in search of a basic problem I&#039;ve found.  I&#039;m using PHP 5.1.6, MySQL 5.0.24a default installs from Ubuntu 6.10, so pretty recent + standard.

I&#039;m using the PHP mysqli API and doing a basic insert into an InnoDB table.  My database class starts a transaction with a &quot;$mysqli-&gt;autocommit(false)&quot;, then executes an insert SQL statement, and completes with a &quot;$mysqli-&gt;commit()&quot;.  It works fine........

...... until PHP bombs mid-way due to a coding bug.  So the insert happens, but the script dies doing some other stuff before the commit() occurs.  I thought the database would rollback - but instead it remains locked.  Another PHP script attempting to insert takes 50 seconds to time-out with a &quot;1205 - Lock wait timeout exceeded; try restarting transaction&quot;.  The 1205 error won&#039;t go away until I restart Apache.  For whatever reason, the resources are not released until the process is killed.

I found that an &#039;exit&#039;, instead of a PHP code bug, will not cause a problem.  So there is an auto-rollback mechanism in place - it just fails miserably when PHP dies unexpectantly.  Having to restarting apache is a pretty drastic measure to overcome a code bug.

To avoid this, I use &quot;register_shutdown_function()&quot; when I start a transaction, and set a flag to indicate a transaction is in process (cause there is no unregister_shutdown_function()).  See below.  So the __shutdown_check() routine (I think it needs to be public) is called when the script bombs - which is able to invoke the rollback().  This seems to work fine.


  public function begin_transaction()
  {
    $ret = self::$mysqli-&gt;autocommit(false);
    $this-&gt;transaction_in_progress = true;
    register_shutdown_function(array($this, &quot;__shutdown_check&quot;));
  }

  public function __shutdown_check()
  {
    if ($this-&gt;transaction_in_progress)
    {
      $this-&gt;rollback();
    }
  }

  public function commit()
  {
    $ret = self::$mysqli-&gt;commit();
    $this-&gt;transaction_in_progress = false;
  }

  public function rollback()
  {
    $ret = self::$mysqli-&gt;rollback();
    $this-&gt;transaction_in_progress = false;
  }


I notice your code above has a loop on the 1205 (and 1213) error.  In my case, each attempt take 50 seconds to time-out - I&#039;m assuming that&#039;s standard (I haven&#039;t tuned anything).  So your script could loop for 5000 seconds.  Perhaps a better solution is to use timestamps and max out based on duration, rather than a fixed loop?</description>
		<content:encoded><![CDATA[<p>I stumbled across this website in search of a basic problem I&#8217;ve found.  I&#8217;m using PHP 5.1.6, MySQL 5.0.24a default installs from Ubuntu 6.10, so pretty recent + standard.</p>
<p>I&#8217;m using the PHP mysqli API and doing a basic insert into an InnoDB table.  My database class starts a transaction with a &#8220;$mysqli-&gt;autocommit(false)&#8221;, then executes an insert SQL statement, and completes with a &#8220;$mysqli-&gt;commit()&#8221;.  It works fine&#8230;&#8230;..</p>
<p>&#8230;&#8230; until PHP bombs mid-way due to a coding bug.  So the insert happens, but the script dies doing some other stuff before the commit() occurs.  I thought the database would rollback &#8211; but instead it remains locked.  Another PHP script attempting to insert takes 50 seconds to time-out with a &#8220;1205 &#8211; Lock wait timeout exceeded; try restarting transaction&#8221;.  The 1205 error won&#8217;t go away until I restart Apache.  For whatever reason, the resources are not released until the process is killed.</p>
<p>I found that an &#8216;exit&#8217;, instead of a PHP code bug, will not cause a problem.  So there is an auto-rollback mechanism in place &#8211; it just fails miserably when PHP dies unexpectantly.  Having to restarting apache is a pretty drastic measure to overcome a code bug.</p>
<p>To avoid this, I use &#8220;register_shutdown_function()&#8221; when I start a transaction, and set a flag to indicate a transaction is in process (cause there is no unregister_shutdown_function()).  See below.  So the __shutdown_check() routine (I think it needs to be public) is called when the script bombs &#8211; which is able to invoke the rollback().  This seems to work fine.</p>
<p>  public function begin_transaction()<br />
  {<br />
    $ret = self::$mysqli-&gt;autocommit(false);<br />
    $this-&gt;transaction_in_progress = true;<br />
    register_shutdown_function(array($this, &#8220;__shutdown_check&#8221;));<br />
  }</p>
<p>  public function __shutdown_check()<br />
  {<br />
    if ($this-&gt;transaction_in_progress)<br />
    {<br />
      $this-&gt;rollback();<br />
    }<br />
  }</p>
<p>  public function commit()<br />
  {<br />
    $ret = self::$mysqli-&gt;commit();<br />
    $this-&gt;transaction_in_progress = false;<br />
  }</p>
<p>  public function rollback()<br />
  {<br />
    $ret = self::$mysqli-&gt;rollback();<br />
    $this-&gt;transaction_in_progress = false;<br />
  }</p>
<p>I notice your code above has a loop on the 1205 (and 1213) error.  In my case, each attempt take 50 seconds to time-out &#8211; I&#8217;m assuming that&#8217;s standard (I haven&#8217;t tuned anything).  So your script could loop for 5000 seconds.  Perhaps a better solution is to use timestamps and max out based on duration, rather than a fixed loop?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-61799</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Mon, 26 Feb 2007 21:22:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-61799</guid>
		<description>No you can&#039;t say so. 

even of you do not lock anything manually there could be statements which come into deadlock, consider for example 2 update statements updating the table going by index one going in forward order and other in reverse order.  These will deadlock.</description>
		<content:encoded><![CDATA[<p>No you can&#8217;t say so. </p>
<p>even of you do not lock anything manually there could be statements which come into deadlock, consider for example 2 update statements updating the table going by index one going in forward order and other in reverse order.  These will deadlock.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raven</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-61791</link>
		<dc:creator>Raven</dc:creator>
		<pubDate>Mon, 26 Feb 2007 21:18:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-61791</guid>
		<description>Thanks for the clarification, Peter.

Is it fair to say that a deadlock can&#039;t happen if you are exclusively using InnoDB and not manually locking things?  I&#039;d like to believe that InnoDB does locking internally in a consistent and safe manner...</description>
		<content:encoded><![CDATA[<p>Thanks for the clarification, Peter.</p>
<p>Is it fair to say that a deadlock can&#8217;t happen if you are exclusively using InnoDB and not manually locking things?  I&#8217;d like to believe that InnoDB does locking internally in a consistent and safe manner&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-61776</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Mon, 26 Feb 2007 21:02:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-61776</guid>
		<description>Raven, 

Lock wait timeout can happen in two cases - in case of cross storage engine lock wait (in which case it well can be deadlock) or most commonly in case of too long lock which can be high load or simply some long running queries.

deadlocks however can handle even with light load - it is more question of probability.</description>
		<content:encoded><![CDATA[<p>Raven, </p>
<p>Lock wait timeout can happen in two cases &#8211; in case of cross storage engine lock wait (in which case it well can be deadlock) or most commonly in case of too long lock which can be high load or simply some long running queries.</p>
<p>deadlocks however can handle even with light load &#8211; it is more question of probability.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raven</title>
		<link>http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/comment-page-1/#comment-61712</link>
		<dc:creator>Raven</dc:creator>
		<pubDate>Mon, 26 Feb 2007 19:30:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/02/25/pitfalls-of-converting-to-innodb/#comment-61712</guid>
		<description>These lock timeouts imply that you have some long running queries (or that your server is overloaded), correct?

I suspect that for most applications you would be better off looking for the source of the long running lock rather than wrapping all your queries in a retry script (which strikes me as being problematic in the context of transactions).

Still, thanks for the post - I wasn&#039;t aware of this MyISAM-&gt;InnoDB gotcha.</description>
		<content:encoded><![CDATA[<p>These lock timeouts imply that you have some long running queries (or that your server is overloaded), correct?</p>
<p>I suspect that for most applications you would be better off looking for the source of the long running lock rather than wrapping all your queries in a retry script (which strikes me as being problematic in the context of transactions).</p>
<p>Still, thanks for the post &#8211; I wasn&#8217;t aware of this MyISAM-&gt;InnoDB gotcha.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
