Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -4017,43 +4017,43 @@ (begin ;; is there a rollup lock? If not, take it (sqlite3:with-transaction no-sync-db (lambda () - (handle-exceptions - exn - (debug:print 0 *default-log-port* "EXCEPTION: exn="exn) - (let* ((rollup-lock-time (db:no-sync-get/default no-sync-db rollup-lock-key #f)) - (waiting-lock-time (db:no-sync-get/default no-sync-db waiting-lock-key #f))) - (if rollup-lock-time ;; someone is doing a rollup - (if (not waiting-lock-time) ;; no one is waiting - (begin - (set! wait-flag #t) - (set! rollup-flag #t) - (db:no-sync-set no-sync-db waiting-lock-key (current-seconds)))) ;; we are going to wait - (begin - (set! rollup-flag #t) - (db:no-sync-set no-sync-db rollup-lock-key (current-seconds))))))) - (if wait-flag - (let loop ((count 100)) - (thread-sleep! 2) - (if (and (not (db:no-sync-get/default no-sync-db waiting-lock-key #f)) - (> count 0)) - (loop (+ count 1)) - (sqlite3:with-transaction - no-sync-db - (lambda () - (db:no-sync-set no-sync-db rollup-lock-key (current-seconds)) - (db:no-sync-del! no-sync-db waiting-lock-key))))))) + ;; (debug:print 0 *default-log-port* "EXCEPTION: exn="exn) + (let* ((rollup-lock-time (db:no-sync-get/default no-sync-db rollup-lock-key #f)) + (waiting-lock-time (db:no-sync-get/default no-sync-db waiting-lock-key #f))) + (if rollup-lock-time ;; someone is doing a rollup + (if (not waiting-lock-time) ;; no one is waiting + (begin + (set! wait-flag #t) + (set! rollup-flag #t) + (db:no-sync-set no-sync-db waiting-lock-key (current-seconds)))) ;; we are going to wait + (begin + (set! rollup-flag #t) + (db:no-sync-set no-sync-db rollup-lock-key (current-seconds))))))) + (if wait-flag + (let loop ((count 10)) ;; about 20 seconds + (thread-sleep! 2) + (if (and (not (db:no-sync-get/default no-sync-db waiting-lock-key #f)) + (> count 0)) + (loop (+ count 1)) + (sqlite3:with-transaction + no-sync-db + (lambda () + (db:no-sync-set no-sync-db rollup-lock-key (current-seconds)) + (db:no-sync-del! no-sync-db waiting-lock-key)))))) ;; now the rollup (if rollup-flag ;; put this into a thread - (thread-start! (make-thread - (lambda () - (db:roll-up-test-state-status dbstruct run-id test-name state status) - (db:no-sync-del! no-sync-db rollup-flag)) - (conc "thread for run-id: " run-id " test-name: " test-name)))))))) - + (begin + ;; (thread-start! (make-thread + ;; (lambda () + (db:roll-up-test-state-status dbstruct run-id test-name state status) + (db:no-sync-del! no-sync-db rollup-lock-key)) + ;; (conc "thread for run-id: " run-id " test-name: " test-name)))))))) + ))))) + ;; I'd like to remove the need for item-path - it is logically not needed here ;; for now we pass in state and status - NOTE: There is a possible race if a test ;; is rapidly re-run while an earlier run is waiting to rollup. ;; (define (db:roll-up-test-state-status dbstruct run-id test-name state status) @@ -4071,11 +4071,13 @@ (lambda (db) ;; NB// Pass the db so it is part fo the transaction ;; item-path is used in get-all-state-status counts to exclude current state/status of THIS test ;; but with the state/status being set earlier this is not needed any longer (let* ((state-status-counts (db:get-all-state-status-counts-for-testname dbstruct run-id test-name)) - (state-statuses (db:roll-up-rules state-status-counts state status)) + (state-statuses (if (null? state-status-counts) + '() + (db:roll-up-rules state-status-counts state status))) (newstate (if (null? state-statuses) state (car state-statuses))) (newstatus (if (null? state-statuses) status @@ -4204,11 +4206,11 @@ (let* ((state-status-counts (db:get-all-state-status-counts-for-run dbstruct run-id)) (state-statuses (db:roll-up-rules state-status-counts #f #f )) (newstate (if (null? state-statuses) curr-state (car state-statuses))) - (newstatus (if (null? state-status) + (newstatus (if (null? state-statuses) curr-status (cadr state-statuses)))) (if (or (not (eq? newstate curr-state)) (not (eq? newstatus curr-status))) (db:set-run-state-status dbstruct run-id newstate newstatus ))))))) ;; (mutex-unlock! *db-transaction-mutex*)