@@ -89,25 +89,30 @@ ;; inuse gets set automatically for rundb's ;; (define (db:get-db dbstruct run-id) (if (sqlite3:database? dbstruct) ;; pass sqlite3 databases on through dbstruct - (begin - (let ((dbdat (if (or (not run-id) - (eq? run-id 0)) - (db:open-main dbstruct) - (db:open-rundb dbstruct run-id) - ))) - dbdat)))) + (if (pair? dbstruct) + dbstruct ;; pass pair ( db . path ) on through + (begin + ;; (assert (dbr:dbstruct? dbstruct)) ;; so much legacy, but by here we should have a genuine dbstruct + (let ((dbdat (if (or (not run-id) + (eq? run-id 0)) + (db:open-main dbstruct) + (db:open-rundb dbstruct run-id) + ))) + dbdat))))) ;; legacy handling of structure for managing db's. Refactor this into dbr:? (define (db:dbdat-get-db dbdat) + ;; (assert (pair? dbdat)) (if (pair? dbdat) (car dbdat) dbdat)) (define (db:dbdat-get-path dbdat) + ;; (assert (pair? dbdat)) (if (pair? dbdat) (cdr dbdat) #f)) ;; mod-read: @@ -321,10 +326,12 @@ (let* ((dbdir (db:dbfile-path #f)) ;; (conc (configf:lookup *configdat* "setup" "linktree") "/.db")) (dbstruct (make-dbr:dbstruct path: dbdir local: local))) dbstruct)) ;; Open the classic megatest.db file in toppath +;; +;; NOTE: returns a dbdat not a dbstruct! ;; (define (db:open-megatest-db #!key (path #f)) (let* ((dbpath (or path (conc *toppath* "/megatest.db"))) (dbexists (file-exists? dbpath)) (db (db:lock-create-open dbpath @@ -813,11 +820,10 @@ (apply rmt-cmd params))) ;; return the target db handle so it can be used ;; (define (db:cache-for-read-only source target #!key (use-last-update #f)) - (common:sync-to-megatest.db #t) ;; BUG!! DON'T LEAVE THIS HERE! (if (and (hash-table-ref/default *global-db-store* target #f) (>= (file-modification-time target)(file-modification-time source))) (hash-table-ref *global-db-store* target) (let* ((toppath (launch:setup)) (targ-db-last-mod (if (file-exists? target) @@ -836,25 +842,35 @@ ;; call a proc with a cached db ;; (define (db:call-with-cached-db proc . params) ;; first cache the db in /tmp - (let* ((cname-part (conc "megatest_cache/" (common:get-testsuite-name))) - (fname (conc (common:get-area-path-signature) ".db")) - (cache-dir (common:get-create-writeable-dir - (list (conc "/tmp/" (current-user-name) "/" cname-part) - (conc "/tmp/" (current-user-name) "-" cname-part) - (conc "/tmp/" (current-user-name) "_" cname-part))))) - ;; (debug:print-info 0 *default-log-port* "Using cache dir " cache-dir) + (let* ((cname-part (conc "megatest_cache/" (common:get-testsuite-name))) + (fname (conc (common:get-area-path-signature) ".db")) + (cache-dir (common:get-create-writeable-dir + (list (conc "/tmp/" (current-user-name) "/" cname-part) + (conc "/tmp/" (current-user-name) "-" cname-part) + (conc "/tmp/" (current-user-name) "_" cname-part)))) + (megatest-db (conc *toppath* "/megatest.db"))) + ;; (debug:print-info 0 *default-log-port* "Using cache dir " cache-dir) (if (not cache-dir) (begin (debug:print 0 *default-log-port* "ERROR: Failed to find an area to write the cache db") (exit 1)) - (let* ((cache-db (db:cache-for-read-only - (conc *toppath* "/megatest.db") + (let* ((th1 (make-thread + (lambda () + (if (and (file-exists? megatest-db) + (file-write-access? megatest-db)) + (begin + (common:sync-to-megatest.db 'timestamps) ;; internally mutexes on *db-local-sync* + (debug:print-info 2 *default-log-port* "Done syncing to megatest.db")))) + "call-with-cached-db sync-to-megatest.db")) + (cache-db (db:cache-for-read-only + megatest-db (conc cache-dir "/" fname) use-last-update: #t))) + (thread-start! th1) (apply proc cache-db params) )))) ;; options: ;; @@ -2249,10 +2265,11 @@ keys) (reverse res))) ;; get key vals for a given run-id (define (db:get-key-vals dbstruct run-id) + ;; (assert (dbr:dbstruct? dbstruct)) (let* ((keys (db:get-keys dbstruct)) (res '()) (dbdat (db:get-db dbstruct #f)) (db (db:dbdat-get-db dbdat))) (for-each