Megatest

Diff
Login

Differences From Artifact [e09aadfd93]:

To Artifact [8830f3b4fa]:


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
	posix typed-records srfi-18
	srfi-69)

;;======================================================================
;;  R E C O R D S
;;======================================================================










;; each db entry is a pair ( db . dbfilepath )
;; NOTE: Need one dbr:dbstruct per main.db, 1.db ...
;;
(defstruct dbr:dbstruct
  (dbname      #f)

  (dbdats      (make-hash-table))  ;; id => dbdat
  (tmpdb       #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
  (read-only   #f)

  (stmt-cache  (make-hash-table))
  )                ;; goal is to converge on one struct for an area but for now it is too confusing
  

(defstruct dbr:dbdat
  (db          #f)    ;; should rename this to oddb for on disk db
  (tmpdb       #f)

  (dbhstack    #f)    ;; do not init with a stack
  (last-sync   0)


  (last-write  (current-seconds))



  (run-id      #f)

  (fname       #f))






; Returns the dbdat for a particular dbfile inside the area
;;
(define (dbr:dbstruct-get-dbdat dbstruct dbfile)
  (hash-table-ref/default (dbr:dbstruct-dbdats dbstruct) dbfile #f))

(define (dbr:dbstruct-dbdat-put! dbstruct dbfile db)
  (hash-table-set! (dbr:dbstruct-dbdats dbstruct) dbfile db))

(define (db:run-id->first-num run-id)
  (let* ((s (number->string run-id))
	 (l (string-length s)))
    (substring s (- l 1) l)))

;; 1234 => 4/1234.db
;;   #f => 0/main.db
;;   (abandoned the idea of num/db)
;; 
(define (db:run-id->path apath run-id)
  (conc apath"/"(db:run-id->dbname run-id)))







>
>
>
>
>
>
>
>
>
|
|

|
|
>
|
|
>

<
<



>
|

|
>

|
|
>
|
|
>
>
|
>
>
>
|
>
|
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|







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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
	posix typed-records srfi-18
	srfi-69)

;;======================================================================
;;  R E C O R D S
;;======================================================================

;; a single Megatest area with it's multiple dbs is
;; managed in a dbstruct
;;
(defstruct dbr:dbstruct
  (areapath  #f)
  (homehost  #f)
  (read-only #f)
  (subdbs (make-hash-table))
  )

;; NOTE: Need one dbr:subdb per main.db, 1.db ...
;;
(defstruct dbr:subdb
  (dbname      #f) ;; .db/1.db
  (mtdb        #f) ;; mtrah/.db/1.db
  ;; (dbdats      (make-hash-table))  ;; id => dbdat 
  (tmpdb       #f) ;; /tmp/.../.db/1.db
  (refndb      #f) ;; /tmp/.../.db/1.db_ref
  (dbstack     #f) ;; stack for tmp db handles, do not initialize with a stack


  (homehost    #f) ;; not used yet
  (on-homehost #f) ;; not used yet
  (read-only   #f)
  (last-sync   0)
  (last-write  (current-seconds))
  )                ;; goal is to converge on one struct for an area but for now it is too confusing

;; need to keep dbhandles and cached statements together
(defstruct dbr:dbdat
  (dbfile      #f)
  (dbh         #f)    
  (stmt-cache  (make-hash-table))
  (read-only   #f))

(define (dbfile:run-id->key run-id)
  (or run-id 'main))

;; ;; set up a single db (e.g. main.db, 1.db ... etc.)
;; ;;
;; (define (db:setup-db dbstruct areapath run-id)
;;   (let* ((dbname   (db:run-id->dbname run-id))
;; 	 (dbstruct (hash-table-ref/default dbstructs dbname #f)))
;;     (if dbstruct
;; 	dbstruct
;; 	(let* ((dbstruct-new (make-dbr:dbstruct)))
;; 	  (db:open-db dbstruct-new run-id areapath: areapath do-sync: #t)
;; 	  (hash-table-set! dbstructs dbname dbstruct-new)
;; 	  dbstruct-new))))
    
;; ; Returns the dbdat for a particular dbfile inside the area
;; ;;
;; (define (dbr:dbstruct-get-dbdat dbstruct dbfile)
;;   (hash-table-ref/default (dbr:dbstruct-dbdats dbstruct) dbfile #f))
;; 
;; (define (dbr:dbstruct-dbdat-put! dbstruct dbfile db)
;;   (hash-table-set! (dbr:dbstruct-dbdats dbstruct) dbfile db))
;; 
;; (define (db:run-id->first-num run-id)
;;   (let* ((s (number->string run-id))
;; 	 (l (string-length s)))
;;     (substring s (- l 1) l)))

;; 1234 => 4/1234.db
;;   #f => 0/main.db
;;   (abandoned the idea of num/db)
;; 
(define (db:run-id->path apath run-id)
  (conc apath"/"(db:run-id->dbname run-id)))