Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -805,13 +805,15 @@ (debug:print-info 4 "launch throttle factor=" *global-delta*) (set! *last-global-delta-printed* *global-delta*))) res)) (define (db:set-var dbstruct var val) + (db:delay-if-busy) (sqlite3:execute (db:get-db dbstruct #f) "INSERT OR REPLACE INTO metadat (var,val) VALUES (?,?);" var val)) (define (db:del-var dbstruct var) + (db:delay-if-busy) (sqlite3:execute (db:get-db dbstruct #f) "DELETE FROM metadat WHERE var=?;" var)) ;; use a global for some primitive caching, it is just silly to ;; re-read the db over and over again for the keys since they never ;; change @@ -907,10 +909,11 @@ (key=?str (string-intersperse (map (lambda (k)(conc k "=?")) keys) " AND "))) (debug:print 3 "keys: " keys " allvals: " allvals " keyvals: " keyvals " key=?str is " key=?str) (debug:print 2 "NOTE: using target " (string-intersperse (map cadr keyvals) "/") " for this run") (if (and runname (null? (filter (lambda (x)(not x)) keyvals))) ;; there must be a better way to "apply and" (let ((res #f)) + (db:delay-if-busy) (apply sqlite3:execute db (conc "INSERT OR IGNORE INTO runs (runname,state,status,owner,event_time" comma keystr ") VALUES (?,?,?,?,strftime('%s','now')" comma valslots ");") allvals) (apply sqlite3:for-each-row (lambda (id) (set! res id)) @@ -917,10 +920,11 @@ db (let ((qry (conc "SELECT id FROM runs WHERE (runname=? " andstr key=?str ");"))) ;(debug:print 4 "qry: " qry) qry) qryvals) + (db:delay-if-busy) (sqlite3:execute db "UPDATE runs SET state=?,status=?,event_time=strftime('%s','now') WHERE id=? AND state='deleted';" state status res) res) (begin (debug:print 0 "ERROR: Called without all necessary keys") #f)))) @@ -1159,36 +1163,41 @@ (let ((finalres (vector header res))) ;; (hash-table-set! *run-info-cache* run-id finalres) finalres))) (define (db:set-comment-for-run dbstruct run-id comment) + (db:delay-if-busy) (sqlite3:execute (db:get-db dbstruct #f) "UPDATE runs SET comment=? WHERE id=?;" comment ;; (sdb:qry 'getid comment) run-id)) ;; does not (obviously!) removed dependent data. But why not!!? (define (db:delete-run dbstruct run-id) ;; First set any related tests to DELETED (let ((db (db:get-db dbstruct run-id))) + (db:delay-if-busy) (sqlite3:execute db "UPDATE tests SET state='DELETED',comment='';") (sqlite3:execute db "DELETE FROM test_steps;") (sqlite3:execute db "DELETE FROM test_data;") (sqlite3:execute (db:get-db dbstruct #f) "UPDATE runs SET state='deleted',comment='' WHERE id=?;" run-id))) (define (db:update-run-event_time dbstruct run-id) + (db:delay-if-busy) (sqlite3:execute (db:get-db dbstruct #f) "UPDATE runs SET event_time=strftime('%s','now') WHERE id=?;" run-id)) (define (db:lock/unlock-run dbstruct run-id lock unlock user) (let ((newlockval (if lock "locked" (if unlock "unlocked" "locked")))) ;; semi-failsafe (sqlite3:execute (db:get-db dbstruct #f) "UPDATE runs SET state=? WHERE id=?;" newlockval run-id) + (db:delay-if-busy) (sqlite3:execute (db:get-db dbstruct #f) "INSERT INTO access_log (user,accessed,args) VALUES(?,strftime('%s','now'),?);" user (conc newlockval " " run-id)) (debug:print-info 1 "" newlockval " run number " run-id))) (define (db:set-run-status db run-id status #!key (msg #f)) + (db:delay-if-busy) (if msg (sqlite3:execute db "UPDATE runs SET status=?,comment=? WHERE id=?;" status msg run-id) (sqlite3:execute db "UPDATE runs SET status=? WHERE id=?;" status run-id))) (define (db:get-run-status db run-id) @@ -1385,10 +1394,11 @@ ;; use db:mintests-get-{id ,run_id,testname ...} (define (db:get-tests-for-runs-mindata dbstruct run-ids testpatt states statuses not-in) (db:get-tests-for-runs dbstruct run-ids testpatt states statuses not-in: not-in qryvals: "id,run_id,testname,state,status,event_time,item_path")) (define (db:get-tests-for-runs dbstruct run-ids testpatt states statuses #!key (not-in #f)(qryvals #f)) + (db:delay-if-busy) (let ((res '())) (for-each (lambda (run-id) (set! res (append res @@ -1402,10 +1412,11 @@ ;; (define (db:delete-test-records dbstruct run-id test-id) (let ((db (db:get-db dbstruct run-id))) (db:general-call db 'delete-test-step-records (list test-id)) + (db:delay-if-busy) (db:general-call db 'delete-test-data-records (list test-id)) (sqlite3:execute db "UPDATE tests SET state='DELETED',status='n/a',comment='' WHERE id=?;" test-id))) (define (db:delete-tests-for-run dbdbstruct run-id) (let ((db (db:get-db dbstruct run-id))) @@ -1428,17 +1439,19 @@ (let ((qry (conc "UPDATE tests SET state=?,status=? WHERE " (if currstate (conc "state='" currstate "' AND ") "") (if currstatus (conc "status='" currstatus "' AND ") "") " run_id=? AND testname=? AND NOT (item_path='' AND testname in (SELECT DISTINCT testname FROM tests WHERE testname=? AND item_path != ''));"))) ;;(debug:print 0 "QRY: " qry) + (db:delay-if-busy) (sqlite3:execute (db:get-db dbstruct run-id) qry run-id newstate newstatus testname testname))) testnames)) ;; speed up for common cases with a little logic ;; NB// Ultimately this will be deprecated in deference to mt:test-set-state-status-by-id ;; (define (db:test-set-state-status-by-id dbstruct run-id test-id newstate newstatus newcomment) + (db:delay-if-busy) (let ((db (db:get-db dbstruct run-id))) (cond ((and newstate newstatus newcomment) (sqlite3:execute db "UPDATE tests SET state=?,status=?,comment=? WHERE id=?;" newstate newstatus newcomment ;; (sdb:qry 'getid newcomment) test-id)) @@ -1451,10 +1464,11 @@ test-id)))) (mt:process-triggers run-id test-id newstate newstatus))) ;; Never used, but should be? (define (db:test-set-state-status-by-run-id-testname db run-id test-name item-path status state) + (db:delay-if-busy) (sqlite3:execute db "UPDATE tests SET state=?,status=?,event_time=strftime('%s','now') WHERE run_id=? AND testname=? AND item_path=?;" state status run-id test-name item-path)) ;; NEW BEHAVIOR: Count tests running in only one run! ;; @@ -1601,10 +1615,11 @@ (conc "SELECT " db:test-record-qry-selector " FROM tests WHERE testname=? AND item_path=?;") test-name item-path) res)) (define (db:test-get-rundir-from-test-id dbstruct run-id test-id) + (db:delay-if-busy) (let ((db (db:get-db dbstruct run-id)) (res #f)) (sqlite3:for-each-row (lambda (tpath) (set! res tpath)) @@ -2022,10 +2037,35 @@ ;; (proc (- remtries 1))))) ;; (apply sqlite3:execute db query params)) ;; (debug:print 0 "ERROR: too many attempts to access db were made and no sucess. query: " ;; query ", params: " params)))) ;; (proc remtries)) +(define (db:delay-if-busy #!key (count 5)) + (let ((dbfj (conc *toppath* "/megatest.db-journal"))) + (if (file-exists? dbfj) + (case count + ((5) + (thread-sleep! 0.1) + (db:delay-if-busy count: 4)) + ((4) + (thread-sleep! 0.4) + (db:delay-if-busy count: 3)) + ((3) + (thread-sleep! 1.0) + (db:delay-if-busy count: 2)) + ((2) + (thread-sleep! 2.0) + (db:delay-if-busy count: 1)) + ((1) + (thread-sleep! 5.0) + (db:delay-if-busy count: 0)) + (else + (debug:print-info 0 "delaying db access due to high database load.") + (thread-sleep! 10)))))) +;; (db:delay-if-busy) +;; (apply sqlite3:execute db query params))) +;; (db:delay-if-busy) (define (db:test-get-records-for-index-file dbstruct run-id test-name) (let ((res '())) (sqlite3:for-each-row (lambda (id itempath state status run_duration logf-id comment-id) @@ -2052,14 +2092,16 @@ testname) res)) ;; create a new record for a given testname (define (db:testmeta-add-record dbstruct testname) + (db:delay-if-busy) (sqlite3:execute (db:get-db dbstruct #f) "INSERT OR IGNORE INTO test_meta (testname,author,owner,description,reviewed,iterated,avg_runtime,avg_disk,tags) VALUES (?,'','','','','','','','');" testname)) ;; update one of the testmeta fields (define (db:testmeta-update-field dbstruct testname field value) + (db:delay-if-busy) (sqlite3:execute (db:get-db dbstruct #f) (conc "UPDATE test_meta SET " field "=? WHERE testname=?;") value testname)) (define (db:testmeta-get-all dbstruct) (let ((res '())) (sqlite3:for-each-row Index: docs/megatest-training.odp ================================================================== --- docs/megatest-training.odp +++ docs/megatest-training.odp cannot compute difference between binary files