Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -98,17 +98,17 @@ ;; (define (rmt:send-receive cmd rid params #!key (attemptnum 1)(area-dat #f)) ;; start attemptnum at 1 so the modulo below works as expected (let* ((alldat *alldat*) (areapath (alldat-areapath alldat)) (dbtype (if (or (not rid)(< rid 1)) ;; this is the criteria for "main.db" - 'main 'runs)) - (dbfname (if (eq? dbtype 'main) + "main" "runs")) + (dbfname (if (equal? dbtype "main") "main.db" (conc rid ".db"))) (dbfile (conc areapath "/.db/" dbfname)) - (udata (alldat-ulexdat alldat)) - (ulexconn (rmt:connect alldat dbfname dbtype))) ;; ulexconn is our new *runremote*, it is a dbowner struct < pdat lastrefresh > + (ulexconn (rmt:connect alldat dbfname dbtype)) ;; ulexconn is our new *runremote*, it is a dbowner struct < pdat lastrefresh > + (udata (alldat-ulexdat alldat))) (ulex:remote-request udata ulexconn 'immediate dbfile 'execute rid params))) ;; need to call this on the other side ;; (api:execute-requests dbstruct-local (vector (symbol->string cmd) params)))) #;(with-input-from-string Index: ulex/ulex.scm ================================================================== --- ulex/ulex.scm +++ ulex/ulex.scm @@ -79,23 +79,22 @@ (begin (setup-as-captain udata) ;; this saves the thread to captain-thread and starts the thread (setup))))) ;; connect to a specific dbfile -;; - if already connected - return the pdat +;; - if already connected - return the dbowner host-port ;; - ask the captain who to talk to for this db -;; - put the entry in the dbowners hash +;; - put the entry in the dbowners hash as dbfile => host-port ;; (define (connect udata dbfname dbtype) (or (hash-table-ref/default (udat-dbowners udata) dbfname #f) (let-values (((success dbowner-host-port)(get-db-owner udata dbfname dbtype))) (if success - (let* ((pdat (udat-get-peer udata dbowner-host-port)) - (dbowner (make-dbowner pdat: pdat))) + (begin ;; just clobber the record, this is the new data no matter what - (hash-table-set! (udat-dbowners udata) dbowner-host-port dbowner) - dbowner) + (hash-table-set! (udat-dbowners udata) dbfname dbowner-host-port) + dbowner-host-port) #f)))) ;; returns: success pingtime ;; ;; NOTE: causes the callee to store the info on this host along with the dbs this host currently owns @@ -155,23 +154,20 @@ (let* ((result (proc dbrec procparam data))) result))) ;; remote-request - send to remote to process in process-request ;; uconn comes from a call to connect and can be used instead of calling connect again -;; uconn is somewhat redundant with dbname but it tells us what host-port to call -;; uconn is a dbowner struct < pdat lastupdate > +;; uconn is the host-port to call ;; we send dbname to the worker so they know which file to open ;; data must be a string with no newlines, it will be handed to the proc ;; at the remote site unchanged. It is up to the user to encode/decode it's contents ;; ;; rtype: immediate, read-only, normal, low-priority ;; (define (remote-request udata uconn rtype dbname prockey procparam data) - (let* ((cookie (make-cookie)) - (pdat (dbowner-pdat uconn)) - (host-port (peer-addr-port pdat))) - (send-receive udata host-port rtype cookie data `(,prockey procparam)))) + (let* ((cookie (make-cookie udata))) + (send-receive udata uconn rtype cookie data `(,prockey procparam)))) (define (ulex-open-db udata dbname) #f) ;;====================================================================== @@ -300,11 +296,11 @@ (handlerkey #f) (qrykey #f) (data #f) (start (current-milliseconds))) -(defstruct dbowner +#;(defstruct dbowner (pdat #f) (last-update (current-seconds))) ;;====================================================================== ;; Captain functions @@ -416,11 +412,11 @@ ;;====================================================================== ;; server primitives ;;====================================================================== (define (make-cookie udata) - (let ((newcnum (+ (udat-cnum udata)))) + (let ((newcnum (+ (udat-cnum udata) 1))) (udat-cnum-set! udata newcnum) (conc (udat-my-address udata) ":" (udat-my-port udata) "-" (udat-my-pid udata) "-" newcnum))) @@ -538,11 +534,11 @@ (val (if proc (proc) "gotping")) (peer (make-peer addr-port: host-port pid: pid)) (dbshash (udat-dbowners udata))) (peer-dbs-set! peer params) ;; params for ping is list of dbs owned by pinger (for-each (lambda (dbfile) - (hash-table-set! dbshash dbfile host-port)) + (hash-table-set! dbshash dbfile host-port)) ;; WRONG? params) ;; register each db in the dbshash (if (not (hash-table-exists? (udat-peers udata) host-port)) (hash-table-set! (udat-peers udata) host-port peer)) ;; save the details of this caller in peers qrykey)) ;; End of ping ((goodbye) @@ -567,17 +563,17 @@ ;; they are still alive and then return that host:port. ;; if no handler found or if the ping fails pick from peers the oldest that ;; is managing the fewest dbs (match params ((dbfile dbtype) - (let* ((curr-owner (hash-table-ref/default (udat-dbowners udata) dbfile #f)) - (owner-host-port (and curr-owner (peer-addr-port curr-owner)))) + (let* ((owner-host-port (hash-table-ref/default (udat-dbowners udata) dbfile #f))) (if owner-host-port (conc qrykey " " owner-host-port) (let* ((pdat (or (hash-table-ref/default (udat-peers udata) host-port #f) ;; no owner - caller gets to own it! (make-peer addr-port: host-port pid: pid dbs: `(,dbfile))))) - (hash-table-set! (udat-dbowners udata) dbfile pdat) + (hash-table-set! (udat-peers udata) host-port pdat) + (hash-table-set! (udat-dbowners udata) dbfile host-port) (conc qrykey " " host-port))))) (else (conc qrykey " BADDATA")))) ;; for work items: ;; handler is one of; immediate, read-only, read-write, high-priority ((immediate read-only normal low-priority) ;; do this work immediately @@ -590,11 +586,12 @@ ((immediate read-only) (process-request udata pdat dbfile qrykey prockey procparam data)) ((normal low-priority) ;; split off later and add logic to support low priority (add-to-work-queue udata pdat dbfile qrykey prockey procparam data)) (else - #f)))))) + #f))) + (else (print "ERROR: params=" params))))) (else ;; (add-to-work-queue udata (get-peer-dat udata host-port) handlerkey qrykey data) #f))) (else (print "BAD DATA? controldat=" controldat " data=" data)