Index: archive.scm ================================================================== --- archive.scm +++ archive.scm @@ -397,11 +397,11 @@ (bup-restore-params (list "-d" archive-path "restore" "-C" *toppath* archive-internal-path))) (debug:print-info 2 *default-log-port* "Restoring archived data to " *toppath* " from archive in " archive-path " ... " archive-internal-path) (run-n-wait bup-exe params: bup-restore-params print-cmd: "Running:")) (sleep 2) (db:multi-db-sync - (db:setup #t *toppath*) ;; (db:setup-db *dbstruct-dbs* *toppath* #f) + (db:setup #t) ;; (db:setup-db *dbstruct-dbs* *toppath* #f) 'killservers ;'dejunk ;'adj-testids 'old2new ) Index: common.scm ================================================================== --- common.scm +++ common.scm @@ -593,11 +593,11 @@ (if (common:on-homehost?) (if (common:api-changed?) (let* ((mtconf (conc (get-environment-variable "MT_RUN_AREA_HOME") "/megatest.config")) (dbfile (conc (get-environment-variable "MT_RUN_AREA_HOME") "/megatest.db")) (read-only (not (file-write-access? dbfile))) - (dbstruct (db:setup #t *toppath*))) ;; (db:setup-db *dbstruct-dbs* *toppath* #f))) ;; #t))) + (dbstruct (db:setup #t))) ;; (db:setup-db *dbstruct-dbs* *toppath* #f))) ;; #t))) (debug:print 0 *default-log-port* "WARNING: Version mismatch!\n" " expected: " (common:version-signature) "\n" " got: " (common:get-last-run-version)) (cond Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -135,11 +135,12 @@ ", location: " ((condition-property-accessor 'exn 'location) exn) )) (define (db:setup do-sync) (assert *toppath* "FATAL: db:setup called before launch:setup has been run.") - (dbfile:setup do-sync *toppath*)) + (let* ((tmpdir (common:get-db-tmp-area))) + (dbfile:setup do-sync *toppath* tmpdir))) ;; looks up subdb and returns it, if not found then set up ;; and then return it. ;; #;(define (db:get-db dbstruct run-id) @@ -181,17 +182,20 @@ ", error: " ((condition-property-accessor 'exn 'message) exn) ", arguments: " ((condition-property-accessor 'exn 'arguments) exn) ", location: " ((condition-property-accessor 'exn 'location) exn) )) +(define (db:open-db dbstruct run-id) + (dbfile:open-db dbstruct run-id db:initialize-main-db)) + ;; (db:with-db dbstruct run-id sqlite3:exec "select blah fgrom blaz;") ;; r/w is a flag to indicate if the db is modified by this query #t = yes, #f = no ;; (define (db:with-db dbstruct run-id r/w proc . params) (let* ((have-struct (dbr:dbstruct? dbstruct)) (dbdat (if have-struct ;; this stuff just allows us to call with a db handle directly - (db:get-subdb dbstruct run-id) + (db:open-db dbstruct run-id) ;; (dbfile:get-subdb dbstruct run-id) #f)) (db (if have-struct ;; this stuff just allows us to call with a db handle directly (dbr:dbdat-dbh dbdat) dbstruct)) (fname (if dbdat @@ -1270,19 +1274,19 @@ (if (equal? (car key) trigger-name) (sqlite3:execute db (cadr key)))) db:trigger-list))) -(define (db:initialize-main-db dbdat) +(define (db:initialize-main-db db) (when (not *configinfo*) (launch:setup)) ;; added because Elena was getting stack dump because *configinfo* below was #f. (let* ((configdat (car *configinfo*)) ;; tut tut, global warning... (keys (keys:config-get-fields configdat)) (havekeys (> (length keys) 0)) (keystr (keys->keystr keys)) (fieldstr (keys:make-key/field-string configdat)) - (db (dbr:dbdat-dbh dbdat))) + #;(db (dbr:dbdat-dbh dbdat))) (for-each (lambda (key) (let ((keyn key)) (if (member (string-downcase keyn) (list "runname" "state" "status" "owner" "event_time" "comment" "fail_count" "pass_count" "contour")) Index: dbfile.scm ================================================================== --- dbfile.scm +++ dbfile.scm @@ -227,12 +227,12 @@ (tmpdbdat (dbfile:open-sqlite3-db tmpdbpath init-proc)) ;; push this on the stack (newsubdb (make-dbr:subdb dbname: dbname mtdbfile: mtdbpath tmpdbfile: tmpdbpath mtdbdat: mtdbdat))) - (dbfile:add-dbdat dbstruct run-id tmpdbdat) (dbfile:set-subdb dbstruct run-id newsubdb) + (dbfile:add-dbdat dbstruct run-id tmpdbdat) newsubdb)) ;; return the new subdb - but shouldn't really use it ;; returns dbdat with dbh and dbfilepath ;; 1. if needed setup the subdb for the given run-id ;; 2. if there is no existing db handle in the stack Index: http-transport.scm ================================================================== --- http-transport.scm +++ http-transport.scm @@ -461,11 +461,11 @@ (start-time (current-milliseconds))) ;; Use this opportunity to sync the tmp db to megatest.db (if (not server-going) ;; *dbstruct-dbs* (begin (debug:print 0 *default-log-port* "SERVER: dbprep") - (set! *dbstruct-dbs* (db:setup #t *toppath*)) ;; run-id)) FIXME!!! + (set! *dbstruct-dbs* (db:setup #t)) ;; run-id)) FIXME!!! (set! server-going #t) (debug:print 0 *default-log-port* "SERVER: running, megatest version: " (common:get-full-version)) ;; NOTE: the server is NOT yet marked as running in the log. We do that in the keep-running routine. (thread-start! *watchdog*))) ;; when things go wrong we don't want to be doing the various queries too often Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -2303,21 +2303,21 @@ (begin (debug:print 0 *default-log-port* "Failed to setup, exiting") (exit 1))) ;; keep this one local ;; (open-run-close patch-db #f) - (let ((dbstructs (db:setup #f *toppath*))) + (let ((dbstructs (db:setup #f))) (common:cleanup-db dbstructs full: #t)) (set! *didsomething* #t))) (if (args:get-arg "-cleanup-db") (begin (if (not (launch:setup)) (begin (debug:print 0 *default-log-port* "Failed to setup, exiting") (exit 1))) - (let ((dbstructs (db:setup #f *toppath*))) + (let ((dbstructs (db:setup #f))) (common:cleanup-db dbstructs)) (set! *didsomething* #t))) (if (args:get-arg "-mark-incompletes") (begin @@ -2372,11 +2372,11 @@ (args:get-arg "-repl") (args:get-arg "-load")) (let* ((toppath (launch:setup)) (dbstructs (if (and toppath (common:on-homehost?)) - (dbfile:setup #t toppath) + (db:setup #t) #f))) ;; make-dbr:dbstruct path: toppath local: (args:get-arg "-local")) #f))) (if *toppath* (cond ((getenv "MT_RUNSCRIPT") ;; How to run megatest scripts @@ -2463,11 +2463,11 @@ (if (args:get-arg "-import-megatest.db") (begin (launch:setup) (db:multi-db-sync - (db:setup #f *toppath*) + (db:setup #f) 'killservers 'dejunk 'adj-testids 'old2new ;; 'new2old @@ -2474,11 +2474,11 @@ ) (set! *didsomething* #t))) (when (args:get-arg "-sync-brute-force") (launch:setup) - ((server:get-bruteforce-syncer (db:setup #t *toppath*) persist-until-sync: #t)) + ((server:get-bruteforce-syncer (db:setup #t) persist-until-sync: #t)) (set! *didsomething* #t)) (if (args:get-arg "-sync-to-megatest.db") (let* ((duh (launch:setup)) (dbstruct (db:setup #f)) Index: rmt.scm ================================================================== --- rmt.scm +++ rmt.scm @@ -370,11 +370,11 @@ res)) (define (rmt:open-qry-close-locally cmd run-id params #!key (remretries 5)) (let* ((qry-is-write (not (member cmd api:read-only-queries))) (db-file-path (db:dbfile-path)) ;; 0)) - (dbstructs-local (db:setup #t *toppath*)) ;; make-dbr:dbstruct path: dbdir local: #t))) + (dbstructs-local (db:setup #t)) ;; make-dbr:dbstruct path: dbdir local: #t))) (read-only (not (file-write-access? db-file-path))) (start (current-milliseconds)) (resdat (if (not (and read-only qry-is-write)) (let ((v (api:execute-requests dbstructs-local (vector (symbol->string cmd) params)))) (handle-exceptions ;; there has been a long history of receiving strange errors from values returned by the client when things go wrong.. Index: tests/simplerun/thebeginning.scm ================================================================== --- tests/simplerun/thebeginning.scm +++ tests/simplerun/thebeginning.scm @@ -1,21 +1,28 @@ (use trace test (prefix sqlite3 sqlite3:)) (import dbfile) (trace-call-sites #t) (trace + ;; dbfile:setup + ;; dbfile:open-sqlite3-db + ;; dbfile:init-subdb + ;; dbfile:add-dbdat + ;; dbfile:set-subdb + ;; db:with-db ;; dbfile:get-subdb ) -(test #f #t (dbr:dbstruct? (dbfile:setup #t *toppath*))) +(define tmpdir (common:get-db-tmp-area)) +(test #f #t (dbr:dbstruct? (dbfile:setup #t *toppath* tmpdir))) (test #f #t (dbr:dbstruct? (db:setup #t))) (define dbstruct *dbstruct-dbs*) (test #f #f (dbfile:get-subdb dbstruct #f)) ;; get main.db (never opened yet) (test #f #f (dbfile:get-subdb dbstruct 1)) ;; get 1.db (test #f #t (hash-table? (dbr:dbstruct-subdbs dbstruct))) - -(test #f #t (dbr:dbdat? (dbfile:get-dbdat *dbstruct-dbs* #f))) +(test #f #t (dbr:dbdat? (dbfile:open-db *dbstruct-dbs* #f db:initialize-main-db))) +(test #f '("SYSTEM" "RELEASE") (db:get-keys *dbstruct-dbs*)) ;; test #f #t (sqlite3:database? (db:open-db dbstruct #f))) ;; test #f #t (sqlite3:database? (db:open-db dbstruct 1))) ;; ;; test #f #t (stack? (dbr:subdb-dbstack subdb