Overview
Comment: | Ripped up and rebuilt (but not completed) send-recieve |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | v1.6584-ck5 |
Files: | files | file ages | folders |
SHA1: |
60d056bd58d180abd29714bf143c9c6b |
User & Date: | matt on 2021-05-10 23:25:10 |
Other Links: | branch diff | manifest | tags |
Context
2021-05-11
| ||
05:34 | Added next round of tests check-in: bda352d54b user: matt tags: v1.6584-ck5 | |
2021-05-10
| ||
23:25 | Ripped up and rebuilt (but not completed) send-recieve check-in: 60d056bd58 user: matt tags: v1.6584-ck5 | |
22:53 | Got loop-test working check-in: ba4f089eda user: matt tags: v1.6584-ck5 | |
Changes
Modified apimod.scm from [dc1a92b44f] to [6bfd389a2f].
︙ | ︙ | |||
155 156 157 158 159 160 161 | testmeta-update-field ;; TASKS tasks-add tasks-set-state-given-param-key )) | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | testmeta-update-field ;; TASKS tasks-add tasks-set-state-given-param-key )) (define (api:dispatch-cmd dbstruct cmd params) (case cmd ;;=============================================== ;; READ/WRITE QUERIES ;;=============================================== ((get-keys-write) (db:get-keys dbstruct)) ;; force a dummy "write" query to force server; for debug in -repl |
︙ | ︙ | |||
371 372 373 374 375 376 377 | ;; TESTMETA ((testmeta-get-record) (apply db:testmeta-get-record dbstruct params)) ;; TASKS ((find-task-queue-records) (apply tasks:find-task-queue-records dbstruct params)) (else (debug:print 0 *default-log-port* "ERROR: bad api call " cmd) | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | < < < | | < < < | | | < > | | 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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 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 413 | ;; TESTMETA ((testmeta-get-record) (apply db:testmeta-get-record dbstruct params)) ;; TASKS ((find-task-queue-records) (apply tasks:find-task-queue-records dbstruct params)) (else (debug:print 0 *default-log-port* "ERROR: bad api call " cmd) (conc "ERROR: BAD api call " cmd)))) ;; These are called by the server on recipt of /api calls ;; - keep it simple, only return the actual result of the call, i.e. no meta info here ;; ;; - returns #( flag result ) ;; (define (api:execute-requests dbstruct cmd params) ;; (handle-exceptions ;; exn ;; (let ((call-chain (get-call-chain))) ;; (debug:print 0 *default-log-port* "WARNING: api:execute-requests received an exception from peer, dat=" dat ", exn=" exn) ;; (print-call-chain (current-error-port)) ;; (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn)) ;; (vector #f (vector exn call-chain dat))) ;; return some stuff for debug if an exception happens ;; (cond ;; ((not (vector? dat)) ;; it is an error to not receive a vector ;; (vector #f (vector #f "remote must be called with a vector"))) ;; ((> *api-process-request-count* 20) ;; 20) ;; (debug:print 0 *default-log-port* "WARNING: api:execute-requests received an overloaded message.") ;; (set! *server-overloaded* #t) ;; (vector #f (vector #f 'overloaded))) ;; the inner vector is what gets returned. nope, don't know why. please refactor! ;; (else (let* (;; (cmd-in (vector-ref dat 0)) ;; (cmd (if (symbol? cmd-in) ;; cmd-in ;; (string->symbol cmd-in))) ;; (params (vector-ref dat 1)) (start-t (current-milliseconds)) ;; (readonly-mode (dbr:dbstruct-read-only dbstruct)) ;; (readonly-command (member cmd api:read-only-queries)) ;; (writecmd-in-readonly-mode (and readonly-mode (not readonly-command))) (res (api:dispatch-cmd dbstruct cmd params))) ;; (if writecmd-in-readonly-mode ;; (conc "attempt to run write command "cmd" on a read-only database") ;; save all stats (let ((delta-t (- (current-milliseconds) start-t))) (hash-table-set! *db-api-call-time* cmd (cons delta-t (hash-table-ref/default *db-api-call-time* cmd '())))) res)) ;; (if #f ;; writecmd-in-readonly-mode ;; (begin ;; (vector #f res)) ;; (begin ;; (vector #t res)))))))) ;; http-server send-response ;; api:process-request ;; db:* ;; ;; NB// Runs on the server as part of the server loop ;; (define (api:process-request dbstruct $) ;; the $ is the request vars proc (debug:print 4 *default-log-port* "server-id:" *server-id*) (let* ((cmd ($ 'cmd)) (params (string->sexpr ($ 'params))) (key ($ 'key)) ;; TODO - add this back ) (debug:print 0 *default-log-port* "cmd:" cmd " with params " params "key " key) (if (equal? key "nokey") ;; *server-id*) ;; TODO - get real key involved (begin (set! *api-process-request-count* (+ *api-process-request-count* 1)) (let* ((resdat (api:execute-requests dbstruct (vector cmd params))) ;; process the request, resdat = #( flag result ) (success (vector-ref resdat 0)) (res (vector-ref resdat 1))) ;; (vector flag payload), get the payload, ignore the flag (why?) (debug:print 4 *default-log-port* "res:" res) (if (not success) |
︙ | ︙ |
Modified commonmod.scm from [b9d002f916] to [89d0b29ed8].
︙ | ︙ | |||
3773 3774 3775 3776 3777 3778 3779 | ;; ;; ;; (define (mddb:get-dashboards) ;; (let ((db (mddb:open-db))) ;; (query fetch-column ;; (sql db "SELECT ipaddr || ':' || portnum FROM dashboards;")))) | | | > > > > | 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 | ;; ;; ;; (define (mddb:get-dashboards) ;; (let ((db (mddb:open-db))) ;; (query fetch-column ;; (sql db "SELECT ipaddr || ':' || portnum FROM dashboards;")))) (define (sexpr->string data) (with-output-to-string (lambda ()(write data)))) (define (string->sexpr instr) (with-input-from-string instr (lambda ()(read)))) ) |
Modified http-transportmod.scm from [a2b5cd07dd] to [1c967146dc].
︙ | ︙ | |||
165 166 167 168 169 170 171 | (let* (($ (request-vars source: 'both)) (dat ($ 'dat)) (res #f)) (cond ((equal? (uri-path (request-uri (current-request))) '(/ "api")) (send-response ;; the $ is the request vars proc | | | 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | (let* (($ (request-vars source: 'both)) (dat ($ 'dat)) (res #f)) (cond ((equal? (uri-path (request-uri (current-request))) '(/ "api")) (send-response ;; the $ is the request vars proc body: ((api-proc) *dbstruct-db* $) ;; ($) => alist headers: '((content-type text/plain))) (set! *db-last-access* (current-seconds))) ((equal? (uri-path (request-uri (current-request))) '(/ "ping")) (send-response body: (conc *toppath*"/"(args:get-arg "-db")) headers: '((content-type text/plain)))) ((equal? (uri-path (request-uri (current-request))) |
︙ | ︙ | |||
301 302 303 304 305 306 307 | (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*))) | < < < < < < < < | 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | (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) |
︙ | ︙ |
Modified rmtmod.scm from [e69c41a548] to [dc42b6de0a].
︙ | ︙ | |||
56 57 58 59 60 61 62 63 64 65 66 67 68 69 | srfi-1 srfi-13 srfi-18 srfi-69 commonmod apimod itemsmod debugprint mtver regex tasksmod pgdb (prefix mtargs args:) dbmod | > | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | srfi-1 srfi-13 srfi-18 srfi-69 commonmod apimod itemsmod http-client debugprint mtver regex tasksmod pgdb (prefix mtargs args:) dbmod |
︙ | ︙ | |||
250 251 252 253 254 255 256 | ;; 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))) | | | > | > > > > > > | > | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | ;; 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 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 rid cmd params) (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)) (res (with-input-from-request (conc "http://"host":"port"/api") `((params . ,payload) (cmd . ,cmd) (key . "nokey") read-string)))) (string->sexpr res)))) (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))) |
︙ | ︙ |