Index: debugprint.scm ================================================================== --- debugprint.scm +++ debugprint.scm @@ -115,11 +115,13 @@ (lambda () ;; (if *logging* ;; (db:log-event (apply conc params)) (apply print params) (debug:handle-remote-logging params) - )))) ;; ) + ))) + #t ;; only here to make remote stuff happy. It'd be nice to fix that ... + ) (define (debug:print-error n e . params) ;; normal print (if (debug:debug-mode n) (with-output-to-port (if (port? e) e (current-error-port)) Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -202,10 +202,14 @@ (all-srvpkts (get-all-server-pkts pktsdir *srvpktspec*)) ;; (dbpath (conc apath "/" dbname)) (viable-srvs (get-viable-servers all-srvpkts dbname))) (get-the-server apath viable-srvs))) + +(define *connstart-mutex* (make-mutex)) +(define *last-main-start* 0) + ;; looks for a connection to main, returns if have and not exired ;; creates new otherwise ;; ;; connections for other servers happens by requesting from main ;; @@ -215,17 +219,22 @@ (let* ((fullpath (db:dbname->path apath "/.db/main.db")) (conns (remotedat-conns remdat)) (conn (hash-table-ref/default conns fullpath #f))) ;; TODO - create call for this (if (and conn ;; conn is NOT a socket, just saying ... (< (current-seconds) (conndat-expires conn))) - conn ;; we are current and good to go - we'll deal elsewhere with a server that was killed or died + #t ;; we are current and good to go - we'll deal elsewhere with a server that was killed or died ;; Below we will find or create and connect to main (let* ((dbname (db:run-id->dbname #f)) (the-srv (rmt:find-main-server apath dbname)) (start-main-srv (lambda () ;; call IF there is no the-srv found - (api:run-server-process apath dbname) - (thread-sleep! 1) + (mutex-lock! *connstart-mutex*) + (if (> (- (current-seconds) *last-main-start*) 5) ;; at least four seconds since last attempt to start main server + (begin + (api:run-server-process apath dbname) + (set! *last-main-start* (current-seconds)) + (thread-sleep! 1))) + (mutex-unlock! *connstart-mutex*) (rmt:open-main-connection remdat apath) ;; TODO: Add limit to number of tries ))) (if (not the-srv) ;; have server, try connecting to it (start-main-srv) (let* ((srv-addr (server-address the-srv)) ;; need serv @@ -245,12 +254,13 @@ srvpkt: the-srv srvkey: srvkey ;; generated by rmt:get-signature on the server side lastmsg: (current-seconds) expires: (+ (current-seconds) 60) ;; this needs to be gathered during the ping ))) - (hash-table-set! conns fullpath new-the-srv))))))) - + (hash-table-set! conns fullpath new-the-srv))) + #t)))) + ;; NB// remdat is a remotedat struct ;; (define (rmt:general-open-connection remdat apath dbname #!key (num-tries 5)) (assert (not (equal? dbname ".db/main.db")) "ERROR: general-open-connection should never be called with main as the db") (let* ((mdbname (db:run-id->dbname #f)) @@ -305,14 +315,12 @@ (else (debug:print-info 0 *default-log-port* "return data from starting server did not match host port servkey pid ipaddr apath dbname " res))) res) (begin (debug:print-info 0 *default-log-port* "Unexpected result: " res) - res)))))) - - - ))) + res))))))) + #t)) ;;====================================================================== ;; FOR DEBUGGING SET TO #t ;; (define *localmode* #t) Index: tests/unittests/basicserver.scm ================================================================== --- tests/unittests/basicserver.scm +++ tests/unittests/basicserver.scm @@ -45,20 +45,20 @@ ;; api:run-server-process ;; rmt:run ;; rmt:try-start-server ) -(test #f #t (rmt:remote? (let ((r (make-rmt:remote))) - (set! *rmt:remote* r) - r))) -(test #f #f (rmt:get-conn *rmt:remote* *toppath* ".db/main.db")) +(test #f #t (remotedat? (let ((r (make-remotedat))) + (set! *remotedat* r) + r))) +(test #f #f (rmt:get-conn *remotedat* *toppath* ".db/main.db")) (test #f #f (rmt:find-main-server *toppath* ".db/main.db")) -(test #f #t (rmt:open-main-connection *rmt:remote* *toppath*)) -(pp (hash-table->alist (rmt:remote-conns *rmt:remote*))) -(test #f #t (rmt:conn? (rmt:get-conn *rmt:remote* *toppath* ".db/main.db"))) +(test #f #t (rmt:open-main-connection *remotedat* *toppath*)) +(pp (hash-table->alist (remotedat-conns *remotedat*))) +(test #f #t (conndat? (rmt:get-conn *remotedat* *toppath* ".db/main.db"))) -(define *main* (rmt:get-conn *rmt:remote* *toppath* ".db/main.db")) +(define *main* (rmt:get-conn *remotedat* *toppath* ".db/main.db")) ;; (for-each (lambda (tdat) ;; (test #f tdat (loop-test (rmt:conn-ipaddr *main*) ;; (rmt:conn-port *main*) tdat))) ;; (list 'a @@ -68,13 +68,13 @@ (define *db* (db:setup ".db/main.db")) ;; these let me cut and paste from source easily (define apath *toppath*) (define dbname ".db/2.db") -(define remote *rmt:remote*) +(define remote *remotedat*) (define keyvals '(("SYSTEM" "a")("RELEASE" "b"))) (test #f '() (string->sexpr "()")) (test #f 'server-started (api:execute-requests *db* 'get-server (list *toppath* ".db/2.db"))) (set! *dbstruct-db* #f) (exit) Index: tests/unittests/server.scm ================================================================== --- tests/unittests/server.scm +++ tests/unittests/server.scm @@ -52,31 +52,34 @@ (define *db* (db:setup ".db/main.db")) ;; these let me cut and paste from source easily (define apath *toppath*) (define dbname ".db/2.db") -(define remote *rmt:remote*) +(define remote *remotedat*) (define keyvals '(("SYSTEM" "a")("RELEASE" "b"))) (test #f #t (rmt:open-main-connection remote apath)) -(test #f #t (rmt:conn? (rmt:get-conn *rmt:remote* *toppath* ".db/main.db"))) -(test #f #t (rmt:conn? (rmt:get-conn *rmt:remote* *toppath* ".db/main.db"))) -(test #f 'server-started (rmt:send-receive-real *rmt:remote* *toppath* ".db/main.db" 'get-server `(,apath ,dbname))) +(test #f #t (conndat? (rmt:get-conn *remotedat* *toppath* ".db/main.db"))) +(test #f #t (conndat? (rmt:get-conn *remotedat* *toppath* ".db/main.db"))) +(test #f ".db/2.db" (list-ref (rmt:send-receive-real *remotedat* *toppath* ".db/main.db" 'get-server `(,apath ,dbname)) + 6)) (thread-sleep! 2) -(test #f #t (list? (rmt:general-open-connection *rmt:remote* *toppath* ".db/2.db"))) +(test #f #t (rmt:general-open-connection *remotedat* *toppath* ".db/2.db")) + +(exit) (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 #f 1 (rmt:send-receive 'register-run 1 (list keyvals "run1" "new" "n/a" "justme" #f))) (test #f 2 (rmt:register-run keyvals "run2" "new" "n/a" "justme" #f)) -;; (test #f 2 (rmt:deregister-server *rmt:remote* *toppath* iface port server-key dbname +;; (test #f 2 (rmt:deregister-server *remotedat* *toppath* iface port server-key dbname -(test #f 2 (rmt:get-count-servers *rmt:remote* *toppath*)) +(test #f 2 (rmt:get-count-servers *remotedat* *toppath*)) (test #f "run2" (rmt:get-run-name-from-id 2)) ;; (exit)