Everything needs to be in a proper transaction, with retries.
Replace the one call site which does an ad hoc BEGIN/COMMIT with a
call to transaction. The body here is already idempotent, so making
it be a loop body is fine.
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
proc spawn-step-begin {flight job ts stepnovar} {
upvar 1 $stepnovar stepno
- with-db {
- db-execute BEGIN
- db-execute "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"
+ transaction {} {
if {[catch {
lock-tables flights
db-execute-array stepinfo "
[pg_quote $ts], 'running',
'STARTING')
"
- db-execute COMMIT
} emsg]} {
global errorInfo errorCode
set ei $errorInfo
}
}
-proc with-db {script} {
- global errorInfo errorCode
- set rc [catch {
- db-open
- uplevel 1 $script
- } result]
- set ei $errorInfo
- set ec $errorCode
- if {$rc} {
- catch { db-close }
- } else {
- db-close
- }
- return -code $rc -errorinfo $ei -errorcode $ec $result
-}
-
proc transaction {tables script {autoreconnect 0}} {
global errorInfo errorCode
variable dbopen