<?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: Explicit Table Locking with PostgreSQL and Django</title>
	<atom:link href="http://www.caktusgroup.com/blog/2009/05/26/explicit-table-locking-with-postgresql-and-django/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.caktusgroup.com/blog/2009/05/26/explicit-table-locking-with-postgresql-and-django/</link>
	<description>Blog &#124; Django Web Development &#124; Raleigh Durham Chapel Hill &#124; Caktus Consulting Group</description>
	<pubDate>Thu, 09 Sep 2010 15:21:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Angelo Dell'Aera</title>
		<link>http://www.caktusgroup.com/blog/2009/05/26/explicit-table-locking-with-postgresql-and-django/#comment-464</link>
		<dc:creator>Angelo Dell'Aera</dc:creator>
		<pubDate>Mon, 16 Nov 2009 11:11:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=218#comment-464</guid>
		<description>Nice code. I was thinking about making it really generic. Think about this idea. You import settings.py thus being able to read DATABASE_ENGINE. Then you define LOCK_MODES this way 

LOCK_MODES = {'postgresql_psycopg2' : POSTGRESQL_LOCK_MODES,
'mysql' : MYSQL_LOCK_MODES, 
...}

(with POSTGRESQL_LOCK_MODES being the same tuple as your LOCK_MODES)

In wrapper then

        def wrapper(*args, **kwargs):
            if DATABASE_ENGINE not in LOCK_MODES.keys():
                 raise ...
            if lock not in LOCK_MODES[DATABASE_ENGINE]:
                raise ...
            if DATABASE_ENGINE == "postgresql_psycopg2":
                postgresql_psycopg2_lock_table(table, lock)
            ...
            return view_func(*args, **kwargs)</description>
		<content:encoded><![CDATA[<p>Nice code. I was thinking about making it really generic. Think about this idea. You import settings.py thus being able to read DATABASE_ENGINE. Then you define LOCK_MODES this way </p>
<p>LOCK_MODES = {&#8217;postgresql_psycopg2&#8242; : POSTGRESQL_LOCK_MODES,<br />
&#8216;mysql&#8217; : MYSQL_LOCK_MODES,<br />
&#8230;}</p>
<p>(with POSTGRESQL_LOCK_MODES being the same tuple as your LOCK_MODES)</p>
<p>In wrapper then</p>
<p>        def wrapper(*args, **kwargs):<br />
            if DATABASE_ENGINE not in LOCK_MODES.keys():<br />
                 raise &#8230;<br />
            if lock not in LOCK_MODES[DATABASE_ENGINE]:<br />
                raise &#8230;<br />
            if DATABASE_ENGINE == &#8220;postgresql_psycopg2&#8243;:<br />
                postgresql_psycopg2_lock_table(table, lock)<br />
            &#8230;<br />
            return view_func(*args, **kwargs)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tobias</title>
		<link>http://www.caktusgroup.com/blog/2009/05/26/explicit-table-locking-with-postgresql-and-django/#comment-403</link>
		<dc:creator>tobias</dc:creator>
		<pubDate>Tue, 29 Sep 2009 22:54:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=218#comment-403</guid>
		<description>The PostgreSQL docs say "locks are always released at transaction end", which I assume includes ROLLBACKs and connection closures.  Try creating a test case for this one and let us know what you find!</description>
		<content:encoded><![CDATA[<p>The PostgreSQL docs say &#8220;locks are always released at transaction end&#8221;, which I assume includes ROLLBACKs and connection closures.  Try creating a test case for this one and let us know what you find!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe Joe</title>
		<link>http://www.caktusgroup.com/blog/2009/05/26/explicit-table-locking-with-postgresql-and-django/#comment-397</link>
		<dc:creator>Joe Joe</dc:creator>
		<pubDate>Tue, 29 Sep 2009 00:38:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=218#comment-397</guid>
		<description>Shouldn't you add a call to transaction.set_dirty() after the cursor.execute() call? What if the transaction exists entirely of SELECTs(which won't internally call set_dirty)? Will the lock still be properly released?

http://docs.djangoproject.com/en/dev/topics/db/sql/#id1</description>
		<content:encoded><![CDATA[<p>Shouldn&#8217;t you add a call to transaction.set_dirty() after the cursor.execute() call? What if the transaction exists entirely of SELECTs(which won&#8217;t internally call set_dirty)? Will the lock still be properly released?</p>
<p><a href="http://docs.djangoproject.com/en/dev/topics/db/sql/#id1" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/db/sql/#id1</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham Fawcett</title>
		<link>http://www.caktusgroup.com/blog/2009/05/26/explicit-table-locking-with-postgresql-and-django/#comment-139</link>
		<dc:creator>Graham Fawcett</dc:creator>
		<pubDate>Fri, 29 May 2009 17:57:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=218#comment-139</guid>
		<description>Excellent recipe! Thank you.

One suggestion: consider changing the signature to require_lock(lock, *models) and execute the LOCK TABLE commands once for each of the models given. This would still work for a single-table lock, but would also make it easy to specify multiple tables in a trickier situation. (It would also help to enforce locking-order by documenting it in one place, which might help to avoid deadlocks.)</description>
		<content:encoded><![CDATA[<p>Excellent recipe! Thank you.</p>
<p>One suggestion: consider changing the signature to require_lock(lock, *models) and execute the LOCK TABLE commands once for each of the models given. This would still work for a single-table lock, but would also make it easy to specify multiple tables in a trickier situation. (It would also help to enforce locking-order by documenting it in one place, which might help to avoid deadlocks.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chirayu Patel</title>
		<link>http://www.caktusgroup.com/blog/2009/05/26/explicit-table-locking-with-postgresql-and-django/#comment-131</link>
		<dc:creator>Chirayu Patel</dc:creator>
		<pubDate>Thu, 28 May 2009 06:52:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=218#comment-131</guid>
		<description>A very useful function. In a similar piece of code, I have also added support for timeout (implemented using time.sleep(random.randint (1, timeout)) and NOWAIT). It helps in identifying lockup problems both in testing and production.</description>
		<content:encoded><![CDATA[<p>A very useful function. In a similar piece of code, I have also added support for timeout (implemented using time.sleep(random.randint (1, timeout)) and NOWAIT). It helps in identifying lockup problems both in testing and production.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Caktus Blog &#187; Blog Archive &#187; Testing Django Views for Concurrency Issues</title>
		<link>http://www.caktusgroup.com/blog/2009/05/26/explicit-table-locking-with-postgresql-and-django/#comment-117</link>
		<dc:creator>Caktus Blog &#187; Blog Archive &#187; Testing Django Views for Concurrency Issues</dc:creator>
		<pubDate>Tue, 26 May 2009 20:59:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=218#comment-117</guid>
		<description>[...] Blog               &#171; Explicit Table Locking with PostgreSQL and Django [...]</description>
		<content:encoded><![CDATA[<p>[...] Blog               &laquo; Explicit Table Locking with PostgreSQL and Django [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
