Megatest

Check-in [9b31e3ddb8]
Login
Overview
Comment:Fixed dbfile:get-dbdat, removed calls to add-dbdat in init-subdb, enhanced the tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.7001-multi-db-rb01
Files: files | file ages | folders
SHA1: 9b31e3ddb880976c8627d561965b10c85d6b9ccd
User & Date: mmgraham on 2022-04-05 17:13:31
Other Links: branch diff | manifest | tags
Context
2022-04-05
17:24
Merged fork check-in: b14c77207c user: matt tags: v1.7001-multi-db-rb01
17:13
Fixed dbfile:get-dbdat, removed calls to add-dbdat in init-subdb, enhanced the tests. check-in: 9b31e3ddb8 user: mmgraham tags: v1.7001-multi-db-rb01
2022-03-31
20:32
Made dbfile:get-dbdat check the subdb. Added a couple of tests check-in: bc14ff3da9 user: mmgraham tags: v1.7001-multi-db-rb01
Changes

Modified dbfile.scm from [aa16ae5aef] to [69adbc2395].

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
;;    if run-id is a string treat it as a filename
;;    if db already open - return inmem
;;    if db not open, open inmem, rundb and sync then return inmem
;;    inuse gets set automatically for rundb's
;;
(define (dbfile:get-dbdat dbstruct run-id)
  (let* ((subdb (dbfile:get-subdb dbstruct run-id)))
    (if (or (not subdb) stack-empty? (dbr:subdb-dbstack subdb))
	#f
	(stack-pop! (dbr:subdb-dbstack subdb)))))

;; return a previously opened db handle to the stack of available handles
(define (dbfile:add-dbdat dbstruct run-id dbdat)
  (let* ((subdb (dbfile:get-subdb dbstruct run-id)))
    (stack-push! (dbr:subdb-dbstack subdb) dbdat)))

;; set up a subdb
;;
(define (dbfile:init-subdb dbstruct run-id init-proc)
  (let* ((dbname    (dbfile:run-id->dbname run-id))
	 (areapath  (dbr:dbstruct-areapath dbstruct))
	 (tmppath   (dbr:dbstruct-tmppath  dbstruct))
	 (mtdbpath  (dbfile:run-id->path areapath run-id))
	 (tmpdbpath (dbfile:run-id->path tmppath run-id))
	 (mtdbdat   (dbfile:open-sqlite3-db mtdbpath init-proc))
	 (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: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
;;     create a new handle and return it (do NOT add
;;     it to the stack).







|
|
















<





<







202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

227
228
229
230
231

232
233
234
235
236
237
238
;;    if run-id is a string treat it as a filename
;;    if db already open - return inmem
;;    if db not open, open inmem, rundb and sync then return inmem
;;    inuse gets set automatically for rundb's
;;
(define (dbfile:get-dbdat dbstruct run-id)
  (let* ((subdb (dbfile:get-subdb dbstruct run-id)))
    (if (stack-empty? (dbr:subdb-dbstack subdb))
	 #f
	(stack-pop! (dbr:subdb-dbstack subdb)))))

;; return a previously opened db handle to the stack of available handles
(define (dbfile:add-dbdat dbstruct run-id dbdat)
  (let* ((subdb (dbfile:get-subdb dbstruct run-id)))
    (stack-push! (dbr:subdb-dbstack subdb) dbdat)))

;; set up a subdb
;;
(define (dbfile:init-subdb dbstruct run-id init-proc)
  (let* ((dbname    (dbfile:run-id->dbname run-id))
	 (areapath  (dbr:dbstruct-areapath dbstruct))
	 (tmppath   (dbr:dbstruct-tmppath  dbstruct))
	 (mtdbpath  (dbfile:run-id->path areapath run-id))
	 (tmpdbpath (dbfile:run-id->path tmppath run-id))
	 (mtdbdat   (dbfile:open-sqlite3-db mtdbpath init-proc))

	 (newsubdb  (make-dbr:subdb dbname:    dbname
				    mtdbfile:  mtdbpath
				    tmpdbfile: tmpdbpath
				    mtdbdat:   mtdbdat)))
    (dbfile:set-subdb dbstruct run-id newsubdb)

    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
;;     create a new handle and return it (do NOT add
;;     it to the stack).
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
	               ;; do not collide
	               (let* ((db (sqlite3:open-database dbpath)))
			 (init-proc db))
	               #;(dbfile:lock-create-open dbpath
					    (lambda (db)
                                              (init-proc db))))
	 (write-access (file-write-access? dbpath)))
    (dbfile:print-err  "db:open-sqlite-db "dbpath)
    #;(if (and dbexists (not write-access))
	(set! *db-write-access* #f))
    ;; (cons db dbpath)))
    (make-dbr:dbdat dbfile: dbpath dbh: db read-only: (not write-access))))

