Megatest

Diff
Login

Differences From Artifact [c78d2e0924]:

To Artifact [af102aa97d]:


28
29
30
31
32
33
34

35
36
37
38
39
40
41
(declare (uses mtmod))

(module dbmod
	(
	 ;; 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







>







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(declare (uses mtmod))

(module dbmod
	(
	 ;; for debug, can be commented out in production
	 dbmod:safely-open-db
	 dbmod:with-db
	 dbmod:open-db

	 ;; used elsewhere, keep
	 dbmod:db-to-db-sync
	 
	 db:test-get-event_time
	 db:test-get-item-path
	 db:test-get-testname
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
	  (begin
	    (sync-proc last-update)

	    ;; 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 10))
		  (condition-case
		   (apply proc dbdat dbh params)
		   (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. 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", params "params", message: "
					  ((condition-property-accessor 'exn 'message) exn))
			(exit 2))))))
      (if use-mutex (mutex-unlock! *db-with-db-mutex*))
      res)))

(define (db:with-db dbstruct run-id w/r proc . params)
  (dbmod:with-db dbstruct run-id w/r proc params))

;; 
(define (dbmod:open-cachedb-db init-proc dbfullname)







|



















|







297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
	  (begin
	    (sync-proc last-update)

	    ;; 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*)) ;; this mutex was causing deadlock. Found in fullrun test.
    (let* ((res (let loop ((count 10))
		  (condition-case
		   (apply proc dbdat dbh params)
		   (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. 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", params "params", message: "
					  ((condition-property-accessor 'exn 'message) exn))
			(exit 2))))))
      ;; (if use-mutex (mutex-unlock! *db-with-db-mutex*))
      res)))

(define (db:with-db dbstruct run-id w/r proc . params)
  (dbmod:with-db dbstruct run-id w/r proc params))

;; 
(define (dbmod:open-cachedb-db init-proc dbfullname)