Index: dbfile.scm ================================================================== --- dbfile.scm +++ dbfile.scm @@ -56,15 +56,17 @@ (areapath #f) (homehost #f) (tmppath #f) (read-only #f) (subdbs (make-hash-table)) + ;; ;; for the inmem approach (see dbmod.scm) ;; this is one db per server (inmem #f) ;; handle for the in memory copy (dbfile #f) ;; path to the db file on disk (ondiskdb #f) ;; handle for the on-disk file + (dbdat #f) ;; create a dbdat for the downstream calls such as db:with-db ) ;; NOTE: Need one dbr:subdb per main.db, 1.db ... ;; (defstruct dbr:subdb @@ -1016,11 +1018,14 @@ ;; call with dbinit=db:initialize-main-db ;; (define (db:open-db dbstruct run-id dbinit) ;; (mutex-lock! *db-open-mutex*) - (let* ((dbdat (dbfile:open-db dbstruct run-id dbinit))) + (let* ((dbdat (case (rmt:transport-mode) + ((http) (dbfile:open-db dbstruct run-id dbinit)) + ((tcp) (dbmod:open-db dbstruct run-id dbinit)) + (else (assert #f "FATAL: rmt:transport-node not correct value"(rmt:transport-mode)))))) (set! *db-write-access* (not (dbr:dbdat-read-only dbdat))) ;; (mutex-unlock! *db-open-mutex*) dbdat)) (define dbfile:db-init-proc (make-parameter #f)) Index: dbmod.scm ================================================================== --- dbmod.scm +++ dbmod.scm @@ -62,21 +62,32 @@ (let* ((db (sqlite3:open-database ":memory:")) (handler (sqlite3:make-busy-timeout 3600))) (sqlite3:set-busy-handler! db handler) (initproc db) db)) + +(define (dbmod:open-db dbstruct run-id dbinit) + (or (dbr:dbstruct-dbdat dbstruct) + (let* ((dbdat (make-dbr:dbdat + dbfile: (dbr:dbstruct-dbfile dbstruct) + dbh: (dbr:dbstruct-inmen dbstruct) + ))) + (dbr:dbstruct-dbdat-set! dbstruct dbdat) + dbdat))) ;; Open the inmem db and the on-disk db ;; populate the inmem db with data ;; ;; Updates fields in dbstruct ;; Returns dbstruct ;; -;; This routine creates the db if not found +;; * This routine creates the db if not found +;; * Probably can get rid of the dbstruct-in ;; -(define (db:open-dbmoddb dbstruct run-id init-proc) ;; (conc *toppath* "/megatest.db") (car *configinfo*))) - (let* ((dbfname (dbmod:run-id->dbfname run-id)) +(define (db:open-dbmoddb areapath run-id init-proc #!key (dbstruct-in #f)) ;; (conc *toppath* "/megatest.db") (car *configinfo*))) + (let* ((dbstruct (or dbstruct-in (make-dbr:dbstruct areapath: areapath))) + (dbfname (dbmod:run-id->dbfname run-id)) (dbpath (dbmod:get-dbdir dbstruct run-id)) ;; directory where all the .db files are kept (dbfullname (dbmod:run-id->full-dbfname dbstruct run-id)) (dbexists (file-exists? dbfullname)) (inmem (dbmod:open-inmem-db init-proc)) (write-access (file-write-access? dbpath)) Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -934,11 +934,11 @@ (case (rmt:transport-mode) ((http)(http-transport:launch)) ((tcp) (debug:print 0 *default-log-port* "INFO: Running using tcp method.") (if run-id - (tt:start-server tl (dbmod:run-id->dbfname run-id)) + (tt:start-server tl (dbmod:run-id->dbfname run-id) api:dispatch-request) (begin (debug:print 0 *default-log-port* "ERROR: transport mode is tcp - -run-id is required.") (exit 1)))) (else (debug:print 0 *default-log-port* "ERROR: rmt:transport-mode value not recognised "(rmt:transport-mode)))) (set! *didsomething* #t))) Index: tcp-transportmod.scm ================================================================== --- tcp-transportmod.scm +++ tcp-transportmod.scm @@ -143,13 +143,13 @@ ;; is there already a server for this dbfile? Then exit. (let* ((ttdat (make-tt areapath: areapath)) (servers (tt:find-server ttdat dbfname))) (tt-handler-set! ttdat handler) (if (null? servers) - (begin + (let* ((dbstruct (dbmod:open-dbmoddb areapath run-id (dbfile:db-init-db)))) (tt:start-tcp-server ttdat) ;; start the tcp-server which applies handler to incoming data - (tt:keep-running ttdat dbfname)) + (tt:keep-running ttdat dbfname handler)) (begin (debug:print 0 *default-log-port* "INFO: found server(s) already running for db "dbfname", "(string-intersperse servers ",")" Exiting.") (exit))))) ;; find a port and start tcp-server