Index: tcp-transportmod.scm ================================================================== --- tcp-transportmod.scm +++ tcp-transportmod.scm @@ -151,11 +151,14 @@ run-id))))) (if conn (begin (debug:print-info 2 *default-log-port* "already connected to a server") conn) ;; we are already connected to the server - (let* ((sdat (tt:get-current-server-info ttdat dbfname))) + (let* ((sdats (tt:get-server-info-sorted ttdat dbfname)) + (sdat (if (null? sdats) + #f + (car sdats)))) (match sdat ((host port start-time server-id pid dbfname2 servinffile) (assert (equal? dbfname dbfname2) "FATAL: read server info from wrong file.") (debug:print-info 2 *default-log-port* "no conn - in match servinffile:" servinffile) (let* ((host-port (conc host":"port)) @@ -188,11 +191,11 @@ (if (> (- curr-secs (tt-last-serv-start ttdat)) 10) (begin (tt-last-serv-start-set! ttdat curr-secs) (server-start-proc))) ;; start server if 10 sec since last attempt (thread-sleep! 1) - (debug:print-info 2 *default-log-port* "server ping result was neither running nor starting. Retrying connect") + (debug:print-info 0 *default-log-port* "server ping result was neither running nor starting. Retrying connect") (tt:client-connect-to-server ttdat dbfname run-id testsuite server-start-proc))))))) (else ;; no good server found, if haven't started server in > 5 secs, start another (if (> (- (current-seconds) (tt-last-serv-start ttdat)) 3) ;; BUG - grow this number really do not want to swamp the machine with servers (begin (debug:print-info 0 *default-log-port* "Starting server for "dbfname) @@ -313,13 +316,10 @@ ))))) (begin (thread-sleep! 1) ;; no conn yet set up, give it a rest and try again (tt:handler ttdat cmd run-id params attemptnum readonly-mode dbfname testsuite mtexe server-start-proc))))) -(define (tt:bid-for-servership run-id) - #f) - ;; gets server info and appends path to server file ;; sorts by age, oldest first ;; ;; returns list of (host port startseconds server-id servinfofile) ;; @@ -341,24 +341,10 @@ (debug:print 2 *default-log-port* "SERVER #"count": "(string-intersperse (map conc sorted) ", "))) (set! count (+ count 1))) sorted) sorted)) -(define (tt:get-current-server-info ttdat dbfname) - (assert (tt-areapath ttdat) "FATAL: areapath not set in ttdat.") - ;; - ;; TODO - replace most of below with tt;get-server-info-sorted - ;; - (let* ((areapath (tt-areapath ttdat)) - (sfiles (tt:find-server areapath dbfname)) - (sdats (filter car (map tt:server-get-info sfiles))) ;; first element is #f if the file disappeared while being read - (sorted (sort sdats (lambda (a b) - (< (list-ref a 2)(list-ref b 2)))))) - (if (null? sorted) - #f ;; we'll want to wait until extra servers have exited - (car sorted)))) - (define (tt:send-receive ttdat conn cmd run-id params) (let* ((host-port (tt-conn-host-port conn)) ;; (conc (tt-conn-host conn)":"(tt-conn-port conn))) (host (tt-conn-host conn)) (port (tt-conn-port conn)) (dat (list cmd run-id params #f))) ;; no meta data yet @@ -481,10 +467,11 @@ ;; (define (tt:start-server areapath run-id dbfname-in handler keys) (assert areapath "FATAL: areapath not provided for tt:start-server") (let* ((ttdat (make-tt areapath: areapath)) (dbfname (or dbfname-in (dbmod:run-id->dbfname run-id)))) + (set! *server-info* ttdat) (let* ((dbstruct (dbmod:open-dbmoddb areapath run-id dbfname (dbfile:db-init-proc) keys))) (tt-handler-set! ttdat (handler dbstruct)) (let* ((servinf-created #f) (tcp-thread (make-thread (lambda () @@ -570,10 +557,11 @@ (exit))))) ;; create a servinfo file start keep-running (tt:create-server-registration-file ttdat dbfname) (procinf-status-set! *procinf* "running") + (tt-state-set! ttdat 'running) (dbfile:with-no-sync-db nosyncdbpath (lambda (nsdb) (dbfile:insert-or-update-process nsdb *procinf*))) (thread-start! run-thread)