Overview
Comment: | One failure to get lock to open db go ahead and try, reset counters of api calls using count of threads, some threads might die and are unable to unregister themselves. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | v1.80 |
Files: | files | file ages | folders |
SHA1: |
e799a787ef3836c8bd39e7adcb8fde70 |
User & Date: | matt on 2023-05-22 20:41:51 |
Other Links: | branch diff | manifest | tags |
Context
2023-05-22
| ||
21:38 | Couple untested fixes check-in: 4a2131ba1d user: matt tags: v1.80 | |
20:41 | One failure to get lock to open db go ahead and try, reset counters of api calls using count of threads, some threads might die and are unable to unregister themselves. check-in: e799a787ef user: matt tags: v1.80 | |
17:50 | Cherry pick ab049 check-in: 64f486e05b user: matt tags: v1.80 | |
Changes
Modified api.scm from [cc67cf0a85] to [00015c9c1f].
︙ | |||
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 | 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + | ;; (ok-res . #t))) ;; (vector #f res)) ;; (begin ;; #;(common:telemetry-log (conc "api-out:"(->string cmd)) ;; payload: `((params . ,params) ;; (ok-res . #f))) ;; (vector #t res)))))))) (define *api-threads* '()) (define (api:register-thread th-in) (set! *api-threads* (cons (cons th-in (current-seconds)) *api-threads*))) (define (api:unregister-thread th-in) (set! *api-threads* (filter (lambda (thdat) (not (eq? th-in (car thdat)))) *api-threads*))) (define (api:remove-dead-or-terminated) (set! *api-threads* (filter (lambda (thdat) (not (member (thread-state (car thdat)) '(terminated dead)))) *api-threads*))) (define (api:get-count-threads-alive) (length *api-threads*)) ;; indat is (cmd run-id params meta) ;; ;; WARNING: Do not print anything in the lambda of this function as it ;; reads/writes to current in/out port ;; (define (api:tcp-dispatch-request-make-handler dbstruct) ;; cmd run-id params) (assert *toppath* "FATAL: api:tcp-dispatch-request-make-handler called but *toppath* not set.") (if (not *server-signature*) (set! *server-signature* (tt:mk-signature *toppath*))) (lambda (indat) (api:register-thread (current-thread)) (let* (;; (indat (deserialize)) (newcount (+ *api-process-request-count* 1)) (numthreads (api:get-count-threads-alive)) (delay-wait (if (> newcount 10) (- newcount 10) 0)) (normal-proc (lambda (cmd run-id params) (case cmd ((ping) *server-signature*) (else (api:dispatch-request dbstruct cmd run-id params)))))) (set! *api-process-request-count* newcount) (set! *db-last-access* (current-seconds)) (if (not (eq? newcount numthreads)) (begin (api:remove-dead-or-terminated) (let ((threads-now (api:get-count-threads-alive))) (debug:print 0 *default-log-port* "WARNING: newcount="newcount", numthreads="numthreads", remaining="threads-now) (set! newcount threads-now)))) (match indat ((cmd run-id params meta) (let* ((db-ok (let* ((dbfname (dbmod:run-id->dbfname run-id)) (ok (equal? dbfname (dbr:dbstruct-dbfname dbstruct)))) (case cmd ((ping) #t) ;; we are fine (else |
︙ | |||
262 263 264 265 266 267 268 | 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 | - + + | ((loaded) (conc "Server loaded, "newcount" threads in flight")) (else #f))) (result (case status ((busy) (if (eq? cmd 'ping) (normal-proc cmd run-id params) ;; newcount must be greater than 5 for busy |
︙ |
Modified dbfile.scm from [10490588b1] to [b9d134230d].
︙ | |||
1393 1394 1395 1396 1397 1398 1399 | 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 | - + - - + + - - - - + + + | (define (dbfile:simple-file-release-lock fname) (handle-exceptions exn #f ;; I don't really care why this failed (at least for now) (delete-file* fname))) |
︙ |
Modified dbmod.scm from [88ea4fc563] to [a5cc78531f].
︙ | |||
173 174 175 176 177 178 179 | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | - + + | (let* ((dbexists (file-exists? dbfullname)) (db (sqlite3:open-database dbfullname)) (handler (sqlite3:make-busy-timeout 136000))) (sqlite3:set-busy-handler! db handler) (if (and dbexists write-access) (init-proc db)) |
︙ |