14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
(vector
#f ;; the main db (contains runs, test_meta etc.) NOT CACHED IN MEM
(make-hash-table) ;; run-id => [ rundb inmemdb last-mod last-read last-sync ]
#f ;; the global string db (use for state, status etc.)
path ;; path to database files/megatest area
local)) ;; read-only local access
;; get and set main db
(define-inline (dbr:dbstruct-get-main vec) (vector-ref vec 0))
(define-inline (dbr:dbstruct-set-main! vec db)(vector-set! vec 0 db))
;; get a rundb vector
(define (dbr:dbstruct-get-rundb-rec vec run-id)
(let* ((dbhash (vector-ref vec 1))
(runvec (hash-table-ref/default dbhash run-id #f)))
(if runvec
runvec
(let ((nvec (vector #f #f -1 -1 -1 #f)))
(hash-table-set! dbhash run-id nvec)
nvec))))
;; [ rundb inmemdb last-mod last-read last-sync ]
(define-inline (dbr:dbstruct-field-name->num field-name)
(case field-name
((rundb) 0) ;; the on-disk db
((inmem) 1) ;; the in-memory db
((mtime) 2) ;; last modification time
((rtime) 3) ;; last read time
((stime) 4) ;; last sync time
((inuse) 5) ;; is the db currently in use
(else -1)))
;; get/set rundb fields
(define (dbr:dbstruct-get-runvec vec run-id field-name)
(let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id))
(fieldnum (dbr:dbstruct-field-name->num field-name)))
;; (vector-set! runvec (dbr:dbstruct-field-name->num 'inuse) #t)
(vector-ref runvec fieldnum)))
(define (dbr:dbstruct-set-runvec! vec run-id field-name val)
(let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id)))
(vector-set! runvec (dbr:dbstruct-field-name->num field-name) runvec)))
;; get/set inmemdb
(define (dbr:dbstruct-get-inmemdb vec run-id)
(let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id)))
(vector-ref runvec 1)))
(define (dbr:dbstruct-set-inmemdb! vec run-id inmemdb)
(let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id)))
(vector-set! runvec 1 inmemdb)))
;; the string db
(define-inline (dbr:dbstruct-get-strdb vec) (vector-ref vec 2))
(define-inline (dbr:dbstruct-set-strdb! vec db)(vector-set! vec 2 db))
;; path
(define-inline (dbr:dbstruct-get-path vec) (vector-ref vec 3))
(define-inline (dbr:dbstruct-set-path! vec path)(vector-set! vec 3))
;; local
(define-inline (dbr:dbstruct-get-local vec) (vector-ref vec 4))
(define-inline (dbr:dbstruct-set-local! vec val)(vector-set! vec 4 val))
(define (make-db:test)(make-vector 20))
(define-inline (db:test-get-id vec) (vector-ref vec 0))
(define-inline (db:test-get-run_id vec) (vector-ref vec 1))
(define-inline (db:test-get-testname vec) (vector-ref vec 2))
(define-inline (db:test-get-state vec) (vector-ref vec 3))
(define-inline (db:test-get-status vec) (vector-ref vec 4))
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
(vector
#f ;; the main db (contains runs, test_meta etc.) NOT CACHED IN MEM
(make-hash-table) ;; run-id => [ rundb inmemdb last-mod last-read last-sync ]
#f ;; the global string db (use for state, status etc.)
path ;; path to database files/megatest area
local)) ;; read-only local access
;;
;; Accessors for a dbstruct
;;
;; get and set main db
(define-inline (dbr:dbstruct-get-main vec) (vector-ref vec 0))
(define-inline (dbr:dbstruct-set-main! vec db)(vector-set! vec 0 db))
;; get the runs hash
(define-inline (dbr:dbstruct-get-dbhash vec) (vector-ref vec 1))
;; the string db
(define-inline (dbr:dbstruct-get-strdb vec) (vector-ref vec 2))
(define-inline (dbr:dbstruct-set-strdb! vec db)(vector-set! vec 2 db))
;; path
(define-inline (dbr:dbstruct-get-path vec) (vector-ref vec 3))
(define-inline (dbr:dbstruct-set-path! vec path)(vector-set! vec 3))
;; local
(define-inline (dbr:dbstruct-get-local vec) (vector-ref vec 4))
(define-inline (dbr:dbstruct-set-local! vec val)(vector-set! vec 4 val))
;; get a rundb vector, create it if not already existing
(define (dbr:dbstruct-get-rundb-rec vec run-id)
(let* ((dbhash (dbr:dbstruct-get-dbhash vec)) ;; get the runs hash
(runvec (hash-table-ref/default dbhash run-id #f))) ;; get the vector for run-id
(if (vector? runvec)
runvec
(let ((nvec (vector #f #f -1 -1 -1 #f)))
(hash-table-set! dbhash run-id nvec)
nvec))))
;; [ rundb inmemdb last-mod last-read last-sync ]
(define-inline (dbr:dbstruct-field-name->num field-name)
(case field-name
((rundb) 0) ;; the on-disk db
((inmem) 1) ;; the in-memory db
((mtime) 2) ;; last modification time
((rtime) 3) ;; last read time
((stime) 4) ;; last sync time
((inuse) 5) ;; is the db currently in use
(else -1)))
;; get/set rundb fields
(define (dbr:dbstruct-get-runvec-val vec run-id field-name)
(let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id))
(fieldnum (dbr:dbstruct-field-name->num field-name)))
;; (vector-set! runvec (dbr:dbstruct-field-name->num 'inuse) #t)
(vector-ref runvec fieldnum)))
(define (dbr:dbstruct-set-runvec-val! vec run-id field-name val)
(let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id)))
(vector-set! runvec (dbr:dbstruct-field-name->num field-name) val)))
;; get/set inmemdb
(define (dbr:dbstruct-get-inmemdb vec run-id)
(let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id)))
(vector-ref runvec 1)))
(define (dbr:dbstruct-set-inmemdb! vec run-id inmemdb)
(let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id)))
(vector-set! runvec 1 inmemdb)))
(define (make-db:test)(make-vector 20))
(define-inline (db:test-get-id vec) (vector-ref vec 0))
(define-inline (db:test-get-run_id vec) (vector-ref vec 1))
(define-inline (db:test-get-testname vec) (vector-ref vec 2))
(define-inline (db:test-get-state vec) (vector-ref vec 3))
(define-inline (db:test-get-status vec) (vector-ref vec 4))
|