Overview
Comment: | wip |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | v1.6584-ck5 |
Files: | files | file ages | folders |
SHA1: |
f9e738a1caf4e3f08ee850244a409691 |
User & Date: | matt on 2021-05-20 23:29:52 |
Other Links: | branch diff | manifest | tags |
Context
2021-05-21
| ||
22:45 | wip check-in: 0fe5a238ee user: matt tags: v1.6584-ck5 | |
2021-05-20
| ||
23:29 | wip check-in: f9e738a1ca user: matt tags: v1.6584-ck5 | |
21:23 | wip check-in: 3576b029da user: matt tags: v1.6584-ck5 | |
Changes
Modified dbmod.scm from [43fca71bc1] to [4c56626e6f].
︙ | ︙ | |||
328 329 330 331 332 333 334 | (define (db:with-db dbstruct run-id r/w proc . params) (assert (dbr:dbstruct? dbstruct) "FATAL: db:with-db called with bad dbstruct") (let* ((dbpath (db:run-id->dbname run-id)) (dbdat (db:get-dbdat dbstruct *toppath* dbpath)) (db (dbr:dbdat-inmem dbdat)) (fname (dbr:dbdat-fname dbdat)) (use-mutex (> *api-process-request-count* 25))) ;; was 25 | | | > | | 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | (define (db:with-db dbstruct run-id r/w proc . params) (assert (dbr:dbstruct? dbstruct) "FATAL: db:with-db called with bad dbstruct") (let* ((dbpath (db:run-id->dbname run-id)) (dbdat (db:get-dbdat dbstruct *toppath* dbpath)) (db (dbr:dbdat-inmem dbdat)) (fname (dbr:dbdat-fname dbdat)) (use-mutex (> *api-process-request-count* 25))) ;; was 25 #;(if (and use-mutex (common:low-noise-print 120 "over-50-parallel-api-requests")) (debug:print-info 0 *default-log-port* *api-process-request-count* " parallel api requests being processed in process " (current-process-id) ", throttling access")) #;(if (common:low-noise-print 600 (conc "parallel-api-requests" *max-api-process-requests*)) (debug:print-info 2 *default-log-port* "Parallel api request count: " *api-process-request-count* " max parallel requests: " *max-api-process-requests*)) (apply proc db params) #;(condition-case (begin (if use-mutex (mutex-lock! *db-with-db-mutex*)) (let ((res (apply proc db params))) (if use-mutex (mutex-unlock! *db-with-db-mutex*)) ;; (if (vector? dbstruct)(db:done-with dbstruct run-id r/w)) res)) (exn (io-error) |
︙ | ︙ | |||
1266 1267 1268 1269 1270 1271 1272 | (sqlite3:execute db "CREATE TABLE IF NOT EXISTS servers (id INTEGER PRIMARY KEY, host TEXT, port INTEGER, servkey TEXT, pid TEXT, ipaddr TEXT, | | > | | 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 | (sqlite3:execute db "CREATE TABLE IF NOT EXISTS servers (id INTEGER PRIMARY KEY, host TEXT, port INTEGER, servkey TEXT, pid TEXT, ipaddr TEXT, apath TEXT, dbname TEXT, event_time TIMESTAMP DEFAULT (strftime('%s','now')), CONSTRAINT servers_constraint UNIQUE (apath,dbname));") (sqlite3:execute db "CREATE TABLE IF NOT EXISTS keys (id INTEGER PRIMARY KEY, fieldname TEXT, fieldtype TEXT, CONSTRAINT keyconstraint UNIQUE (fieldname));") |
︙ | ︙ | |||
5515 5516 5517 5518 5519 5520 5521 | ;;====================================================================== ;; S E R V E R R E C O R D S ;;====================================================================== ;; these are all intended to be run against main.db ;; run this one in a transaction where first check if host:port is taken | | > > > > > > > > > | | > | | | | | | 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 | ;;====================================================================== ;; S E R V E R R E C O R D S ;;====================================================================== ;; these are all intended to be run against main.db ;; run this one in a transaction where first check if host:port is taken (define (db:register-server dbstruct host port servkey pid ipaddr apath dbname) (db:with-db dbstruct #f #f (lambda (db) (sqlite3:with-transaction db (lambda () (let* ((sinfo (db:get-server-info dbstruct apath dbname))) (if sinfo (begin (debug:print-info 0 *default-log-port* "Server already running at "sinfo ", while trying to register server " host":"port) #f) ;; server already registered (begin (sqlite3:execute db "INSERT INTO servers (host,port,servkey,pid,ipaddr,apath,dbname) VALUES (?,?,?,?,?,?,?);" host port servkey pid ipaddr apath dbname) (db:get-server-info dbstruct apath dbname))))))))) (define (db:get-server-info dbstruct apath dbname) (db:with-db dbstruct #f #f (lambda (db) (sqlite3:fold-row (lambda (res host port servkey pid ipaddr apath dbpath) (list host port servkey pid ipaddr apath dbpath)) #f db "SELECT host,port,servkey,pid,ipaddr,apath,dbname FROM servers WHERE apath=? AND dbname=?;" apath dbname)))) ) |
Modified fullrununit.sh from [3ffa0b3716] to [12bf13749e].
1 2 | #!/bin/bash | | | 1 2 3 4 5 6 | #!/bin/bash (killall mtest -v;sleep 1;killall mtest -v -9;rm -f tests/simplerun/.db/* tests/simplerun/logs/* tests/basicserver.log) & ck5 make -j install && wait && ck5 make unit |
Modified rmtmod.scm from [faeb47f828] to [d0cb393e69].
︙ | ︙ | |||
259 260 261 262 263 264 265 | #t) (start-main-srv))) (start-main-srv)))) ;; NB// remote is a rmt:remote struct ;; (define (rmt:general-open-connection remote apath dbname #!key (num-tries 5)) | > | | | | | | | | | | | | | < | | | | > > > | | | | | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | #t) (start-main-srv))) (start-main-srv)))) ;; NB// remote is a rmt:remote struct ;; (define (rmt:general-open-connection remote apath dbname #!key (num-tries 5)) (let ((mdbname (db:run-id->dbname #f))) (cond ((not (rmt:get-conn remote apath mdbname)) ;; no channel open to main? (rmt:open-main-connection remote apath) (thread-sleep! 2) (rmt:general-open-connection remote apath mdbname)) ((not (rmt:get-conn remote apath dbname)) ;; no channel open to dbname? (let* ((res (rmt:send-receive-real remote apath mdbname 'get-server `(,apath ,dbname)))) (case res ((server-started) (if (> num-tries 0) (begin (thread-sleep! 2) (rmt:general-open-connection remote apath dbname num-tries: (- num-tries 1))) (begin (debug:print-error 0 *default-log-port* "Failed to start servers needed or open channel to "apath", "dbname) (exit 1)))) (else (if (list? res) ;; server has been registered and the info was returned. pass it on. res (begin (debug:print-info 0 *default-log-port* "Unexpected result: " res) res))))))))) ;;====================================================================== ;; Defaults to current area ;; (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:general-open-connection conns apath dbname) (rmt:send-receive-real conns apath dbname 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-real remote apath dbname cmd params) (let* ((conn (rmt:get-conn remote apath dbname))) (assert conn "FATAL: rmt:send-receive-real called without the needed channels opened") (let* ((payload (sexpr->string params)) (res (with-input-from-request (rmt:conn->uri conn "api") `((params . ,payload) (cmd . ,cmd) |
︙ | ︙ | |||
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | (rmt:send-receive 'get-runs-cnt-by-patt #f (list runpatt targetpatt keys))) ;; Use the special run-id == #f scenario here since there is no run yet (define (rmt:register-run keyvals runname state status user contour) ;; first register in main.db (thus the #f) (let* ((run-id (rmt:send-receive 'register-run #f (list keyvals runname state status user contour)))) ;; now register in the run db itself (rmt:send-receive 'register-run run-id (list keyvals runname state status user contour)) run-id)) (define (rmt:get-run-name-from-id run-id) (rmt:send-receive 'get-run-name-from-id run-id (list run-id))) (define (rmt:delete-run run-id) (rmt:send-receive 'delete-run run-id (list run-id))) | > > > | 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 | (rmt:send-receive 'get-runs-cnt-by-patt #f (list runpatt targetpatt keys))) ;; Use the special run-id == #f scenario here since there is no run yet (define (rmt:register-run keyvals runname state status user contour) ;; first register in main.db (thus the #f) (let* ((run-id (rmt:send-receive 'register-run #f (list keyvals runname state status user contour)))) ;; now register in the run db itself ;; NEED A RECORD INSERT INCLUDING SETTING id (rmt:send-receive 'register-run run-id (list keyvals runname state status user contour)) run-id)) (define (rmt:get-run-name-from-id run-id) (rmt:send-receive 'get-run-name-from-id run-id (list run-id))) (define (rmt:delete-run run-id) (rmt:send-receive 'delete-run run-id (list run-id))) |
︙ | ︙ | |||
1492 1493 1494 1495 1496 1497 1498 | (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)))) (let* ((sdat *server-info*)) ;; we have a run-id server (rmt:send-receive-real *rmt:remote* *toppath* (db:run-id->dbname #f) | | | 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 | (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)))) (let* ((sdat *server-info*)) ;; we have a run-id server (rmt:send-receive-real *rmt:remote* *toppath* (db:run-id->dbname #f) 'register-server `(,(servdat-uuid sdat) ,(current-process-id) ,(servdat-host sdat) ;; iface ,(servdat-port sdat)))))))) (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) |
︙ | ︙ | |||
2269 2270 2271 2272 2273 2274 2275 | (begin (debug:print-error 0 *default-log-port* "transport appears to have died, exiting server") (exit)) (loop start-time (equal? sdat last-sdat) sdat)))))))) | | > | | | | | > | | 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 | (begin (debug:print-error 0 *default-log-port* "transport appears to have died, exiting server") (exit)) (loop start-time (equal? sdat last-sdat) sdat)))))))) (define (rmt:register-server remote apath iface port server-key dbname) (rmt:open-main-connection remote apath) ;; we need a channel to main.db (rmt:send-receive-real remote apath ;; params: host port servkey pid ipaddr dbpath (db:run-id->dbname #f) 'register-server `(,iface ,port ,server-key ,(current-process-id) ,iface ,apath ,dbname))) (define (http-transport:wait-for-stable-interface #!optional (num-tries-allowed 100)) ;; wait until *server-info* stops changing (let loop ((sdat #f) ;; this is our copy of the *last* *server-info* (tries 0)) ;; first we verify port and interface, update *server-info* in need be. (cond |
︙ | ︙ |
Modified tests/unittests/basicserver.scm from [d917ba01d8] to [67b7c04b63].
︙ | ︙ | |||
62 63 64 65 66 67 68 | '(a "b" 123 1.23 ))) (test #f #t (number? (rmt:send-receive 'ping #f 'hello))) (define *db* (db:setup #f)) ;; these let me cut and paste from source easily (define apath *toppath*) | | > | > | | > > > | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | '(a "b" 123 1.23 ))) (test #f #t (number? (rmt:send-receive 'ping #f 'hello))) (define *db* (db:setup #f)) ;; these let me cut and paste from source easily (define apath *toppath*) (define dbname ".db/2.db") (define remote *rmt:remote*) (define keyvals '(("SYSTEM" "a")("RELEASE" "b"))) (test #f 'server-started (api:execute-requests *db* 'get-server (list *toppath* ".db/2.db"))) (set! *dbstruct-db* #f) (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 'server-started (rmt:send-receive-real *rmt:remote* *toppath* ".db/main.db" 'get-server `(,apath ,dbname))) (thread-sleep! 2) (test #f #t (list? (rmt:general-open-connection *rmt:remote* *toppath* ".db/2.db"))) (test #f '("SYSTEM" "RELEASE") (rmt:get-keys)) (test #f 1 (rmt:send-receive 'register-run #f (list keyvals "run1" "new" "n/a" "justme" #f))) (test #t 1 (rmt:send-receive 'register-run run-id (list keyvals "run1" "new" "n/a" "justme" #f))) (test #f 1 (rmt:register-run keyvals "run2" "new" "n/a" "justme" #f)) ;; (delete-file* "logs/1.log") ;; (define run-id 1) ;; (test "setup for run" #t (begin (launch:setup) ;; (string? (getenv "MT_RUN_AREA_HOME")))) ;; |
︙ | ︙ |