]> xenbits.xensource.com Git - people/liuw/osstest.git/commitdiff
Executive DB: Reduce strength of DB locks
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 11 Dec 2015 16:13:00 +0000 (16:13 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 11 Dec 2015 16:53:49 +0000 (16:53 +0000)
The purpose of these locks is partly to prevent transactions being
aborted (which I'm not sure the existing code would in practice cope
with, although this is a bug) and also to avoid bugs due to the fact
that
  SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
does not mean that the transactions are necessarily serialisable!
  http://www.postgresql.org/docs/8.3/static/transaction-iso.html

In SQL in general it is possible for read-only transactions to
conflict with writing transactions.

However, in PostgreSQL this is not a problem because Postgres uses
multi-version concurrency control: it retains the old version of the
data while the read transaction is open:
  http://www.postgresql.org/docs/8.3/static/transaction-iso.html

So a read transaction cannot cause a write transaction to abort, nor
vice versa.  So there is no need to have the database explicit table
locks prevent concurrent read access.

Preventing concurrent read access means that simple and urgent updates
can be unnecessarily delayed by long-running reader transactions in
the history reporters and archaeologists.

So, reduce the lock mode from ACCESS EXCLUSIVE to ACCESS.  This still
conflicts with all kinds of updates and prospective updates, but no
longer with SELECT:
  http://www.postgresql.org/docs/8.3/static/explicit-locking.html

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
v2: Fix grammar and typo in commit message.

Osstest/JobDB/Executive.pm
tcl/JobDB-Executive.tcl

index 69cb2763daa9b0b5c827f586870fa52dcf69e3ea..124e7c000e72c6303532384ae4dd565ed2e25423 100644 (file)
@@ -43,7 +43,7 @@ sub begin_work ($$$) { #method
     
     return if $ENV{'OSSTEST_DEBUG_NOSQLLOCK'};
     foreach my $tab (@$tables) {
-        $dbh->do("LOCK TABLE $tab IN ACCESS EXCLUSIVE MODE");
+        $dbh->do("LOCK TABLE $tab IN EXCLUSIVE MODE");
     }
 }
 
index f37bbaf06eeec3ba7fde65be8fd33473ec26a7ef..a3dbb9e9fbbcbd8c86093e722859eb7f29ba0946 100644 (file)
@@ -133,7 +133,7 @@ proc lock-tables {tables} {
     # must be inside transaction
     foreach tab $tables {
         db-execute "
-               LOCK TABLE $tab IN ACCESS EXCLUSIVE MODE
+               LOCK TABLE $tab IN EXCLUSIVE MODE
         "
     }
 }