Provide an `autoreconnect' argument which will automatically reconnect
to the db if the connection has been lost.  It will make only one
reconnection attempt.

No functional change yet because no call sites have been changed.

Signed-off-by: Ian Jackson <ian.jack...@eu.citrix.com>
---
 tcl/JobDB-Executive.tcl | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tcl/JobDB-Executive.tcl b/tcl/JobDB-Executive.tcl
index 535fbd7..0fc0a6d 100644
--- a/tcl/JobDB-Executive.tcl
+++ b/tcl/JobDB-Executive.tcl
@@ -303,7 +303,7 @@ proc step-set-status {flight job stepno st} {
     }
 }
 
-proc transaction {tables script} {
+proc transaction {tables script {autoreconnect 0}} {
     global errorInfo errorCode
     set retries 100
     while 1 {
@@ -332,6 +332,20 @@ proc transaction {tables script} {
                    after 500
                    continue
                }
+               {OSSTEST-PSQL * 08*} -
+               {OSSTEST-PSQL * 57*} -
+               {OSSTEST-PSQL-SSL-SYSCALL *} {
+                   # Class 08 — Connection Exception
+                   # Class 57 — Operator Intervention
+                   #    (includes various shutdowns)
+                   logputs stderr \
+ "db connection exception (autoreconnect=$autoreconnect): $result\n$ei\n$ec\n"
+                   if {$autoreconnect} {
+                       set autoreconnect 0; # try this only once
+                       db-reopen
+                       continue
+                   }
+               }
            }
            catch { db-ensure-closed }
        }
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

Reply via email to