Overview
Comment: | Overhauled rpc-transport:launch and rpc-transport:run to account for things introduced to http-transport like inmem db maintenance ; made and used rpc-transport:server-shutdown ; made (more) opinionaltedly encapsulated procedures for task unit |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | rpc-transport |
Files: | files | file ages | folders |
SHA1: |
c88c8f26e022c48a91a0dd152eb6058e |
User & Date: | bjbarcla on 2016-11-02 00:44:01 |
Other Links: | branch diff | manifest | tags |
Context
2016-11-02
| ||
03:09 | made changes to fix tcp-buffer size to 0 so rpc worked. small fight here between http-transport and rpc-transport here... hopefully this patch does the job. check-in: 58d1011733 user: bjbarcla tags: rpc-transport | |
00:44 | Overhauled rpc-transport:launch and rpc-transport:run to account for things introduced to http-transport like inmem db maintenance ; made and used rpc-transport:server-shutdown ; made (more) opinionaltedly encapsulated procedures for task unit check-in: c88c8f26e0 user: bjbarcla tags: rpc-transport | |
2016-11-01
| ||
02:46 | picked nit check-in: e9f1cb9e4b user: bjbarcla tags: rpc-transport | |
Changes
Modified http-transport.scm from [f8800e432b] to [8236b0c25e].
︙ | |||
383 384 385 386 387 388 389 | 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | - + | (begin (debug:print-error 0 *default-log-port* "transport appears to have died, exiting server " server-id " for run " run-id) (tasks:server-delete-record (db:delay-if-busy tdbdat) server-id "failed to start, never received server alive signature") (exit)) (loop start-time (equal? sdat last-sdat) sdat))))))) |
︙ |
Modified rmt.scm from [ec0b0ba85a] to [fa9d72cfee].
︙ | |||
72 73 74 75 76 77 78 | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | + + - + + - + | #f)))) (define *send-receive-mutex* (make-mutex)) ;; should have separate mutex per run-id ;; RA => e.g. usage (rmt:send-receive 'get-var #f (list varname)) ;; (define (rmt:send-receive cmd rid params #!key (attemptnum 1)) ;; start attemptnum at 1 so the modulo below works as expected |
︙ |
Modified rpc-transport.scm from [702db23fbc] to [bd4853520b].
︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 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 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 313 314 315 316 317 318 319 320 321 322 323 324 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + - - - - + + + - - + + + - - - - - + + - - - - - + + + + + + + - - + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + - + + - - + + + + + + + + + + + + - + - + - - - - - - - - - - + - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | (declare (uses common)) (declare (uses db)) (declare (uses tests)) (declare (uses tasks)) ;; tasks are where stuff is maintained about what is running. (include "common_records.scm") (include "db_records.scm") (define *heartbeat-mutex* (make-mutex)) (define *server-loop-heart-beat* (current-seconds)) ;; procstr is the name of the procedure to be called as a string (define (rpc-transport:autoremote procstr params) (handle-exceptions exn (begin (debug:print 1 *default-log-port* "Remote failed for " proc " " params) (apply (eval (string->symbol procstr)) params)) ;; (if *runremote* ;; (apply (eval (string->symbol (conc "remote:" procstr))) params) (apply (eval (string->symbol procstr)) params))) ;; retry an operation (depends on srfi-18) (define (retry-thunk the-thunk #!key (accept-result? (lambda (x) x)) (retries 4) (wait-seconds-between-tries 0.2) (failure-value #f)) (let loop ((res (the-thunk)) (retries-left retries)) (cond ((accept-result? res) res) ((> retries-left 0) (thread-sleep! wait-seconds-between-tries) (loop (the-thunk) (sub1 retries-left))) (else failure-value)))) (define (rpc-transport:server-shutdown server-id rpc:listener #!key (from-on-exit #f)) (BB> "rpc-transport:server-shutdown entered.") (on-exit (lambda () #t)) ;; turn off on-exit stuff ;;(tcp-close rpc:listener) ;; gotta exit nicely ;;(tasks:bb-server-set-state! server-id "stopped") ;; TODO: (low) the following is extraordinaritly slow. Maybe we don't even need portlogger for rpc anyway?? the exception-based failover when ports are taken is fast! ;;(BB> "before plog rel") ;;(portlogger:open-run-close portlogger:set-port (rpc:default-server-port) "released") (set! *time-to-exit* #t) (BB> "before db:sync-touched") (if *inmemdb* (db:sync-touched *inmemdb* *run-id* force-sync: #t)) (BB> "before bb-server-delete-record") (tasks:bb-server-delete-record server-id " rpc-transport:keep-running complete") (BB> "Before (exit)") (unless from-on-exit (exit)) ) ;; all routes though here end in exit ... ;; ;; start_server? ;; (define (rpc-transport:launch run-id) |
︙ | |||
193 194 195 196 197 198 199 | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | - + | (begin (server:try-running run-id) (thread-sleep! 2) (rpc-transport:client-setup run-id (- remtries 1))))) (let* ((server-db-info (open-run-close tasks:get-server-info tasks:open-db run-id))) (debug:print-info 0 *default-log-port* "client:setup server-dat=" server-dat ", remaining-tries=" remaining-tries) (if server-db-info |
︙ |
Modified server.scm from [c9c38a4420] to [b3bc3d6537].
︙ | |||
258 259 260 261 262 263 264 265 266 267 268 269 270 271 | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | + + + | (if (eof-object? inl) (case (string->symbol res) ((NOREPLY) #f) ((LOGIN_OK) #t) (else #f)) (loop (read-line) inl)))))) ;; Client will call this procedure on the server via the low-level transport (http/rpc/etc) to verify its toppath matches the server's toppath. ;; A true result means client and server are associated with same megatest instance, share the same megatest.config, etc...) A false result means the client should not talk to this server. (define (server:login toppath) (lambda (toppath) (set! *last-db-access* (current-seconds)) (if (equal? *toppath* toppath) (begin ;; (debug:print-info 2 *default-log-port* "login successful") #t) |
︙ |
Modified tasks.scm from [c4bf88d4c8] to [afe54500ce].
︙ | |||
289 290 291 292 293 294 295 296 297 298 299 300 301 302 | 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | + + + + | (remtries 100)) (if (member port used-ports) (if (> remtries 0) (loop (get-rand-port)(- remtries 1)) (get-rand-port)) port)))))) ;; there can be multiple servers spawned for the same runid. we want exactly zero or one servers per runid. The caller is a nascent server. It wants to know if it should proceed or if it is redundant. this function chooses a winner and tells me if I am the winner. Alternative is lots of runaway servers. Nobody wants that, trust me. ;; ;; algo: get all server info entries for this runid. Each nascent server will insert an entry for its runid before getting here. Entries are visible globally. If current hostname and current processid match first entry, then yes I am the server; return server-id as my prize for winning. Otherwise, I am not the server; return #f. ;; (define (tasks:server-am-i-the-server? mdb run-id) (let* ((all (tasks:server-get-servers-vying-for-run-id mdb run-id)) (first (if (null? all) #f;; (begin (debug:print-error 0 *default-log-port* "no servers listed, should be at least one by now.") ;; (sqlite3:finalize! mdb) ;; (exit 1)) (car (db:get-rows all))))) |
︙ | |||
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | 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 | + + + + + + + + + + + + + + + + + | ;; BB> bb opinion - want to push responsibility into api (encapsulation), like waiting if db is busy and finding the db handle in the first place. why should the caller need to be concerned?? If my opinion carries, we'll remove the bb- and make other needful adjustments. (define (bb-mdb-inserter mdb-expecting-proc mdbless-args) (let ((mdb (db:delay-if-busy (tasks:open-db)))) (apply mdb-expecting-proc (cons mdb mdbless-args)))) (define (tasks:bb-server-lock-slot . args) (bb-mdb-inserter tasks:server-lock-slot args)) (define (tasks:bb-server-set-interface-port . args) (bb-mdb-inserter tasks:server-set-interface-port args)) (define (tasks:bb-server-am-i-the-server? . args) (bb-mdb-inserter tasks:server-am-i-the-server? args)) (define (tasks:bb-server-set-state! . args) (bb-mdb-inserter tasks:server-set-state! args)) (define (tasks:bb-get-server-info . args) (bb-mdb-inserter tasks:get-server-info args)) (define (tasks:bb-num-in-available-state . args) (bb-mdb-inserter tasks:num-in-available-state args)) (define (tasks:bb-server-delete-records-for-this-pid . args) (bb-mdb-inserter tasks:server-delete-records-for-this-pid args)) (define (tasks:bb-server-delete-record . args) (bb-mdb-inserter tasks:server-delete-record args)) ;; BB: renaming tasks:get-server to get-server-info to make clear we aren't creating servers here (define (tasks:get-server-info mdb run-id #!key (retries 10)) (let ((res #f) (best #f)) (handle-exceptions |
︙ |