Index: http-transportmod.scm ================================================================== --- http-transportmod.scm +++ http-transportmod.scm @@ -95,10 +95,15 @@ ;; (use spiffy uri-common intarweb http-client spiffy-request-vars intarweb spiffy-directory-listing) ;; ;; Configurations for server (tcp-buffer-size 2048) (max-connections 2048) + +(defstruct sdat + host + port + uuid) (define (http-transport:make-server-url hostport) (if (not hostport) #f (conc "http://" (car hostport) ":" (cadr hostport)))) @@ -221,11 +226,11 @@ (http-transport:try-start-server ipaddrstr (portlogger:open-run-close portlogger:find-port))) (begin (print "ERROR: Tried and tried but could not start the server")))) ;; any error in following steps will result in a retry - (set! *server-info* (list ipaddrstr portnum)) + (set! *server-info* (make-sdat host: ipaddrstr port: portnum)) (debug:print 0 *default-log-port* "INFO: Trying to start server on " ipaddrstr ":" portnum) ;; This starts the spiffy server ;; NEED WAY TO SET IP TO #f TO BIND ALL ;; (start-server bind-address: ipaddrstr port: portnum) (if config-hostname ;; this is a hint to bind directly @@ -457,16 +462,18 @@ (let* ((pkt-dat `((host . ,host) (port . ,port) (servkey . ,servkey) (pid . ,(current-process-id)) (ipaddr . ,ipaddr) - (dbpath . ,dbpath)))) - (write-alist->pkt - pkts-dir - pkt-dat - pktspec: pkt-spec - ptype: 'server))) + (dbpath . ,dbpath))) + (uuid (write-alist->pkt + pkts-dir + pkt-dat + pktspec: pkt-spec + ptype: 'server))) + (debug:print 0 *default-log-port* "Server on "host":"port" registered in pkt "uuid) + uuid)) ;; ya, fake it for now ;; (define (register-server-in-db db-file) #t) @@ -599,23 +606,33 @@ (not changed) (> (- (current-seconds) start-time) 2)) (begin (debug:print-info 0 *default-log-port* "Received server alive signature, now attempting to lock in server") ;; create a server pkt in *toppath*/.meta/srvpkts - - (register-server pkts-dir *srvpktspec* (get-host-name) - (cadr sdat) server-key (car sdat) db-file) + + ;; TODO: + ;; 1. change sdat to stuct + ;; 2. add uuid to struct + ;; 3. update uuid in sdat here + ;; + (sdat-uuid-set! sdat + (register-server + pkts-dir *srvpktspec* + (get-host-name) + (sdat-port sdat) server-key + (sdat-host sdat) db-file)) ;; now read pkts and see if we are a contender (let* ((all-pkts (get-all-server-pkts pkts-dir *srvpktspec*)) (viables (get-viable-servers all-pkts db-file)) (best-srv (get-best-candidate viables db-file)) (best-srv-key (if best-srv (alist-ref 'servkey best-srv) #f))) + (debug:print 0 *default-log-port* "best-srv-key: "best-srv-key", server-key: "server-key) ;; am I the best-srv, compare server-keys to know (if (and (equal? best-srv-key server-key) (register-server-in-db db-file)) - (if (db:get-iam-server-lock *dbstruct-db* run-id) + (if (db:get-iam-server-lock *dbstruct-db* *toppath* run-id) (debug:print 0 *default-log-port* "I'm the server!") (bdat-time-to-exit-set! *bdat* #t))) ;; nope, we are not needed, exit when can do sdat)) (begin (debug:print-info 0 *default-log-port* "Still waiting, last-sdat=" last-sdat) @@ -673,11 +690,12 @@ ;; Check that iface and port have not changed (can happen if server port collides) (mutex-lock! *heartbeat-mutex*) (set! sdat *server-info*) (mutex-unlock! *heartbeat-mutex*) - (if (not (equal? sdat (list iface port))) + (if (or (not (equal? (sdat-host sdat) iface)) + (not (equal? (sdat-port sdat) port))) (let ((new-iface (car sdat)) (new-port (cadr sdat))) (debug:print-info 0 *default-log-port* "WARNING: interface changed, refreshing iface and port info") (set! iface new-iface) (set! port new-port) Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -809,11 +809,11 @@ ;; this segment will run launch:setup only if -log is not set. This is fairly safe as servers are not ;; manually started and thus should never be started in a non-megatest area. Thus no need to handle situation ;; where (launch:setup) returns #f? ;; - (if (or (args:get-arg "-log")(args:get-arg "-server")) ;; redirect the log always when a server + (if (or (args:get-arg "-log")#;(args:get-arg "-server")) ;; redirect the log always when a server (handle-exceptions exn (begin (print "ERROR: Failed to switch to log output. " ((condition-property-accessor 'exn 'message) exn) ", exn=" exn) )