︙ | | |
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
+
|
;;
(define (dbfile:run-id->path apath run-id)
(conc apath"/"(dbfile:run-id->dbname run-id)))
(define (db:dbname->path apath dbname)
(conc apath"/"dbname))
;; POTENTIAL BUG: this implementation could produce a db file if run-id is neither #f or a number
(define (dbfile:run-id->dbname run-id)
(cond
((number? run-id) (conc ".megatest/" (modulo run-id 100) ".db"))
((not run-id) (conc ".megatest/main.db"))
(else run-id)))
;; Make the dbstruct, setup up auxillary db's and call for main db at least once
|
︙ | | |
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
-
+
-
-
-
-
-
-
-
-
-
+
+
|
#f
(begin
(set! *dbfile:num-handles-in-use* (+ *dbfile:num-handles-in-use* 1))
(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))
(let* ((subdb (dbfile:get-subdb dbstruct run-id)))
(age (- (current-seconds)(dbr:dbdat-birth-sec dbdat))))
(if #f ;; (> age 300) ;; just testing - discard and close after 30 sec
(begin
;; (map sqlite3:finalize! (hash-table-values (dbr:dbdat-stmt-cache dbdat)))
;; (sqlite3:finalize! (dbr:dbdat-dbh dbdat))
(dbfile:print-err "INFO: Discarded dbdat over 30 sec old ("age"s)"))
(begin
(set! *dbfile:num-handles-in-use* (- *dbfile:num-handles-in-use* 1))
(stack-push! (dbr:subdb-dbstack subdb) dbdat)))))
(set! *dbfile:num-handles-in-use* (- *dbfile:num-handles-in-use* 1))
(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))
|
︙ | | |
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
-
-
+
+
|
;;
;; this stuff is for initial debugging, please remove it when
;; this code stabilizes
(define *dbopens* (make-hash-table))
(define (dbfile:inc-db-open dbfile)
(let* ((curr-opens-count (+ (hash-table-ref/default *dbopens* dbfile 0) 1)))
(if (> curr-opens-count 1) ;; this should NOT be happening
(dbfile:print-err "INFO: db "dbfile" has been opened "curr-opens-count" times!"))
;; (if (> curr-opens-count 1) ;; this should NOT be happening
;; (dbfile:print-err "INFO: db "dbfile" has been opened "curr-opens-count" times!"))
(hash-table-set! *dbopens* dbfile curr-opens-count)
curr-opens-count))
;; Open the classic megatest.db file (defaults to open in toppath)
;;
;; NOTE: returns a dbdat not a dbstruct!
;;
|
︙ | | |
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
|
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
-
|
(if (not db-exists)
(begin
(sqlite3:execute db "CREATE TABLE IF NOT EXISTS no_sync_metadat (var TEXT,val TEXT, CONSTRAINT no_sync_metadat_constraint UNIQUE (var));"))
)))
(db (dbfile:cautious-open-database dbname init-proc))) ;; (sqlite3:open-database dbname)))
(sqlite3:execute db "PRAGMA synchronous = 0;")
(sqlite3:set-busy-handler! db (sqlite3:make-busy-timeout 136000))
;;(sqlite3:execute db "PRAGMA journal_mode=WAL;")
(set! *no-sync-db* db)
db))))
(define (db:no-sync-set db var val)
(sqlite3:execute db "INSERT OR REPLACE INTO no_sync_metadat (var,val) VALUES (?,?);" var val))
(define (db:no-sync-del! db var)
|
︙ | | |
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
|
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
|
-
-
|
#;(subdb (if have-struct
(dbfile:get-subdb dbstruct run-id)
#f))
(use-mutex (> *api-process-request-count* 25))) ;; was 25
(if (and use-mutex
(common:low-noise-print 120 "over-50-parallel-api-requests"))
(dbfile:print-err *api-process-request-count* " parallel api requests being processed in process " (current-process-id) ", throttling access"))
#;(if (common:low-noise-print 600 (conc "parallel-api-requests" *max-api-process-requests*))
(dbfile:print-err "Parallel api request count: " *api-process-request-count* " max parallel requests: " *max-api-process-requests*))
(condition-case
(begin
(if use-mutex (mutex-lock! *db-with-db-mutex*))
(let ((res (apply proc dbdat db params)))
(if use-mutex (mutex-unlock! *db-with-db-mutex*))
;; (if (vector? dbstruct)(db:done-with dbstruct run-id r/w))
(if dbdat
|
︙ | | |