Megatest

Check-in [3576b029da]
Login
Overview
Comment:wip
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.6584-ck5
Files: files | file ages | folders
SHA1: 3576b029daf55679881ef9d5ee8348c9032a0649
User & Date: matt on 2021-05-20 21:23:34
Other Links: branch diff | manifest | tags
Context
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
20:33
wip check-in: ffccd73793 user: matt tags: v1.6584-ck5
Changes

Modified rmtmod.scm from [2a788fb0b5] to [faeb47f828].

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
;; do we have a connection to apath dbname and
;; is it not expired? then return it
;;
;; else setup a connection
;;
;; if that fails, return '(#f "some reason") ;; NB// convert to raising an exception
;;
(define (rmt:get-connection remote apath dbname)
  (let* ((fullname (db:dbname->path apath dbname)) ;; we'll switch to full name later
	 (conn     (hash-table-ref/default (rmt:remote-conns remote) dbname #f)))
    (if (and conn
	     (< (current-seconds) (rmt:conn-expires conn)))
	conn
	#f)))








|







204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
;; do we have a connection to apath dbname and
;; is it not expired? then return it
;;
;; else setup a connection
;;
;; if that fails, return '(#f "some reason") ;; NB// convert to raising an exception
;;
(define (rmt:get-conn remote apath dbname)
  (let* ((fullname (db:dbname->path apath dbname)) ;; we'll switch to full name later
	 (conn     (hash-table-ref/default (rmt:remote-conns remote) dbname #f)))
    (if (and conn
	     (< (current-seconds) (rmt:conn-expires conn)))
	conn
	#f)))

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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
				  lastmsg: (current-seconds)
				  expires: (+ (current-seconds) 60) ;; this needs to be gathered during the ping
				  ))
		#t)
	      (start-main-srv)))
	(start-main-srv))))

(define (rmt:main-open-connection remote apath)
  (rmt:open-main-connection remote apath)
  (rmt:get-connection remote apath (db:run-id->dbname #f)))

;; NB// remote is a rmt:remote struct
;;
(define (rmt:general-open-connection remote apath dbname #!key (num-tries 5))

  (let  ((mainconn (rmt:get-connection remote apath (db:run-id->dbname #f))))
    ;; (debug:print 0 *default-log-port* "remote: " remote)
    (if (not mainconn)
	(begin
	  (rmt:open-main-connection remote apath)
	  (thread-sleep! 2)
	  (rmt:general-open-connection remote apath dbname))
	;; we have a connection to main, ask for contact info for dbname

	(let* ((res (rmt:send-receive-real remote apath dbname 'get-server #f `(,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)))
		 'failed))
	    

	    (else
	     (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: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)))
    (if conn
	(let* (;; (host    (rmt:conn-ipaddr conn))
	       ;; (port    (rmt:conn-port   conn))
	       (payload (sexpr->string params))
	       (res      (with-input-from-request
			  (rmt:conn->uri conn "api")
			  `((params . ,payload)
			    (cmd    . ,cmd)
			    (key    . "nokey"))
			  read-string)))
	  (if (string? res)
	      (string->sexpr res)
	      res))
	;; no conn yet, start it up
	(begin
	  (rmt:general-open-connection remote apath dbname)
	  (rmt:send-receive-real remote apath dbname rid cmd params)))))

;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed
;; sometime in the future.
;;
;; Purpose - call the main.db server and request a server be started
;; for the given area path and dbname
;;
(define (rmt:send-receive-server-start remote apath dbname)
  (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
		      (rmt:conn->uri conn "api") ;; (conc "http://"host":"port"/api")
		      `((params . (,apath ,dbname))
			;; (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"))







<
<
<
<



>
|
<
<
<
|
|
|
<
>
|
|
|
|
|
|
|
|
|
|
>
|
|
|










>






|
|
<
<
|
|
|
|
|
|
|
|
|
|
<
<
<
<








|

<
<
<
|
|
|
<
<







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



325
326
327


328
329
330
331
332
333
334
				  lastmsg: (current-seconds)
				  expires: (+ (current-seconds) 60) ;; this needs to be gathered during the ping
				  ))
		#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))
  (cond
   ((not (rmt:get-conn remote apath (db:run-id->dbname #f))) ;; no channel open to main? 



    (rmt:open-main-connection remote apath)
    (thread-sleep! 2)
    (rmt:general-open-connection remote apath dbname))

   ((not (rmt:get-conn remote apath dbname))                 ;; no channel open to dbname?     
    (let* ((res (rmt:send-receive-real remote apath dbname #f '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
	 (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 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-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)
			(key    . "nokey"))
		      read-string)))
      (if (string? res)
	  (string->sexpr res)
	  res))))





;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed
;; sometime in the future.
;;
;; Purpose - call the main.db server and request a server be started
;; for the given area path and dbname
;;
(define (rmt:send-receive-server-start remote apath dbname)
  (let* ((conn (rmt:get-conn remote apath dbname)))
    (assert conn "FATAL: Unable to connect to db "apath"/"dbname)



    (let* ((res      (with-input-from-request
		      (rmt:conn->uri conn "api") 
		      `((params . (,apath ,dbname)))


		      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"))

Modified tests/unittests/basicserver.scm from [1f95013738] to [d917ba01d8].

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
 ;; rmt:send-receive-real
 ;; rmt:send-receive
 ;; sexpr->string
 ;; server-ready?
 ;; rmt:register-server
 ;; rmt:open-main-connection
 ;; rmt:general-open-connection
 ;; rmt:get-connection
 ;; common:watchdog
 ;; rmt:find-main-server
 ;; get-all-server-pkts
 ;; get-viable-servers
 ;; get-best-candidate
 ;; api:run-server-process
 )

(test #f #t (rmt:remote? (let ((r (make-rmt:remote)))
			   (set! *rmt:remote* r)
			   r)))
(test #f #f (rmt:get-connection *rmt:remote* *toppath* ".db/main.db"))
(test #f #f (rmt:find-main-server *toppath* ".db/main.db"))
(test #f #t (rmt:open-main-connection *rmt:remote* *toppath*))
(pp (hash-table->alist (rmt:remote-conns *rmt:remote*)))
(test #f #t (rmt:conn? (rmt:get-connection *rmt:remote* *toppath* ".db/main.db")))

(define *main*  (rmt:get-connection *rmt:remote* *toppath* ".db/main.db"))

(for-each (lambda (tdat)
	    (test #f tdat (loop-test (rmt:conn-ipaddr *main*)
				     (rmt:conn-port *main*) tdat)))
	  (list 'a
		'(a "b" 123 1.23 )))
(test #f #t (number? (rmt:send-receive 'ping #f 'hello)))

(define *db* (db:setup #f))






(test #f 'server-started (api:execute-requests *db* 'get-server (list *toppath* ".db/1.db")))
(set! *dbstruct-db* #f)


(test #f 'server-started (rmt:general-open-connection *rmt:remote* *toppath* ".db/1.db"))
(thread-sleep! 2)
(test #f 'server-started (rmt:general-open-connection *rmt:remote* *toppath* ".db/1.db"))

(test #f '("SYSTEM" "RELEASE") (rmt:get-keys))
(test #f 1 (rmt:register-run '(("SYSTEM" "a")("RELEASE" "b")) "run1" "new" "n/a" "justme" #f))

;; (delete-file* "logs/1.log")







|











|



|

|









>
>
>
>
>
>


>
>
|







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
 ;; rmt:send-receive-real
 ;; rmt:send-receive
 ;; sexpr->string
 ;; server-ready?
 ;; rmt:register-server
 ;; rmt:open-main-connection
 ;; rmt:general-open-connection
 ;; rmt:get-conny
 ;; common:watchdog
 ;; rmt:find-main-server
 ;; get-all-server-pkts
 ;; get-viable-servers
 ;; get-best-candidate
 ;; api:run-server-process
 )

(test #f #t (rmt:remote? (let ((r (make-rmt:remote)))
			   (set! *rmt:remote* r)
			   r)))
(test #f #f (rmt:get-conn *rmt:remote* *toppath* ".db/main.db"))
(test #f #f (rmt:find-main-server *toppath* ".db/main.db"))
(test #f #t (rmt:open-main-connection *rmt:remote* *toppath*))
(pp (hash-table->alist (rmt:remote-conns *rmt:remote*)))
(test #f #t (rmt:conn? (rmt:get-conn *rmt:remote* *toppath* ".db/main.db")))

(define *main*  (rmt:get-conn *rmt:remote* *toppath* ".db/main.db"))

(for-each (lambda (tdat)
	    (test #f tdat (loop-test (rmt:conn-ipaddr *main*)
				     (rmt:conn-port *main*) tdat)))
	  (list 'a
		'(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/1.db")
(define remote *rmt:remote*)

(test #f 'server-started (api:execute-requests *db* 'get-server (list *toppath* ".db/1.db")))
(set! *dbstruct-db* #f)
(test #f #t (rmt:open-main-connection remote apath))
(test #f 'server-started (rmt:send-receive-real remote apath ".db/main.db" #f 'get-server `(,apath ,dbname)))

(thread-sleep! 2)
(test #f 'server-started (rmt:general-open-connection *rmt:remote* *toppath* ".db/1.db"))

(test #f '("SYSTEM" "RELEASE") (rmt:get-keys))
(test #f 1 (rmt:register-run '(("SYSTEM" "a")("RELEASE" "b")) "run1" "new" "n/a" "justme" #f))

;; (delete-file* "logs/1.log")