[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [OSSTEST PATCH 3/4] Database locking: Tcl: Cover LOCK TABLEs with catch

Previously we would retry only the body, but not LOCK TABLEs.

We got away with it before because of the heavyweight locking of even
long-running read-only transactions, but now the LOCK TABLEs can fail
(at least in a mixed-version system, and perhaps even in a system with
only new code).

Additionally, if one of the LOCK TABLEs fails, the code's use of the
db handle becomes stuck because of the failed transaction: the error
is caught by the daemon's main loop error handler, but the db handle
is not subjected to ROLLBACK and all future attempts to use it will

So: move the LOCK TABLEs (and the SET TRANSACTION) into the catch, so
that deadlocks in LOCK TABLEs are retried (after ROLLBACK).

The COMMIT remains outside the eval but this should be unaffected by
DB deadlocks if the LOCK TABLEs are right.

Note that this code does not attempt to distinguish DB deadlock errors
from other errors.  Arguably this is quite wrong.  Fixing it to
distinguish deadlocks is awkward because pg_execute does not leave the
error information anywhere it can be found.  Contrary to what the
documentation seems to imply, it does not set errorCode (!)

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
 tcl/JobDB-Executive.tcl |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tcl/JobDB-Executive.tcl b/tcl/JobDB-Executive.tcl
index a3dbb9e..8e45ea7 100644
--- a/tcl/JobDB-Executive.tcl
+++ b/tcl/JobDB-Executive.tcl
@@ -228,9 +228,11 @@ proc transaction {tables script} {
     while 1 {
         set ol {}
         db-execute BEGIN
-        lock-tables $tables
-       set rc [catch { uplevel 1 $script } result]
+       set rc [catch {
+           lock-tables $tables
+           uplevel 1 $script
+       } result]
        if {!$rc} {
            if {[catch {
                db-execute COMMIT

Xen-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.