Index: dbfile.scm ================================================================== --- dbfile.scm +++ dbfile.scm @@ -64,10 +64,12 @@ ;; this is one db per server (inmem #f) ;; handle for the in memory copy (dbfile #f) ;; path to the db file on disk (ondiskdb #f) ;; handle for the on-disk file (dbdat #f) ;; create a dbdat for the downstream calls such as db:with-db + (last-update 0) + (syncback-proc #f) ) ;; NOTE: Need one dbr:subdb per main.db, 1.db ... ;; (defstruct dbr:subdb Index: dbmod.scm ================================================================== --- dbmod.scm +++ dbmod.scm @@ -109,11 +109,14 @@ db)))) (tables (db:sync-all-tables-list keys))) (dbr:dbstruct-inmem-set! dbstruct inmem) (dbr:dbstruct-ondiskdb-set! dbstruct db) (dbr:dbstruct-dbfile-set! dbstruct dbfullname) + (dbr:dbstruct-syncback-proc-set! dbstruct (lambda (last-update) + (dbmod:sync-tables tables last-update inmem db))) (dbmod:sync-tables tables #f db inmem) + (dbr:dbstruct-last-update-set! dbstruct (current-seconds)) ;; should this be offset back in time by one second? dbstruct)) (define (dbmod:close-db dbstruct) ;; do final sync to disk file ;; (do-sync ...) Index: tcp-transportmod.scm ================================================================== --- tcp-transportmod.scm +++ tcp-transportmod.scm @@ -271,11 +271,11 @@ (lambda () (tt:start-tcp-server ttdat)) ;; start the tcp-server which applies handler to incoming data "tcp-server-thread")) (run-thread (make-thread (lambda () - (tt:keep-running ttdat dbfname))))) + (tt:keep-running ttdat dbfname dbstruct))))) (thread-start! tcp-thread) (thread-start! run-thread) (thread-join! run-thread) ;; run thread will exit on timeout or other conditions ;; ;; set a flag here to tell tcp-thread to stop running @@ -291,21 +291,26 @@ (exit))) (begin (debug:print 0 *default-log-port* "INFO: found server(s) already running for db "dbfname", "(string-intersperse servers ",")" Exiting.") (exit))))) -(define (tt:keep-running ttdat dbfname) +(define (tt:keep-running ttdat dbfname dbstruct) ;; verfiy conn for ready ;; listener socket has been started by this stage (thread-sleep! 1) (let loop ((count 0)) (if (> count 60) (begin (debug:print 0 *default-log-port* "FATAL: Could not start a tcp server, giving up.") (exit 1)) (if (not (tt-port ttdat)) ;; no connection yet - (begin + (let* ((last-update (dbr:dbstruct-last-update dbstruct)) + (curr-secs (current-seconds))) + (if (> (- curr-secs last-update) 3) ;; every 3-4 seconds + (begin + ((dbr:dbstruct-syncback-proc) last-update) + (dbr:dbstruct-last-update-set! curr-secs))) (thread-sleep! 1) (loop (+ count 1)))))) (tt:create-server-registration-file ttdat dbfname) ;; now start watching the last-access, if it hasn't been touched