Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -50,14 +50,15 @@ ;;====================================================================== ;; R E C O R D S ;;====================================================================== ;; each db entry is a pair ( db . dbfilepath ) -;; I propose this record evolves into the area record +;; NOTE: Need one dbr:dbstruct per main.db, 1.db ... ;; -(defstruct dbr:dbstruct - (tmpdb #f) +(defstruct dbr:dbstruct + (dbname #f) + (tmpdbs #f) (dbstack #f) ;; stack for tmp db handles, do not initialize with a stack (mtdb #f) (refndb #f) (homehost #f) ;; not used yet (on-homehost #f) ;; not used yet @@ -394,29 +395,36 @@ (set! last-update-time lup)) db "select max(lup) from ( select max(last_update) as lup from tests union select max(last_update) as lup from runs);") last-update-time)) ;)) + +;; set up a single db (e.g. main.db, 1.db ... etc.) +;; +(define (db:setup-db dbstructs run-id) + (let* ((dbname (db:run-id->dbname run-id)) + (dbstruct (or (hash-table-ref/default dbstructs dbname #f) + (make-dbr:dbstruct)))) + (db:open-db dbstruct run-id areapath: areapath do-sync: do-sync) + (hash-table-set! dbstructs dbname dbstruct) + dbstruct)) + ;; Make the dbstruct, setup up auxillary db's and call for main db at least once ;; ;; called in http-transport and replicated in rmt.scm for *local* access. ;; (define (db:setup do-sync #!key (areapath #f)) ;; (cond - (*dbstruct-db* *dbstruct-db*);; TODO: when multiple areas are supported, this optimization will be a hazard + (*dbstruct-dbs* *dbstruct-dbs*);; TODO: when multiple areas are supported, this optimization will be a hazard (else ;;(common:on-homehost?) - (debug:print-info 13 *default-log-port* "db:setup entered (first time, not cached.)") - (let* ((dbstruct (make-dbr:dbstruct))) + (let* ((dbstructs (make-hash-table))) (when (not *toppath*) (debug:print-info 13 *default-log-port* "in db:setup, *toppath* not set; calling launch:setup") (launch:setup areapath: areapath)) - (debug:print-info 13 *default-log-port* "Begin db:open-db") - (db:open-db dbstruct #f areapath: areapath do-sync: do-sync) - (debug:print-info 13 *default-log-port* "Done db:open-db") - (set! *dbstruct-db* dbstruct) + (set! *dbstruct-dbs* dbstructs) ;;(debug:print-info 13 *default-log-port* "new dbstruct = "(dbr:dbstruct->alist dbstruct)) dbstruct)))) ;; (else ;; (debug:print 0 *default-log-port* "ERROR: attempt to open database when not on homehost. Exiting. Homehost: " (common:get-homehost)) ;; (exit 1)))) @@ -1144,26 +1152,23 @@ options) data-synced)) ;; Sync all changed db's ;; -(define (db:tmp->megatest.db-sync dbstruct last-update) - (let* ((all-dbs (cons "main.db" (glob (conc (db:dbfile-path)"/[0-9]*.db"))))) - (for-each - (lambda (dbname) - (let* ((mtdb (dbr:dbstruct-mtdb dbstruct)) - - - ;; more to do here? - - - (tmpdb (db:get-db dbstruct)) - (refndb (dbr:dbstruct-refndb dbstruct)) - (res (db:sync-tables (db:sync-all-tables-list dbstruct) last-update tmpdb refndb mtdb))) - (stack-push! (dbr:dbstruct-dbstack dbstruct) tmpdb) - res)) - all-dbs))) +(define (db:tmp->megatest.db-sync dbstruct run-id last-update) + (let* ((dbname (db:run-id->dbname run-id)) + (mtdb (dbr:dbstruct-mtdb dbstruct)) + + + ;; more to do here? + + + (tmpdb (db:get-db dbstruct)) + (refndb (dbr:dbstruct-refndb dbstruct)) + (res (db:sync-tables (db:sync-all-tables-list dbstruct) last-update tmpdb refndb mtdb))) + (stack-push! (dbr:dbstruct-dbstack dbstruct) tmpdb) + res)) ;;;; run-ids ;; if #f use *db-local-sync* : or 'local-sync-flags ;; if #t use timestamps : or 'timestamps ;;