︙ | | | ︙ | |
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
(< (current-seconds) (rmt:conn-expires conn)))
conn
#f)))
(define (rmt:find-main-server apath dbname)
(let* ((pktsdir (get-pkts-dir apath))
(all-srvpkts (get-all-server-pkts pktsdir *srvpktspec*))
(dbpath (conc apath "/" dbname))
(viable-srvs (get-viable-servers all-srvpkts dbpath)))
(get-the-server viable-srvs)))
;; looks for a connection to main
;; connections for other servers happens by requesting from main
;;
(define (rmt:open-main-connection remote apath)
(let* ((dbname (db:run-id->dbname #f))
(the-srv (rmt:find-main-server apath dbname))
(start-main-srv (lambda ()
;; srv not ready, delay a little and try again
(api:run-server-process apath dbname)
(thread-sleep! 2)
(rmt:open-main-connection remote apath) ;; TODO: Add limit to number of tries
)))
(if the-srv ;; yes, we have a server, now try connecting to it
(let* ((srv-addr (server-address the-srv))
(ipaddr (alist-ref 'ipaddr the-srv))
(port (alist-ref 'port the-srv))
(fullpath (db:dbname->path apath dbname))
|
|
|
|
|
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
(< (current-seconds) (rmt:conn-expires conn)))
conn
#f)))
(define (rmt:find-main-server apath dbname)
(let* ((pktsdir (get-pkts-dir apath))
(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)))
;; looks for a connection to main
;; connections for other servers happens by requesting from main
;;
(define (rmt:open-main-connection remote apath)
(let* ((dbname (db:run-id->dbname #f))
(the-srv (rmt:find-main-server apath dbname))
(start-main-srv (lambda ()
;; srv not ready, delay a little and try again
(api:run-server-process apath dbname)
(thread-sleep! 4)
(rmt:open-main-connection remote apath) ;; TODO: Add limit to number of tries
)))
(if the-srv ;; yes, we have a server, now try connecting to it
(let* ((srv-addr (server-address the-srv))
(ipaddr (alist-ref 'ipaddr the-srv))
(port (alist-ref 'port the-srv))
(fullpath (db:dbname->path apath dbname))
|
︙ | | | ︙ | |
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
res))
;; no conn yet, start it up
(begin
(rmt:general-open-connection remote apath dbname)
(rmt:send-receive-real remote apath dbname rid cmd params)))))
;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed
;; sometime in the future
;;
(define (rmt:send-receive-server-start remote apath dbname)
(let* ((conn (rmt:get-connection remote apath dbname)))
(assert conn "FATAL: Unable to connect to db "apath"/"dbname)
(let* (;; (host (rmt:conn-ipaddr conn))
;; (port (rmt:conn-port conn))
;; (payload (sexpr->string params))
|
|
>
>
>
|
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
res))
;; no conn yet, start it up
(begin
(rmt:general-open-connection remote apath dbname)
(rmt:send-receive-real remote apath dbname rid cmd params)))))
;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed
;; sometime in the future.
;;
;; Purpose - call the main.db server and request a server be started
;; for the given area path and dbname
;;
(define (rmt:send-receive-server-start remote apath dbname)
(let* ((conn (rmt:get-connection remote apath dbname)))
(assert conn "FATAL: Unable to connect to db "apath"/"dbname)
(let* (;; (host (rmt:conn-ipaddr conn))
;; (port (rmt:conn-port conn))
;; (payload (sexpr->string params))
|
︙ | | | ︙ | |
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
|
(loop (cdr tail)
(if (equal? dbpath (alist-ref 'dbpath spkt))
(cons spkt res)
res))))))
;; from viable servers get one that is alive and ready
;;
(define (get-the-server serv-pkts)
(let loop ((tail serv-pkts))
(if (null? tail)
#f
(let* ((spkt (car tail))
(host (alist-ref 'ipaddr spkt))
(port (alist-ref 'port spkt))
(dbpth (alist-ref 'dbpath spkt))
(addr (server-address spkt)))
(if (server-ready? host port dbpth)
spkt
(loop (cdr tail)))))))
;; am I the "first" in line server? I.e. my D card is smallest
;; use Z card as tie breaker
;;
(define (get-best-candidate serv-pkts dbpath)
|
|
|
|
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
|
(loop (cdr tail)
(if (equal? dbpath (alist-ref 'dbpath spkt))
(cons spkt res)
res))))))
;; from viable servers get one that is alive and ready
;;
(define (get-the-server apath serv-pkts)
(let loop ((tail serv-pkts))
(if (null? tail)
#f
(let* ((spkt (car tail))
(host (alist-ref 'ipaddr spkt))
(port (alist-ref 'port spkt))
(dbpth (alist-ref 'dbpath spkt))
(addr (server-address spkt)))
(if (server-ready? host port (conc apath"/"dbpth))
spkt
(loop (cdr tail)))))))
;; am I the "first" in line server? I.e. my D card is smallest
;; use Z card as tie breaker
;;
(define (get-best-candidate serv-pkts dbpath)
|
︙ | | | ︙ | |
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
|
(tries 0))
;; first we verify port and interface, update *server-info* in need be.
(cond
((> tries num-tries-allowed)
(debug:print 0 *default-log-port* "http-transport:keep-running, giving up after trying for several minutes.")
(exit 1))
((not *server-info*)
(thread-sleep! 1.5)
(loop *server-info* (+ tries 1)))
((not sdat)
(debug:print 0 *default-log-port* "http-transport:keep-running, impossible, should never get here.")
(thread-sleep! 1.5)
(loop *server-info* (+ tries 1)))
((or (not (equal? (servdat-host sdat)(servdat-host *server-info*)))
(not (equal? (servdat-port sdat)(servdat-port *server-info*))))
(debug:print-info 0 *default-log-port* "WARNING: interface changed, refreshing iface and port info")
(thread-sleep! 1.5)
(loop *server-info* (+ tries 1)))
(else
(if (not *server-id*)(set! *server-id* (server:mk-signature)))
(debug:print 0 *default-log-port*
"SERVER STARTED: " (servdat-host *server-info*)
":" (servdat-port *server-info*)
" AT " (current-seconds) " server-id: " *server-id*)
|
|
|
|
|
|
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
|
(tries 0))
;; first we verify port and interface, update *server-info* in need be.
(cond
((> tries num-tries-allowed)
(debug:print 0 *default-log-port* "http-transport:keep-running, giving up after trying for several minutes.")
(exit 1))
((not *server-info*)
(thread-sleep! 0.25)
(loop *server-info* (+ tries 1)))
((not sdat)
(debug:print 0 *default-log-port* "http-transport:keep-running, still no interface, tries="tries)
(thread-sleep! 0.25)
(loop *server-info* (+ tries 1)))
((or (not (equal? (servdat-host sdat)(servdat-host *server-info*)))
(not (equal? (servdat-port sdat)(servdat-port *server-info*))))
(debug:print-info 0 *default-log-port* "WARNING: interface changed, refreshing iface and port info")
(thread-sleep! 0.25)
(loop *server-info* (+ tries 1)))
(else
(if (not *server-id*)(set! *server-id* (server:mk-signature)))
(debug:print 0 *default-log-port*
"SERVER STARTED: " (servdat-host *server-info*)
":" (servdat-port *server-info*)
" AT " (current-seconds) " server-id: " *server-id*)
|
︙ | | | ︙ | |
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
|
;; Call this to start the actual server
;;
;; all routes though here end in exit ...
;;
;; This is the point at which servers are started
;;
(define (rmt:launch dbname)
;;(let* ((tmp-area (common:get-db-tmp-area))
;; (server-start (conc tmp-area "/.server-start"))
;; (server-started (conc tmp-area "/.server-started"))
;; (start-time (common:lazy-modification-time server-start))
;; (started-time (common:lazy-modification-time server-started))
;; (server-starting (< start-time started-time)) ;; if start-time is less than started-time then a server is still starting
;; (start-time-old (> (- (current-seconds) start-time) 5))
|
|
|
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
|
;; Call this to start the actual server
;;
;; all routes though here end in exit ...
;;
;; This is the point at which servers are started
;;
(define (rmt:server-launch dbname)
;;(let* ((tmp-area (common:get-db-tmp-area))
;; (server-start (conc tmp-area "/.server-start"))
;; (server-started (conc tmp-area "/.server-started"))
;; (start-time (common:lazy-modification-time server-start))
;; (started-time (common:lazy-modification-time server-started))
;; (server-starting (< start-time started-time)) ;; if start-time is less than started-time then a server is still starting
;; (start-time-old (> (- (current-seconds) start-time) 5))
|
︙ | | | ︙ | |