@@ -26,11 +26,162 @@ (declare (uses debugprint)) (declare (uses mtargs)) (declare (uses mtmod)) (module dbmod - * + ( + ;; for debug, can be commented out + dbmod:safely-open-db + + dbmod:db-to-db-sync + + db:test-get-event_time + db:test-get-item-path + db:test-get-testname + db:get-value-by-header + + db:get-subdb + + db:multi-db-sync + + dbmod:open-dbmoddb + dbmod:run-id->dbfname + + db:roll-up-rules + db:get-all-state-status-counts-for-test + db:test-set-state-status-db + db:general-call + db:cache-for-read-only + db:convert-test-itempath + + db:test-data-rollup + db:keep-trying-until-true + db:get-test-info-by-id + db:with-db + db:get-test-id + db:get-test-info + + dbmod:print-db-stats + db:get-keys + db:open-no-sync-db + db:add-stats + + ;; dbr:counts record accessors + dbr:counts->alist + + db:add-var + db:archive-register-block-name + db:archive-register-disk + db:create-all-triggers + db:csv->test-data + db:dec-var + db:del-var + db:delete-old-deleted-test-records + db:delete-run + db:delete-steps-for-test! + db:delete-test-records + db:drop-all-triggers + db:get-all-run-ids + db:get-all-runids + db:get-changed-record-ids + db:get-changed-record-run-ids + db:get-changed-record-test-ids + db:get-count-tests-running + db:get-count-tests-running-for-run-id + db:get-count-tests-running-for-testname + db:get-count-tests-running-in-jobgroup + db:get-data-info-by-id + db:get-key-val-pairs + db:get-key-vals + db:get-latest-host-load + db:get-main-run-stats + db:get-matching-previous-test-run-records + db:get-not-completed-cnt + db:get-num-runs + db:get-prereqs-not-met + db:get-prev-run-ids + db:get-raw-run-stats + db:get-run-ids-matching-target + db:get-run-info + db:get-run-name-from-id + db:get-run-record-ids + db:get-run-state + db:get-run-state-status + db:get-run-stats + db:get-run-status + db:get-run-times + db:get-runs + db:get-runs-by-patt + db:get-runs-cnt-by-patt + db:get-steps-data + db:get-steps-for-test + db:get-steps-info-by-id + db:get-target + db:get-targets + db:get-test-state-status-by-id + db:get-test-times + db:get-testinfo-state-status + db:get-tests-for-run + db:get-tests-for-run-mindata + db:get-tests-for-run-state-status + db:get-tests-tags + db:get-toplevels-and-incompletes + db:get-var + db:have-incompletes? + db:inc-var + db:initialize-main-db + db:insert-run + db:insert-test + db:lock/unlock-run + db:login + db:read-test-data + db:read-test-data-varpatt + db:register-run + db:set-run-state-status + db:set-run-status + db:set-state-status-and-roll-up-run + db:set-var + db:simple-get-runs + db:test-get-archive-block-info + db:test-get-logfile-info + db:test-get-paths-matching-keynames-target-new + db:test-get-records-for-index-file + db:test-get-rundir-from-test-id + db:test-get-top-process-pid + db:test-set-archive-block-id + db:test-set-state-status + db:test-set-top-process-pid + db:test-toplevel-num-items + db:testmeta-add-record + db:testmeta-get-record + db:testmeta-update-field + db:teststep-set-status! + db:top-test-set-per-pf-counts + db:update-run-event_time + db:update-run-stats + db:update-tesdata-on-repilcate-db + tasks:add + tasks:find-task-queue-records + tasks:get-last + tasks:set-state-given-param-key + + *db-stats* + dbmod:nfs-get-dbstruct + *db-stats-mutex* + + db:get-header + db:get-rows + db:get-changed-run-ids + + db:set-sync + db:setup + db:get-access-mode + db:test-record-fields + + db:logpro-dat->csv + std-exit-procedure + ) (import scheme) (cond-expand (chicken-4 @@ -79,11 +230,11 @@ dbfile debugprint mtmod ) -(include "common_records.scm") +;; (include "common_records.scm") ;; (include "db_records.scm") ;; (include "key_records.scm") (include "run_records.scm") (define *number-of-writes* 0) @@ -1401,62 +1552,62 @@ (hash-table-set! sync-durations (conc srcfile ".db") (- (current-milliseconds) start-time))) (debug:print-info 2 *default-log-port* "skipping delta sync. " srcfile " is up to date")))) dbfiles)) data-synced)) -;; Sync all changed db's -;; -(define (db:tmp->megatest.db-sync dbstruct run-id last-update) - (let* ((subdbs (hash-table-values (dbr:dbstruct-subdbs dbstruct))) - (res '())) - (for-each - (lambda (subdb) - (let* ((mtdb (dbr:subdb-mtdbdat subdb)) - (tmpdb (db:get-subdb dbstruct run-id)) - (refndb (dbr:subdb-refndb subdb)) - (newres (db:sync-tables (db:sync-all-tables-list (db:get-keys dbstruct)) last-update tmpdb refndb mtdb))) - ;; (stack-push! (dbr:subdb-dbstack subdb) tmpdb) - ;; BUG: verify this is really needed - (dbfile:add-dbdat dbstruct run-id tmpdb) - (set! res (cons newres res)))) - subdbs) - res)) +;; ;; Sync all changed db's +;; ;; +;; (define (db:tmp->megatest.db-sync dbstruct run-id last-update) +;; (let* ((subdbs (hash-table-values (dbr:dbstruct-subdbs dbstruct))) +;; (res '())) +;; (for-each +;; (lambda (subdb) +;; (let* ((mtdb (dbr:subdb-mtdbdat subdb)) +;; (tmpdb (db:get-subdb dbstruct run-id)) +;; (refndb (dbr:subdb-refndb subdb)) +;; (newres (db:sync-tables (db:sync-all-tables-list (db:get-keys dbstruct)) last-update tmpdb refndb mtdb))) +;; ;; (stack-push! (dbr:subdb-dbstack subdb) tmpdb) +;; ;; BUG: verify this is really needed +;; (dbfile:add-dbdat dbstruct run-id tmpdb) +;; (set! res (cons newres res)))) +;; subdbs) +;; res)) ;;;; run-ids ;; if #f use *db-local-sync* : or 'local-sync-flags ;; if #t use timestamps : or 'timestamps ;; ;; NB// no-sync-db is the db handle, not a flag! ;; -(define (db:sync-to-megatest.db dbstruct #!key (no-sync-db #f)) - (let* ((start-time (current-seconds)) - (last-full-update (if no-sync-db - (db:no-sync-get/default no-sync-db "LAST_FULL_UPDATE" 0) - 0)) - (full-sync-needed (> (- start-time last-full-update) 3600)) ;; every hour do a full sync - (last-update (if full-sync-needed - 0 - (if no-sync-db - (db:no-sync-get/default no-sync-db "LAST_UPDATE" 0) - 0))) ;; (or (db:get-var dbstruct "LAST_UPDATE") 0)) - (sync-needed (> (- start-time last-update) 6)) - (res (if (or sync-needed ;; don't sync if a sync already occurred in the past 6 seconds - full-sync-needed) - (begin - (if no-sync-db - (begin - (if full-sync-needed (db:no-sync-set no-sync-db "LAST_FULL_UPDATE" start-time)) - (db:no-sync-set no-sync-db "LAST_UPDATE" start-time))) - (db:tmp->megatest.db-sync dbstruct last-update)) - 0)) - (sync-time (- (current-seconds) start-time))) - (debug:print-info 3 *default-log-port* "Sync of newdb to olddb completed in " sync-time " seconds pid="(current-process-id)) - (if (common:low-noise-print 30 "sync new to old") - (if sync-needed - (debug:print-info 0 *default-log-port* "Sync of " res " records from newdb to olddb completed in " sync-time " seconds pid="(current-process-id)) - (debug:print-info 0 *default-log-port* "No sync needed, last updated " (- start-time last-update) " seconds ago"))) - res)) +;; (define (db:sync-to-megatest.db dbstruct #!key (no-sync-db #f)) +;; (let* ((start-time (current-seconds)) +;; (last-full-update (if no-sync-db +;; (db:no-sync-get/default no-sync-db "LAST_FULL_UPDATE" 0) +;; 0)) +;; (full-sync-needed (> (- start-time last-full-update) 3600)) ;; every hour do a full sync +;; (last-update (if full-sync-needed +;; 0 +;; (if no-sync-db +;; (db:no-sync-get/default no-sync-db "LAST_UPDATE" 0) +;; 0))) ;; (or (db:get-var dbstruct "LAST_UPDATE") 0)) +;; (sync-needed (> (- start-time last-update) 6)) +;; (res (if (or sync-needed ;; don't sync if a sync already occurred in the past 6 seconds +;; full-sync-needed) +;; (begin +;; (if no-sync-db +;; (begin +;; (if full-sync-needed (db:no-sync-set no-sync-db "LAST_FULL_UPDATE" start-time)) +;; (db:no-sync-set no-sync-db "LAST_UPDATE" start-time))) +;; (db:tmp->megatest.db-sync dbstruct run-id last-update)) +;; 0)) +;; (sync-time (- (current-seconds) start-time))) +;; (debug:print-info 3 *default-log-port* "Sync of newdb to olddb completed in " sync-time " seconds pid="(current-process-id)) +;; (if (common:low-noise-print 30 "sync new to old") +;; (if sync-needed +;; (debug:print-info 0 *default-log-port* "Sync of " res " records from newdb to olddb completed in " sync-time " seconds pid="(current-process-id)) +;; (debug:print-info 0 *default-log-port* "No sync needed, last updated " (- start-time last-update) " seconds ago"))) +;; res)) (define (db:initialize-main-db db #!key (launch-setup #f)) (when (not *configinfo*) (if launch-setup @@ -3056,11 +3207,13 @@ #t (lambda (dbdat db) (delproc db))) (if (and (file-exists? mtdbfile) (file-write-access? mtdbfile)) - (let* ((db (sqlite3:open-database mtdbfile))) + (let* ((db (sqlite3:open-database mtdbfile)) + (handler (sqlite3:make-busy-timeout 136000))) + (sqlite3:set-busy-handler! db handler) (delproc db) (sqlite3:finalize! db))))) ;; ;; 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