Index: common.scm ================================================================== --- common.scm +++ common.scm @@ -50,20 +50,22 @@ (define *alt-log-file* #f) ;; used by -log (define *common:denoise* (make-hash-table)) ;; for low noise printing ;; DATABASE (define *dbstruct-db* #f) -(define *db-stats* (make-hash-table)) ;; hash of vectors < count duration-total > +(define *db-stats* (make-hash-table)) ;; hash of vectors < count duration-total > (define *db-stats-mutex* (make-mutex)) (define *db-sync-mutex* (make-mutex)) (define *db-multi-sync-mutex* (make-mutex)) (define *db-local-sync* (make-hash-table)) ;; used to record last touch of db (define *megatest-db* #f) (define *last-db-access* (current-seconds)) ;; update when db is accessed via server (define *db-write-access* #t) (define *inmemdb* #f) (define *task-db* #f) ;; (vector db path-to-db) +(define *db-access-allowed* #t) ;; flag to allow access +(define *db-access-mutex* (make-mutex)) ;; SERVER (define *my-client-signature* #f) (define *transport-type* 'http) (define *rpc:listener* #f) ;; if set up for server communication this will hold the tcp port @@ -112,14 +114,31 @@ (set! *test-info* (make-hash-table)) (set! *run-info-cache* (make-hash-table)) (set! *env-vars-by-run-id* (make-hash-table)) (set! *test-id-cache* (make-hash-table))) -;; Generic string database (normalization of sorts) +;; Generic string database (define sdb:qry #f) ;; (make-sdb:qry)) ;; 'init #f) -;; Generic path database (normalization of sorts) +;; Generic path database (define *fdb* #f) + +;;====================================================================== +;; L O C K E R S A N D B L O C K E R S +;;====================================================================== + +;; block further accesses to databases. Call this before shutting db down +(define (common:db-block-further-queries) + (mutex-lock! *db-access-mutex*) + (set! *db-access-allowed* #f) + (mutex-unlock! *db-access-mutex*)) + +(define (common:db-access-allowed?) + (let ((val (begin + (mutex-lock! *db-access-mutex*) + *db-access-allowed* + (mutex-unlock! *db-access-mutex*)))) + val)) ;;====================================================================== ;; U S E F U L S T U F F ;;====================================================================== Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -278,10 +278,12 @@ ;; close all opened run-id dbs (define (db:close-all dbstruct) ;; finalize main.db (db:sync-touched dbstruct 0 force-sync: #t) + (common:db-block-further-queries) + (mutex-lock! *db-sync-mutex*) ;; with this perhaps it isn't necessary to use the block-further-queries mechanism? (sqlite3:finalize! (db:get-db dbstruct #f)) (let* ((local (dbr:dbstruct-get-local dbstruct)) (rundb (dbr:dbstruct-get-rundb dbstruct))) (if local (for-each @@ -296,11 +298,12 @@ (sqlite3:database? rundb)) (handle-exceptions exn #t ;; (debug:print 0 "WARNING: database files may not have been closed correctly. Consider running -cleanup-db") (sqlite3:interrupt! rundb) - (sqlite3:finalize! rundb #t))))) + (sqlite3:finalize! rundb #t)))) + (mutex-unlock! *db-sync-mutex*)) (define (db:open-inmem-db) (let* ((db (sqlite3:open-database ":memory:")) (handler (make-busy-timeout 3600))) (db:initialize-run-id-db db) Index: rmt.scm ================================================================== --- rmt.scm +++ rmt.scm @@ -168,12 +168,14 @@ ;; mark this run as dirty if this was a write (if (not (member cmd api:read-only-queries)) (let ((start-time (current-seconds))) (mutex-lock! *db-multi-sync-mutex*) (let ((last-sync (hash-table-ref/default *db-local-sync* run-id 0))) - (if (> (- start-time last-sync) 5) ;; every five seconds + (if (and (> (- start-time last-sync) 5) ;; every five seconds + (common:db-access-allowed?)) (begin + ;; MOVE THIS TO A THREAD? (db:multi-db-sync (list run-id) 'new2old) (debug:print-info 0 "Sync of newdb to olddb for run-id " run-id " completed in " (- (current-seconds) start-time) " seconds") (hash-table-set! *db-local-sync* run-id start-time)))) (mutex-unlock! *db-multi-sync-mutex*))) res)))