Overview
Comment: | Changed sleep after server start from 3 to 4 seconds to avoid unncessary server restarts. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | v1.80 |
Files: | files | file ages | folders |
SHA1: |
d5b4d7755f0266b8d75746c93d1026ad |
User & Date: | mmgraham on 2024-05-13 17:02:48 |
Other Links: | branch diff | manifest | tags |
Context
2024-05-14
| ||
08:58 | added extra condition to tests:get-items to return #f when items and itemstable were #f check-in: ac15ec2989 user: mmgraham tags: v1.80 | |
2024-05-13
| ||
17:02 | Changed sleep after server start from 3 to 4 seconds to avoid unncessary server restarts. check-in: d5b4d7755f user: mmgraham tags: v1.80 | |
2024-05-10
| ||
10:37 | merged fork check-in: 545db1f8c6 user: mmgraham tags: v1.80 | |
Changes
Modified tcp-transportmod.scm from [c81bb58c08] to [27966bec9e].
︙ | ︙ | |||
127 128 129 130 131 132 133 | (equal? (dbfile:run-id->dbfname run-id) dbfname))) (tcp-buffer-size 2048) ;; (max-connections 4096) ;; do all the busy work of finding and setting up conn for ;; connecting to a server | > > > > > > | > > > > > > > > > > > > > > > > > > > > | | | 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 | (equal? (dbfile:run-id->dbfname run-id) dbfname))) (tcp-buffer-size 2048) ;; (max-connections 4096) ;; do all the busy work of finding and setting up conn for ;; connecting to a server ;; This function, `tt:client-connect-to-server`, is designed to manage connections between a client and a server within a testing framework. ;; The function takes four arguments: ;; 1. `ttdat`: a data structure that holds information about the testing environment or connections. ;; 2. `dbfname`: The name of the database file that the client wants to connect to. ;; 3. `run-id`: An identifier for the current run of the test suite. ;; 4. `testsuite`: The test suite that is being run. ;; ;; Here's a step-by-step explanation of what the function does: ;; ;; 1. It first asserts that the `run-id` is valid for the given `dbfname` using the `tt:valid-run-id` function. If the `run-id` is not valid, it raises a fatal error. ;; 2. It prints debug information indicating that the function `tt:client-connect-to-server` has been called with the given `dbfname`. ;; 3. It attempts to retrieve an existing connection to the server from a hash table (`tt-conns`) using the `dbfname` as the key. If a connection already exists, it prints debug information and returns the existing connection. ;; 4. If no existing connection is found, it retrieves the current server information from the servinfo file, using the `tt:get-current-server-info` function. ;; 5. It uses pattern matching to destructure the server information into variables (`host`, `port`, `start-time`, `server-id`, `pid`, `dbfname2`, `servinffile`). It then asserts that the `dbfname` from the server info matches the one provided to the function. ;; 6. It constructs a connection object (`conn`) with the server information. ;; 7. It attempts to ping the server using `tt:timed-ping` to verify that the server is running and can be communicated with. ;; 8. Depending on the result of the ping: ;; - If the server is running (`running`), it prints debug information, saves the connection in the hash table, and returns the connection. ;; - If the server is starting (`starting`), it sleeps for 2 seconds and then recursively calls itself to retry the connection. ;; - If the server is neither running nor starting, it checks if it's been more than 10 seconds since the last server start attempt. If so, it attempts to start the server using `server-start-proc` and then sleeps for 1 second before retrying the connection. ;; 9. If no server information is found (`else` case), it checks if it's been more than 3 seconds since the last server start attempt. If so, it starts a new server using `server-start-proc`, updates the last server start time, and sleeps for 4 seconds. ;; 10. It then sleeps for 1 second and prints debug information before recursively calling itself to retry the connection. ;; ;; The function uses recursion to keep trying to connect to the server, with various sleep intervals to prevent overwhelming the system with connection attempts or server starts. ;; It also uses a hash table to cache connections and avoid reconnecting to a server if a connection already exists. ;; The function is designed to handle different server states and ensure that a server is running and available before returning a valid connection to the caller. ;; (define (tt:client-connect-to-server ttdat dbfname run-id testsuite) (assert (tt:valid-run-id run-id dbfname) "FATAL: invalid run-id "run-id) (debug:print-info 2 *default-log-port* "tt:client-connect-to-server " dbfname) (let* ((conn (hash-table-ref/default (tt-conns ttdat) dbfname #f)) (server-start-proc (lambda () (tt:server-process-run (tt-areapath ttdat) testsuite ;; (dbfile:testsuite-name) (common:find-local-megatest) run-id)))) (if conn (begin (debug:print-info 2 *default-log-port* "already connected to a server for " dbfname) conn) ;; we are already connected to the server (let* ((sdat (tt:get-current-server-info ttdat dbfname))) (match sdat ((host port start-time server-id pid dbfname2 servinffile) (assert (equal? dbfname dbfname2) "FATAL: read server info from wrong file.") (debug:print-info 2 *default-log-port* "no conn - in match servinffile:" servinffile) (let* ((host-port (conc host":"port)) |
︙ | ︙ | |||
187 188 189 190 191 192 193 | (tt:client-connect-to-server ttdat dbfname run-id testsuite))))))) (else ;; no good server found, if haven't started server in > 5 secs, start another (if (> (- (current-seconds) (tt-last-serv-start ttdat)) 3) ;; BUG - grow this number really do not want to swamp the machine with servers (begin (debug:print-info 0 *default-log-port* "Starting server for "dbfname) (server-start-proc) (tt-last-serv-start-set! ttdat (current-seconds)) | | | 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | (tt:client-connect-to-server ttdat dbfname run-id testsuite))))))) (else ;; no good server found, if haven't started server in > 5 secs, start another (if (> (- (current-seconds) (tt-last-serv-start ttdat)) 3) ;; BUG - grow this number really do not want to swamp the machine with servers (begin (debug:print-info 0 *default-log-port* "Starting server for "dbfname) (server-start-proc) (tt-last-serv-start-set! ttdat (current-seconds)) (thread-sleep! 4) )) (thread-sleep! 1) (debug:print-info 0 *default-log-port* "Connect to server for " dbfname) (tt:client-connect-to-server ttdat dbfname run-id testsuite))))))) (define (tt:timed-ping host port server-id) (let* ((start-time (current-milliseconds)) |
︙ | ︙ | |||
535 536 537 538 539 540 541 | (nosyncdbpath (conc areapath"/.mtdb")) (cleanup (lambda () (if (tt-cleanup-proc ttdat) ((tt-cleanup-proc ttdat))) (dbfile:with-no-sync-db nosyncdbpath (lambda (db) (let* ((dbtmpname (dbr:dbstruct-dbtmpname dbstruct))) | | | 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | (nosyncdbpath (conc areapath"/.mtdb")) (cleanup (lambda () (if (tt-cleanup-proc ttdat) ((tt-cleanup-proc ttdat))) (dbfile:with-no-sync-db nosyncdbpath (lambda (db) (let* ((dbtmpname (dbr:dbstruct-dbtmpname dbstruct))) (debug:print-info 0 *default-log-port* "keep-running: removing lock for file "dbtmpname) (db:no-sync-del! db dbfname) )))))) (set! *server-info* ttdat) (let loop ((count 0)) (if (> count 240) (begin (debug:print 0 *default-log-port* "FATAL: Could not start a tcp server, giving up.") |
︙ | ︙ |