Index: dbmod.scm ================================================================== --- dbmod.scm +++ dbmod.scm @@ -421,11 +421,11 @@ (db (dbr:dbdat-db dbdat)) (inmem (dbr:dbdat-inmem dbdat)) (start-t (current-seconds)) (last-update (dbr:dbdat-last-write dbdat)) (last-sync (dbr:dbdat-last-sync dbdat))) - (debug:print-info 4 *default-log-port* "Syncing for dbfile: " dbfile) + (debug:print-info 0 *default-log-port* "Syncing for dbfile: " dbfile) (mutex-lock! *db-multi-sync-mutex*) (let* ((update_info (cons (if force-sync 0 last-update) "last_update")) (need-sync (or force-sync (>= last-update last-sync)))) (if need-sync (db:sync-tables (db:sync-all-tables-list) update_info inmem db) Index: launchmod.scm ================================================================== --- launchmod.scm +++ launchmod.scm @@ -2289,13 +2289,16 @@ (dbfile (args:get-arg "-db")) (apath *toppath*)) (let loop () (thread-sleep! 5) ;; add control / setting for this (if am-server - (if (not *dbstruct-db*) + (if (not *dbstruct-db*) ;; skip syncing until db is setup (loop) - (db:sync-inmem->disk *dbstruct-db* *toppath* dbfile)))))) + (begin + (debug:print-info 0 *default-log-port* "syncing "apath" "dbfile" at "(current-seconds)) + (db:sync-inmem->disk *dbstruct-db* apath dbfile) + (loop))))))) ;; ;; (let ((dbstruct ;; (debug:print-info 13 *default-log-port* "after db:setup with dbstruct=" dbstruct) ;; (cond Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -1452,37 +1452,51 @@ (rmt:print-db-stats)) (let ((th1 (make-thread (lambda () ;; thread for cleaning up, give it five seconds (if *server-info* (let ((dbfile (servdat-dbfile *server-info*))) (if dbfile - (begin - + (let* ((am-server (args:get-arg "-server")) + (dbfile (args:get-arg "-db")) + (apath *toppath*)) ;; do a final sync here - - (if (string-match ".*/main.db$" dbfile) - (let ((pkt-file (conc (get-pkts-dir *toppath*) - "/" (servdat-uuid *server-info*) - ".pkt"))) - (debug:print-info 0 *default-log-port* "removing pkt "pkt-file) - (delete-file* pkt-file) - (debug:print-info 0 *default-log-port* "Releasing lock for "dbfile) - (db:with-lock-db (servdat-dbfile *server-info*) - (lambda (dbh dbfile) - (db:release-lock dbh dbfile)))) - (let* ((sdat *server-info*)) ;; we have a run-id server - (rmt:send-receive-real *rmt:remote* *toppath* - (db:run-id->dbname #f) - 'deregister-server - `(,(servdat-uuid sdat) - ,(current-process-id) - ,(servdat-host sdat) ;; iface - ,(servdat-port sdat))))))))) + (debug:print-info 0 *default-log-port* "Doing final sync for "apath" "dbfile" at "(current-seconds)) + (db:sync-inmem->disk *dbstruct-db* apath dbfile) + (if am-server + (if (string-match ".*/main.db$" dbfile) + (let ((pkt-file (conc (get-pkts-dir *toppath*) + "/" (servdat-uuid *server-info*) + ".pkt"))) + (debug:print-info 0 *default-log-port* "removing pkt "pkt-file) + (delete-file* pkt-file) + (debug:print-info 0 *default-log-port* "Releasing lock for "dbfile) + (db:with-lock-db (servdat-dbfile *server-info*) + (lambda (dbh dbfile) + (db:release-lock dbh dbfile)))) + (let* ((sdat *server-info*) ;; we have a run-id server + (host (servdat-host sdat)) + (port (servdat-port sdat)) + (uuid (servdat-uuid sdat))) + (debug:print-info 0 *default-log-port* "deregistering server "host":"port" with uuid "uuid) + #;(rmt:send-receive-real *rmt:remote* *toppath* + (db:run-id->dbname #f) + 'deregister-server + `(,(servdat-uuid sdat) + ,(current-process-id) + ,(servdat-host sdat) ;; iface + ,(servdat-port sdat))) + (rmt:send-receive 'deregister-server #f + `(,(servdat-uuid sdat) + ,(current-process-id) + ,(servdat-host sdat) ;; iface + ,(servdat-port sdat))) + ))))))) ;; (if *dbstruct-db* (db:close-all *dbstruct-db*)) ;; one second allocated (if (bdat-task-db *bdat*) ;; TODO: Check that this is correct for task db (let ((db (cdr (bdat-task-db *bdat*)))) (if (sqlite3:database? db) (begin + (debug:print-info 0 *default-log-port* "Closing down task db "db) (sqlite3:interrupt! db) (sqlite3:finalize! db #t) (bdat-task-db-set! *bdat* #f))))) #;(http-client#close-idle-connections!) (if (not (eq? *default-log-port* (current-error-port))) Index: tests/unittests/server.scm ================================================================== --- tests/unittests/server.scm +++ tests/unittests/server.scm @@ -64,13 +64,21 @@ (test #f #t (list? (rmt:general-open-connection *rmt:remote* *toppath* ".db/2.db"))) (test #f '("SYSTEM" "RELEASE") (rmt:get-keys)) (test #f 1 (rmt:send-receive 'register-run #f (list keyvals "run1" "new" "n/a" "justme" #f))) (print "Got here.") -(test #t 1 (rmt:send-receive 'register-run 1 (list keyvals "run2" "new" "n/a" "justme" #f))) +(trace + rmt:send-receive + rmt:send-receive-real + ) +(test #f 1 (rmt:send-receive 'register-run 1 (list keyvals "run1" "new" "n/a" "justme" #f))) (test #f 1 (rmt:register-run keyvals "run2" "new" "n/a" "justme" #f)) + +(thread-sleep! 5) +(exit) + ;; (delete-file* "logs/1.log") ;; (define run-id 1) ;; (test "setup for run" #t (begin (launch:setup)