(define (dbfile:print-and-exit . params)
  (with-output-to-port







|







263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
	               ;; do not collide
	               (let* ((db (sqlite3:open-database dbpath)))
			 (init-proc db))
	               #;(dbfile:lock-create-open dbpath
					    (lambda (db)
                                              (init-proc db))))
	 (write-access (file-write-access? dbpath)))
    (dbfile:print-err  "db:open-sqlite-db "dbpath " db: " db)
    #;(if (and dbexists (not write-access))
	(set! *db-write-access* #f))
    ;; (cons db dbpath)))
    (make-dbr:dbdat dbfile: dbpath dbh: db read-only: (not write-access))))

(define (dbfile:print-and-exit . params)
  (with-output-to-port

Modified tests/simplerun/thebeginning.scm from [4bb9f4885a] to [9beea9f91a].

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18



19


20
21
22
23
24
25
26
27
28


29

30
31
(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
 )

(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:open-db *dbstruct-dbs* #f db:initialize-main-db)))
(test #f '("SYSTEM" "RELEASE") (db:get-keys *dbstruct-dbs*))
(test #f #f (dbr:dbdat? (dbfile:get-dbdat dbstruct 1))) ;; not open yet
(test #f #f (sqlite3:database? (db:open-db dbstruct #f)))
(test #f #f (sqlite3:database? (db:open-db dbstruct 1)))

;; (test #f #t (stack? (dbr:subdb-dbstack subdb


;; test #f #f (db:get-subdb dbstruct 1))

;; 
;; ; (test #f #f (stack? (dbr:subdb-dbstack subdb)))






|


>









>
>
>
|
>
>
|

|

|
<
<

|
>
>
|
>
|
<
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30


31
32
33
34
35
36
37

(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
 ;; db:initialize-main-db
 ;; dbfile:set-subdb
 ;; db:with-db
 ;; dbfile:get-subdb
 )

(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 #t (dbr:dbdat? (dbfile:open-db *dbstruct-dbs* #f db:initialize-main-db)))
(define mydbdat (dbfile:open-db *dbstruct-dbs* #f db:initialize-main-db))
(dbfile:add-dbdat dbstruct #f mydbdat)
(test #f #t (dbr:subdb? (dbfile:get-subdb dbstruct #f)))
(test #f #t (dbr:dbdat? (dbfile:get-dbdat dbstruct #f)))
(test #f #f (dbr:dbdat? (dbfile:get-dbdat dbstruct #f))) ;; stack empty so should fail.

(test #f #t (hash-table? (dbr:dbstruct-subdbs dbstruct)))
(test #f #t (stack? (dbr:subdb-dbstack (dbfile:get-subdb dbstruct #f))))
(test #f '("SYSTEM" "RELEASE") (db:get-keys *dbstruct-dbs*))




(test #f #t (dbr:dbdat? (dbfile:open-db dbstruct 1 db:initialize-main-db)))
(define rundbdat (dbfile:open-db dbstruct 1 db:initialize-main-db))
(dbfile:add-dbdat dbstruct 1 rundbdat)
(test #f #t (dbr:subdb? (dbfile:get-subdb dbstruct 1)))
(test #f #t (dbr:dbdat? (dbfile:get-dbdat dbstruct 1)))