Index: commonmod.scm ================================================================== --- commonmod.scm +++ commonmod.scm @@ -383,11 +383,11 @@ *db-sync-in-progress* *db-multi-sync-mutex* *task-db* *db-access-allowed* *db-access-mutex* -*db-transaction-mutex* +;; *db-transaction-mutex* *db-cache-path* *db-with-db-mutex* *db-api-call-time* *didsomething* *no-sync-db* @@ -962,16 +962,17 @@ (define *db-last-access* (current-seconds)) ;; last db access, used in server (define *db-write-access* #t) ;; db sync (define *db-last-sync* 0) ;; last time the sync to megatest.db happened (define *db-sync-in-progress* #f) ;; if there is a sync in progress do not try to start another +;; multi-sync mutex used in both dbmod and launchmod (define *db-multi-sync-mutex* (make-mutex)) ;; protect access to *db-sync-in-progress*, *db-last-sync* ;; task db (define *task-db* #f) ;; (vector db path-to-db) (define *db-access-allowed* #t) ;; flag to allow access (define *db-access-mutex* (make-mutex)) -(define *db-transaction-mutex* (make-mutex)) +;; (define *db-transaction-mutex* (make-mutex)) (define *db-cache-path* #f) (define *db-with-db-mutex* (make-mutex)) (define *db-api-call-time* (make-hash-table)) ;; hash of command => (list of times) ;; no sync db (define *no-sync-db* #f) Index: dbmod.scm ================================================================== --- dbmod.scm +++ dbmod.scm @@ -345,11 +345,13 @@ (inmem #f) (last-sync 0) (last-write (current-seconds)) (run-id #f) (fname #f)) - + +(define *db-transaction-mutex* (make-mutex)) + ;; Returns the dbdat for a particular dbfile inside the area ;; (define (dbr:dbstruct-get-dbdat dbstruct dbfile) (hash-table-ref/default (dbr:dbstruct-dbdats dbstruct) dbfile #f)) @@ -526,17 +528,20 @@ res)) ;; called before db is open? ;; (define (db:get-iam-server-lock dbh dbfname host port) - (sqlite3:with-transaction - dbh - (lambda () - (let* ((locker (db:get-locker dbh dbfname))) - (if locker - locker - (db:take-lock dbh dbfname port)))))) + (mutex-lock! *db-transaction-mutex*) + (let ((res (sqlite3:with-transaction + dbh + (lambda () + (let* ((locker (db:get-locker dbh dbfname))) + (if locker + locker + (db:take-lock dbh dbfname port))))))) + (mutex-unlock! *db-transaction-mutex*) + res)) ;; (exn sqlite3) (define (db:get-locker dbh dbfname) (condition-case (sqlite3:first-row dbh "SELECT owner_pid,owner_host,owner_port,event_time FROM locks WHERE lockname=?;" dbfname) @@ -1009,10 +1014,11 @@ ;; (db:delay-if-busy targdb) ;; NO WAITING (if (member "last_update" field-names) (debug:print-info 3 *default-log-port* "is-trigger-dropped: " is-trigger-dropped)) (for-each (lambda (fromdat-lst) + (mutex-lock! *db-transaction-mutex*) (sqlite3:with-transaction db (lambda () (for-each ;; (lambda (fromrow) @@ -1029,11 +1035,12 @@ (if (not same) (begin (debug:print 0 *default-log-port* "applying data "fromrow"to table "tablename", numrecs="numrecs) (apply sqlite3:execute stmth (vector->list fromrow)) (hash-table-set! numrecs tablename (+ 1 (hash-table-ref/default numrecs tablename 0))))))) - fromdat-lst)))) + fromdat-lst))) + (mutex-unlock! *db-transaction-mutex*)) fromdats) (sqlite3:finalize! stmth) (if (member "last_update" field-names) (db:create-trigger db tablename))))) @@ -1515,10 +1522,11 @@ (keys (keys:config-get-fields configdat)) (havekeys (> (length keys) 0)) (keystr (keys->keystr keys)) (fieldstr (keys:make-key/field-string configdat)) #;(db (dbr:dbdat-db dbdat))) + (mutex-lock! *db-transaction-mutex*) (for-each (lambda (key) (let ((keyn key)) (if (member (string-downcase keyn) (list "runname" "state" "status" "owner" "event_time" "comment" "fail_count" "pass_count" "contour")) @@ -1641,10 +1649,11 @@ CONSTRAINT metadat_constraint UNIQUE (var));") (sqlite3:execute db "CREATE TABLE IF NOT EXISTS access_log (id INTEGER PRIMARY KEY, user TEXT, accessed TIMESTAMP, args TEXT);") ;; Must do this *after* running patch db !! No more. ;; cannot use db:set-var since it will deadlock, hardwire the code here (sqlite3:execute db "INSERT OR REPLACE INTO metadat (var,val) VALUES (?,?);" "MEGATEST_VERSION" (common:version-signature)) + (mutex-unlock! *db-transaction-mutex*) (debug:print-info 11 *default-log-port* "db:initialize END") ;; )))) ;;====================================================================== ;; R U N S P E C I F I C D B ;;====================================================================== @@ -2771,11 +2780,11 @@ ;; Update run_stats for given run_id ;; input data is a list (state status count) ;; (define (db:update-run-stats dbstruct run-id stats) - ;; (mutex-lock! *db-transaction-mutex*) + (mutex-lock! *db-transaction-mutex*) (db:with-db dbstruct run-id #f @@ -2793,11 +2802,11 @@ (sqlite3:execute stmt1 run-id (car dat)(cadr dat)) (apply sqlite3:execute stmt2 run-id dat)) stats))))) (sqlite3:finalize! stmt1) (sqlite3:finalize! stmt2) - ;; (mutex-unlock! *db-transaction-mutex*) + (mutex-unlock! *db-transaction-mutex*) res)))) (define (db:get-main-run-stats dbstruct run-id) (db:with-db dbstruct