Overview
Comment: | wip |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | v1.6584-ck5 |
Files: | files | file ages | folders |
SHA1: |
621ec7fe98de26ddf7fb1de7f92cde2b |
User & Date: | matt on 2021-05-02 22:49:18 |
Other Links: | branch diff | manifest | tags |
Context
2021-05-02
| ||
23:50 | wip check-in: 3c5e874d19 user: matt tags: v1.6584-ck5 | |
22:49 | wip check-in: 621ec7fe98 user: matt tags: v1.6584-ck5 | |
15:41 | wip check-in: 9f8cd866ea user: matt tags: v1.6584-ck5 | |
Changes
Modified commonmod.scm from [91b24e1910] to [b9d002f916].
︙ | ︙ | |||
209 210 211 212 213 214 215 | (define *db-api-call-time* (make-hash-table)) ;; hash of command => (list of times) ;; no sync db (define *no-sync-db* #f) ;; SERVER (define *my-client-signature* #f) (define *transport-type* 'http) ;; override with [server] transport http|rpc|nmsg | > | | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | (define *db-api-call-time* (make-hash-table)) ;; hash of command => (list of times) ;; no sync db (define *no-sync-db* #f) ;; SERVER (define *my-client-signature* #f) (define *transport-type* 'http) ;; override with [server] transport http|rpc|nmsg ;; replaced by *rmt:remote* ;; (define *runremote* #f) ;; if set up for server communication this will hold <host port> ;; (define *max-cache-size* 0) (define *logged-in-clients* (make-hash-table)) (define *server-id* #f) (define *server-info* #f) ;; good candidate for easily convert to non-global ;; (define *time-to-exit* #f) (define *server-run* #t) (define *run-id* #f) |
︙ | ︙ | |||
609 610 611 612 613 614 615 | ((abort) "ABORT") ((skip) "SKIP") (else "FAIL"))) (define (common:logpro-exit-code->test-status exit-code) (status-sym->string (common:logpro-exit-code->status-sym exit-code))) | > > | | | | | | | | | | | | | 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | ((abort) "ABORT") ((skip) "SKIP") (else "FAIL"))) (define (common:logpro-exit-code->test-status exit-code) (status-sym->string (common:logpro-exit-code->status-sym exit-code))) ;; REPLACED BY rmt:remote in rmtmod.scm ;; ;; (defstruct remote ;; (hh-dat #f) ;; (common:get-homehost)) ;; homehost record ( addr . hhflag ) ;; (server-url #f) ;; (server:check-if-running *toppath*) #f)) ;; (server-id #f) ;; (server-info #f) ;; (if *toppath* (server:check-if-running *toppath*) #f)) ;; (last-server-check 0) ;; last time we checked to see if the server was alive ;; (conndat #f) ;; ;; (transport *transport-type*) ;; (server-timeout #f) ;; (server:expiration-timeout)) ;; (force-server #f) ;; (ro-mode #f) ;; (ro-mode-checked #f)) ;; flag that indicates we have checked for ro-mode ;; launching and hosts (defstruct host (reachable #f) (last-update 0) (last-used 0) (last-cpuload 1)) |
︙ | ︙ |
Modified http-transportmod.scm from [1f587f4eee] to [904aac257a].
︙ | ︙ | |||
295 296 297 298 299 300 301 | (set! *http-connections-next-cleanup* (+ (current-seconds) 10)) (mutex-unlock! *http-mutex*)) (define (http-transport:inc-requests-and-prep-to-close-all-connections) (mutex-lock! *http-mutex*) (set! *http-requests-in-progress* (+ 1 *http-requests-in-progress*))) | < < < < | | < | < < < < > | < | | > | > > > | > | | | | | | | | | | | | | | | | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | (set! *http-connections-next-cleanup* (+ (current-seconds) 10)) (mutex-unlock! *http-mutex*)) (define (http-transport:inc-requests-and-prep-to-close-all-connections) (mutex-lock! *http-mutex*) (set! *http-requests-in-progress* (+ 1 *http-requests-in-progress*))) ;; serverdat contains uuid to be used for connection validation ;; ;; NOTE: serverdat must be initialized or created by servdat-init ;; (define (http-transport:send-receive sdat qry-key cmd params #!key (numretries 3)) (let* ((res #f) (success #t) (sparams (with-output-to-string (lambda ()(write params))))) ;; send the data and get the response extract the needed info from ;; the http data and process and return it. (let* ((send-recieve (lambda () (set! res (vector #t ;; success (with-input-from-request (servdat-api-uri sdat) (list (cons 'key qry-key) (cons 'srvid (servdat-uuid sdat)) (cons 'cmd cmd) (cons 'params sparams)) read))))) (time-out (lambda () (thread-sleep! 45) (debug:print 0 *default-log-port* "WARNING: send-receive took more than 45 seconds!!") #f)) (th1 (make-thread send-recieve "with-input-from-request")) (th2 (make-thread time-out "time out"))) (thread-start! th1) (thread-start! th2) (thread-join! th1) (close-idle-connections!) (thread-terminate! th2) (if (string? res) (with-input-from-string res (lambda () read)) res)))) ;; careful closing of connections stored in *runremote* ;; (define (http-transport:close-connections #!key (area-dat #f)) (debug:print-info 0 *default-log-port* "http-transport:close-connections doesn't do anything now!")) ;; (let* ((runremote (or area-dat *runremote*)) ;; (server-dat (if runremote ;; (remote-conndat runremote) ;; #f))) ;; (hash-table-ref/default *runremote* run-id #f))) ;; (if (vector? server-dat) ;; (let ((api-dat (http-transport:server-dat-get-api-uri server-dat))) ;; (handle-exceptions ;; exn ;; (begin ;; (print-call-chain *default-log-port*) ;; (debug:print-error 0 *default-log-port* " closing connection failed with error: " ((condition-property-accessor 'exn 'message) exn) ", exn=" exn)) ;; (close-connection! api-dat) ;; ;;(close-idle-connections!) ;; #t)) ;; #f))) (define (make-http-transport:server-dat)(make-vector 6)) (define (http-transport:server-dat-get-iface vec) (vector-ref vec 0)) (define (http-transport:server-dat-get-port vec) (vector-ref vec 1)) (define (http-transport:server-dat-get-api-uri vec) (vector-ref vec 2)) (define (http-transport:server-dat-get-api-url vec) (vector-ref vec 3)) |
︙ | ︙ | |||
384 385 386 387 388 389 390 | (define (http-transport:server-dat-update-last-access vec) (if (vector? vec) (vector-set! vec 5 (current-seconds)) (begin (print-call-chain (current-error-port)) (debug:print-error 0 *default-log-port* "call to http-transport:server-dat-update-last-access with non-vector!!")))) | | | < < < < < < < < > > > > > > | | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | (define (http-transport:server-dat-update-last-access vec) (if (vector? vec) (vector-set! vec 5 (current-seconds)) (begin (print-call-chain (current-error-port)) (debug:print-error 0 *default-log-port* "call to http-transport:server-dat-update-last-access with non-vector!!")))) ;; initialize servdat for client side, setup needed parameters ;; pass in #f as sdat-in to create sdat ;; (define (servdat-init sdat-in iface port uuid) (let* ((sdat (or sdat-in (make-servdat)))) (if uuid (servdat-uuid-set! sdat uuid)) (servdat-host-set! sdat iface) (servdat-port-set! sdat port) (servdat-api-url-set! sdat (conc "http://" iface ":" port "/api")) (servdat-api-uri-set! sdat (uri-reference (servdat->url sdat))) (servdat-api-req-set! sdat (make-request method: 'POST uri: (servdat-api-uri sdat))) ;; set up the http-client parameters (max-retry-attempts 1) ;; consider all requests indempotent (retry-request? (lambda (request) #f)) (determine-proxy (constantly #f)) sdat)) ;;====================================================================== ;; NEW SERVER METHOD ;;====================================================================== ;; only use for main.db - need to re-write some of this :( ;; |
︙ | ︙ | |||
470 471 472 473 474 475 476 | (read-pkt->alist pkt-file pktspec: pktspec)) all-pkt-files))) (define (server-address srv-pkt) (conc (alist-ref 'host srv-pkt) ":" (alist-ref 'port srv-pkt))) | | | > | 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | (read-pkt->alist pkt-file pktspec: pktspec)) all-pkt-files))) (define (server-address srv-pkt) (conc (alist-ref 'host srv-pkt) ":" (alist-ref 'port srv-pkt))) (define (server-ready? host port) ;; server-address is host:port ;; ping the server and ask it ;; if it ready (let* ((sdat (servdat-init #f host port #f))) (http-transport:send-receive sdat 'ping '()))) ;; from the pkts return servers associated with dbpath ;; NOTE: Only one can be alive - have to check on each ;; in the list of pkts returned ;; (define (get-viable-servers serv-pkts dbpath) (let loop ((tail serv-pkts) |
︙ | ︙ | |||
497 498 499 500 501 502 503 504 | ;; from viable servers get one that is alive and ready ;; (define (get-the-server serv-pkts dbpath) (let loop ((tail serv-pkts)) (if (null? tail) #f (let* ((spkt (car tail)) (addr (server-address spkt))) | > > | | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | ;; from viable servers get one that is alive and ready ;; (define (get-the-server serv-pkts dbpath) (let loop ((tail serv-pkts)) (if (null? tail) #f (let* ((spkt (car tail)) (host (alist-ref 'host spkt)) (port (alist-ref 'port spkt)) (addr (server-address spkt))) (if (server-ready? host port) 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) |
︙ | ︙ | |||
576 577 578 579 580 581 582 | (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 (equal? best-srv-key server-key) (if (get-lock-db sdat db-file) ;; (db:get-iam-server-lock *dbstruct-db* *toppath* run-id) | > | | | | | | | | | | | | | | | | | | | | | | | | | 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | (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 (equal? best-srv-key server-key) (if (get-lock-db sdat db-file) ;; (db:get-iam-server-lock *dbstruct-db* *toppath* run-id) (begin (debug:print 0 *default-log-port* "I'm the server!") (servdat-dbfile-set! sdat db-file)) (begin (debug:print 0 *default-log-port* "I'm not the server, exiting.") (bdat-time-to-exit-set! *bdat* #t) (thread-sleep! 0.2) (exit))) (begin (debug:print 0 *default-log-port* "Keys do not match "best-srv-key", "server-key", exiting.") (bdat-time-to-exit-set! *bdat* #t) (thread-sleep! 0.2) (exit))) sdat)) (begin ;; sdat not yet contains server info (debug:print-info 0 *default-log-port* "Still waiting, last-sdat=" last-sdat) (sleep 4) (if (> (- (current-seconds) start-time) 120) ;; been waiting for two minutes (begin (debug:print-error 0 *default-log-port* "transport appears to have died, exiting server") (exit)) (loop start-time (equal? sdat last-sdat) sdat)))))))) ;; run http-transport:keep-running in a parallel thread to monitor that the db is being ;; used and to shutdown after sometime if it is not. ;; (define (http-transport:keep-running dbname) ;; if none running or if > 20 seconds since ;; server last used then start shutdown |
︙ | ︙ |
Modified launchmod.scm from [ba5b81a174] to [c24b724e9b].
︙ | ︙ | |||
1446 1447 1448 1449 1450 1451 1452 | (write (list (list 'testpath test-path) ;; (list 'transport (conc *transport-type*)) ;; (list 'serverinf *server-info*) #;(list 'homehost (let* ((hhdat (common:get-homehost))) (if hhdat (car hhdat) #f))) | | | | | 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 | (write (list (list 'testpath test-path) ;; (list 'transport (conc *transport-type*)) ;; (list 'serverinf *server-info*) #;(list 'homehost (let* ((hhdat (common:get-homehost))) (if hhdat (car hhdat) #f))) ;; (list 'serverurl (if *runremote* ;; (remote-server-url *runremote*) ;; #f)) ;; (list 'areaname (common:get-area-name)) (list 'toppath *toppath*) (list 'work-area work-area) (list 'test-name test-name) (list 'runscript runscript) (list 'run-id run-id ) (list 'test-id test-id ) |
︙ | ︙ |
Modified rmtmod.scm from [13d1c5f978] to [659d29d212].
︙ | ︙ | |||
132 133 134 135 136 137 138 | ;; ;; grep define ../rmt.scm | grep rmt: |perl -pi -e 's/\(define\s+\((\S+)\W.*$/\1/'|sort -u ;;====================================================================== ;; S U P P O R T F U N C T I O N S ;;====================================================================== | | | | | | | | | | | | | | > > > > > | > > > | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | ;; ;; grep define ../rmt.scm | grep rmt: |perl -pi -e 's/\(define\s+\((\S+)\W.*$/\1/'|sort -u ;;====================================================================== ;; S U P P O R T F U N C T I O N S ;;====================================================================== ;; ;; if a server is either running or in the process of starting call client:setup ;; ;; else return #f to let the calling proc know that there is no server available ;; ;; ;; (define (rmt:get-connection-info areapath #!key (area-dat #f)) ;; TODO: push areapath down. ;; (let* ((runremote (or area-dat *runremote*)) ;; (cinfo (if (remote? runremote) ;; (remote-conndat runremote) ;; #f))) ;; (if cinfo ;; cinfo ;; (if (server:check-if-running areapath) ;; (client:setup areapath) ;; #f)))) (defstruct rmt:remote (conns (make-hash-table)) ;; apath/dbname => rmt:conn ) (defstruct rmt:conn (apath #f) (dbname #f) (fullname #f) (hostport #f) (lastmsg 0) (expires 0)) ;; replaces *runremote* (define *rmt:remote* (make-rmt:remote)) ;; do we have a connection to apath dbname and ;; is it not expired? then return it ;; ;; else setup a connection ;; ;; if that fails, return '(#f "some reason") ;; NB// convert to raising an exception ;; (define (rmt:get-connection remote apath dbname) (let* ((fullname (db:dbname->path apath dbname)) (conn (hash-table-ref/default (rmt:remote-conns remote) fullname #f))) (if (and conn (> (current-seconds) (rmt:conn-expires conn))) conn #f))) ;; (rmt:general-open-connection remote apath dbname)))) ;; looks for a connection to main ;; connections for other servers happens by requesting from main ;; (define (rmt:open-main-connection remote apath) (let* ((pktsdir (get-pkts-dir apath)) (all-srvpkts (get-all-server-pkts pktsdir *srvpktspec*)) (viable-srvs (get-viable-servers all-srvpkts apath)) |
︙ | ︙ | |||
204 205 206 207 208 209 210 211 | hostport: srv-addr lastmsg: (current-seconds) expires: (+ (current-seconds) 60) ;; this needs to be gathered during the ping )) (start-main-srv))) (start-main-srv)))) (define (rmt:general-open-connection remote apath dbname) | > > | > > | > | < > > > | | < > < < < < | < > | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 212 213 214 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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | hostport: srv-addr lastmsg: (current-seconds) expires: (+ (current-seconds) 60) ;; this needs to be gathered during the ping )) (start-main-srv))) (start-main-srv)))) ;; NB// remote is a rmt:remote struct ;; (define (rmt:general-open-connection remote apath dbname) (let ((mainconn (rmt:get-connection remote apath (db:run-id->dbname #f)))) (if (not mainconn) (begin (rmt:open-main-connection remote apath) (thread-sleep! 1) (rmt:general-open-connection remote apath dbname)) ;; we have a connection to main, ask for contact info for dbname (let* ((res (http-transport:send-receive mainconn "x" 'get-server `(,apath ,dbname)))) (print "rmt:general-open-connection got res="res))))) ;;====================================================================== ;; Defaults to ;; (define (rmt:send-receive cmd rid params #!key (attemptnum 1)(area-dat #f)) (if (not *rmt:remote*)(set! *rmt:remote* (make-rmt:remote))) (let* ((apath *toppath*) (conns *rmt:remote*) (dbname (db:run-id->dbname rid))) (rmt:send-receive-real conns apath dbname rid params))) ;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed ;; sometime in the future ;; (define (rmt:send-receive-real remote apath dbname rid params) (let* ((conn (rmt:get-connection remote apath dbname))) (assert conn "FATAL: Unable to connect to db "apath"/"dbname) #t ;; here we do the actual connection work )) (define (rmt:print-db-stats) (let ((fmtstr "~40a~7-d~9-d~20,2-f")) ;; "~20,2-f" (debug:print 18 *default-log-port* "DB Stats\n========") (debug:print 18 *default-log-port* (format #f "~40a~8a~10a~10a" "Cmd" "Count" "TotTime" "Avg")) (for-each (lambda (cmd) (let ((cmd-dat (hash-table-ref *db-stats* cmd))) (debug:print 18 *default-log-port* (format #f fmtstr cmd (vector-ref cmd-dat 0) (vector-ref cmd-dat 1) (/ (vector-ref cmd-dat 1)(vector-ref cmd-dat 0)))))) |
︙ | ︙ | |||
539 540 541 542 543 544 545 | (if (> tot 10) (cons newmax-cmd currmax) (cons 'none 0)) (loop (car tal)(cdr tal) newmax-cmd currmax))))))) (mutex-unlock! *db-stats-mutex*) res)) | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | (if (> tot 10) (cons newmax-cmd currmax) (cons 'none 0)) (loop (car tal)(cdr tal) newmax-cmd currmax))))))) (mutex-unlock! *db-stats-mutex*) res)) ;;====================================================================== ;; ;; A C T U A L A P I C A L L S ;; ;;====================================================================== |
︙ | ︙ | |||
1122 1123 1124 1125 1126 1127 1128 | (define (rmt:test-set-archive-block-id run-id test-id archive-block-id) (rmt:send-receive 'test-set-archive-block-id run-id (list run-id test-id archive-block-id))) (define (rmt:test-get-archive-block-info archive-block-id) (rmt:send-receive 'test-get-archive-block-info #f (list archive-block-id))) | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 824 825 826 827 828 829 830 831 832 833 834 835 836 837 | (define (rmt:test-set-archive-block-id run-id test-id archive-block-id) (rmt:send-receive 'test-set-archive-block-id run-id (list run-id test-id archive-block-id))) (define (rmt:test-get-archive-block-info archive-block-id) (rmt:send-receive 'test-get-archive-block-info #f (list archive-block-id))) ;; gets mtpg-run-id and syncs the record if different ;; (define (tasks:run-id->mtpg-run-id dbh cached-info run-id area-info smallest-last-update-time) (let* ((runs-ht (hash-table-ref cached-info 'runs)) (runinf (hash-table-ref/default runs-ht run-id #f)) (area-id (vector-ref area-info 0))) (if runinf |
︙ | ︙ | |||
1769 1770 1771 1772 1773 1774 1775 | (delete-file* pkt-file) (if (and dbfile (string-match ".*/main.db$" dbfile)) (begin (debug:print-info 0 *default-log-port* "Releasing lock for "dbfile) (db:with-lock-db (servdat-dbfile *server-info*) (lambda (dbh dbfile) | | | 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 | (delete-file* pkt-file) (if (and dbfile (string-match ".*/main.db$" dbfile)) (begin (debug:print-info 0 *default-log-port* "Releasing lock for "dbfile) (db:with-lock-db (servdat-dbfile *server-info*) (lambda (dbh dbfile) (db:release-lock dbh dbfile))))))) (if (bdat-task-db *bdat*) ;; TODO: Check that this is correct for task db (let ((db (cdr (bdat-task-db *bdat*)))) (if (sqlite3:database? db) (begin (sqlite3:interrupt! db) (sqlite3:finalize! db #t) (bdat-task-db-set! *bdat* #f))))) |
︙ | ︙ | |||
1870 1871 1872 1873 1874 1875 1876 | (let ((num-ok (length (server:get-best (server:get-list areapath))))) (if (and (> try-num 0) ;; first time through simply wait a little while then try again (< num-ok 1)) ;; if there are no decent candidates for servers then try starting a new one (server:kind-run areapath)) (thread-sleep! 5) (loop (server:check-if-running areapath) (+ try-num 1))))))) | < < < < < < < < | 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 | (let ((num-ok (length (server:get-best (server:get-list areapath))))) (if (and (> try-num 0) ;; first time through simply wait a little while then try again (< num-ok 1)) ;; if there are no decent candidates for servers then try starting a new one (server:kind-run areapath)) (thread-sleep! 5) (loop (server:check-if-running areapath) (+ try-num 1))))))) ;; called in megatest.scm, host-port is string hostname:port ;; ;; NOTE: This is NOT called directly from clients as not all transports support a client running ;; in the same process as the server. ;; (define (server:ping host port server-id #!key (do-exit #f)) |
︙ | ︙ |