<?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"
	>
<channel>
	<title>Comments on: Mysql::Error: Deadlock found when trying to get lock</title>
	<atom:link href="http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/</link>
	<description>Things that have more than zero impact (on my live)</description>
	<pubDate>Sun, 05 Feb 2012 00:02:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Henryk</title>
		<link>http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/#comment-10630</link>
		<dc:creator>Henryk</dc:creator>
		<pubDate>Wed, 24 Nov 2010 16:35:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/#comment-10630</guid>
		<description>@Mina

Thank you for that pointer. It is good to see that postgress improved the granularity of their locks and algorithms making deadlocks less likely. But I'm sure that it is still possible to cause deadlocks in postgress. So good code should still be able to handle a deadlock in the database and it should also deal with the side-effects in the rails code.</description>
		<content:encoded><![CDATA[<p>@Mina</p>
<p>Thank you for that pointer. It is good to see that postgress improved the granularity of their locks and algorithms making deadlocks less likely. But I&#039;m sure that it is still possible to cause deadlocks in postgress. So good code should still be able to handle a deadlock in the database and it should also deal with the side-effects in the rails code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mina</title>
		<link>http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/#comment-10612</link>
		<dc:creator>Mina</dc:creator>
		<pubDate>Tue, 23 Nov 2010 14:09:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/#comment-10612</guid>
		<description>I've documented a similar problem in the PostgreSQL database.  You can read my analysis here: http://mina.naguib.ca/blog/2010/11/22/postgresql-foreign-key-deadlocks.html

The good news is that, in PG's case, it's being fixed in the database itself.</description>
		<content:encoded><![CDATA[<p>I&#039;ve documented a similar problem in the PostgreSQL database.  You can read my analysis here: <a href="http://mina.naguib.ca/blog/2010/11/22/postgresql-foreign-key-deadlocks.html" rel="nofollow">http://mina.naguib.ca/blog/2010/11/22/postgresql-foreign-key-deadlocks.html</a></p>
<p>The good news is that, in PG&#039;s case, it&#039;s being fixed in the database itself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henryk</title>
		<link>http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/#comment-3876</link>
		<dc:creator>Henryk</dc:creator>
		<pubDate>Fri, 24 Jul 2009 21:18:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/#comment-3876</guid>
		<description>@Richie

I'm not sure, it's enough just to rerun the sql statement. You also need to continue at the right place in the try-block.
I think the problem boils down to: Deadlocks can be a serious issue that is not easy to deal with. Since rails is built with the assumption of &lt;a href="http://web.archive.org/web/20070222020918/www.loudthinking.com/arc/000516.html" rel="nofollow"&gt;a singler layer of cleverness&lt;/a&gt; you have to add rollback rails code to your except block as well.

&lt;code&gt;&lt;pre&gt;
retries = 0
begin
  MyModel.transaction do
     #do your stuff
  end
rescue ActiveRecord::StatmentInvalid =&gt; e
  # raise if e is not a deadlock
  # ROLLBACK your other rails variables, eg. counters.
  retries += 1
  raise if retries &gt; 3
  retry
end
&lt;/pre&gt;&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>@Richie</p>
<p>I&#039;m not sure, it&#039;s enough just to rerun the sql statement. You also need to continue at the right place in the try-block.<br />
I think the problem boils down to: Deadlocks can be a serious issue that is not easy to deal with. Since rails is built with the assumption of <a href="http://web.archive.org/web/20070222020918/www.loudthinking.com/arc/000516.html" rel="nofollow">a singler layer of cleverness</a> you have to add rollback rails code to your except block as well.</p>
<p><code>
<pre>
retries = 0
begin
  MyModel.transaction do
     #do your stuff
  end
rescue ActiveRecord::StatmentInvalid => e
  # raise if e is not a deadlock
  # ROLLBACK your other rails variables, eg. counters.
  retries += 1
  raise if retries > 3
  retry
end
</pre>
<p></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richie Vos</title>
		<link>http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/#comment-3874</link>
		<dc:creator>Richie Vos</dc:creator>
		<pubDate>Fri, 24 Jul 2009 17:14:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.littleimpact.de/index.php/2008/08/03/mysqlerror-deadlock-found-when-trying-to-get-lock/#comment-3874</guid>
		<description>Glad to see someone else mentioning the apparent unsafeness of that deadlock retry plugin. We put it in our project for awhile, then thought better of it after thinking the exact same thing you are.

It would be nice if there was a plugin that would instead just re-run the sql statements again instead of the code itself.</description>
		<content:encoded><![CDATA[<p>Glad to see someone else mentioning the apparent unsafeness of that deadlock retry plugin. We put it in our project for awhile, then thought better of it after thinking the exact same thing you are.</p>
<p>It would be nice if there was a plugin that would instead just re-run the sql statements again instead of the code itself.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

