@@ -27,13 +27,15 @@ (declare (uses mtargs)) (declare (uses mtmod)) (module dbmod ( - ;; for debug, can be commented out + ;; for debug, can be commented out in production dbmod:safely-open-db - + dbmod:with-db + + ;; used elsewhere, keep dbmod:db-to-db-sync db:test-get-event_time db:test-get-item-path db:test-get-testname @@ -297,24 +299,27 @@ ;; MOVE THIS CALL TO INSIDE THE sync-proc CALL (dbr:dbstruct-last-update-set! dbstruct curr-secs) ))) (assert (sqlite3:database? dbh) "FATAL: bad db handle in dbmod:with-db") (if use-mutex (mutex-lock! *db-with-db-mutex*)) - (let* ((res (let loop ((count 3)) + (let* ((res (let loop ((count 10)) (condition-case (apply proc dbdat dbh params) - (exn (busy) + (exn (sqlite3) ;; was 'busy', but never got hit (if (> count 0) (begin (debug:print-info 0 *default-log-port* "dbmod:with-db, database is busy, will try "count" more times.") (thread-sleep! 1) (loop (- count 1))) (begin - (debug:print-info 0 *default-log-port* "dbmod:with-db, database is busy, giving up.") + (debug:print-info 0 *default-log-port* "dbmod:with-db, database is busy, giving up. params: "params) (exit 1)))) + (exn (locked) + (dbfile:print-err exn "ERROR: dbmod:with-db: database locked for run-id "run-id", params "params", message: " + ((condition-property-accessor 'exn 'message) exn))) (exn () - (dbfile:print-err exn "ERROR: dbmod:with-db: Unknown error with database for run-id "run-id", message: " + (dbfile:print-err exn "ERROR: dbmod:with-db: Unknown error with database for run-id "run-id", params "params", message: " ((condition-property-accessor 'exn 'message) exn)) (exit 2)))))) (if use-mutex (mutex-unlock! *db-with-db-mutex*)) res))) @@ -354,10 +359,13 @@ (else (debug:print 0 *default-log-port* "Unknown dbfile:cache-method setting: " (dbfile:cache-method)) #f))) +;; +;; converge this with dbfile:cautious-open-database +;; (define (dbmod:safely-open-db dbfullname init-proc write-access) (dbfile:with-simple-file-lock (conc dbfullname".lock") (lambda () (let* ((dbexists (file-exists? dbfullname))