Megatest

Diff
Login

Differences From Artifact [43fca71bc1]:

To Artifact [4c56626e6f]:


328
329
330
331
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346
347
(define (db:with-db dbstruct run-id r/w proc . params)
  (assert (dbr:dbstruct? dbstruct) "FATAL: db:with-db called with bad dbstruct")
  (let* ((dbpath    (db:run-id->dbname run-id))
	 (dbdat     (db:get-dbdat dbstruct *toppath* dbpath))
	 (db        (dbr:dbdat-inmem dbdat))
	 (fname     (dbr:dbdat-fname dbdat))
	 (use-mutex (> *api-process-request-count* 25))) ;; was 25
    (if (and use-mutex
	     (common:low-noise-print 120 "over-50-parallel-api-requests"))
	(debug:print-info 0 *default-log-port* *api-process-request-count* " parallel api requests being processed in process " (current-process-id) ", throttling access"))
    (if (common:low-noise-print 600 (conc "parallel-api-requests" *max-api-process-requests*))
	(debug:print-info 2 *default-log-port* "Parallel api request count: " *api-process-request-count* " max parallel requests: " *max-api-process-requests*))

    (condition-case
     (begin
       (if use-mutex (mutex-lock! *db-with-db-mutex*))
       (let ((res (apply proc db params)))
	 (if use-mutex (mutex-unlock! *db-with-db-mutex*))
	 ;; (if (vector? dbstruct)(db:done-with dbstruct run-id r/w))
	 res))
     (exn (io-error)







|


|

>
|







328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
(define (db:with-db dbstruct run-id r/w proc . params)
  (assert (dbr:dbstruct? dbstruct) "FATAL: db:with-db called with bad dbstruct")
  (let* ((dbpath    (db:run-id->dbname run-id))
	 (dbdat     (db:get-dbdat dbstruct *toppath* dbpath))
	 (db        (dbr:dbdat-inmem dbdat))
	 (fname     (dbr:dbdat-fname dbdat))
	 (use-mutex (> *api-process-request-count* 25))) ;; was 25
    #;(if (and use-mutex
	     (common:low-noise-print 120 "over-50-parallel-api-requests"))
	(debug:print-info 0 *default-log-port* *api-process-request-count* " parallel api requests being processed in process " (current-process-id) ", throttling access"))
    #;(if (common:low-noise-print 600 (conc "parallel-api-requests" *max-api-process-requests*))
	(debug:print-info 2 *default-log-port* "Parallel api request count: " *api-process-request-count* " max parallel requests: " *max-api-process-requests*))
     (apply proc db params)
    #;(condition-case
     (begin
       (if use-mutex (mutex-lock! *db-with-db-mutex*))
       (let ((res (apply proc db params)))
	 (if use-mutex (mutex-unlock! *db-with-db-mutex*))
	 ;; (if (vector? dbstruct)(db:done-with dbstruct run-id r/w))
	 res))
     (exn (io-error)
1266
1267
1268
1269
1270
1271
1272
1273

1274
1275
1276
1277
1278
1279
1280
1281
1282
       (sqlite3:execute db "CREATE TABLE IF NOT EXISTS servers
                                   (id INTEGER PRIMARY KEY,
                                    host TEXT,
                                    port INTEGER,
                                    servkey TEXT,
                                    pid TEXT,
                                    ipaddr TEXT,
                                    dbpath TEXT,

                                    event_time TIMESTAMP DEFAULT (strftime('%s','now')),
                               CONSTRAINT servers_constraint UNIQUE (dbpath));")

       (sqlite3:execute db "CREATE TABLE IF NOT EXISTS keys
                                    (id INTEGER PRIMARY KEY,
                                     fieldname TEXT,
                                     fieldtype TEXT,
                                CONSTRAINT keyconstraint UNIQUE (fieldname));")
       







|
>

|







1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
       (sqlite3:execute db "CREATE TABLE IF NOT EXISTS servers
                                   (id INTEGER PRIMARY KEY,
                                    host TEXT,
                                    port INTEGER,
                                    servkey TEXT,
                                    pid TEXT,
                                    ipaddr TEXT,
                                    apath TEXT,
                                    dbname TEXT,
                                    event_time TIMESTAMP DEFAULT (strftime('%s','now')),
                               CONSTRAINT servers_constraint UNIQUE (apath,dbname));")

       (sqlite3:execute db "CREATE TABLE IF NOT EXISTS keys
                                    (id INTEGER PRIMARY KEY,
                                     fieldname TEXT,
                                     fieldtype TEXT,
                                CONSTRAINT keyconstraint UNIQUE (fieldname));")
       
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526









5527
5528

5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
;;======================================================================
;; S E R V E R   R E C O R D S
;;======================================================================

;; these are all intended to be run against main.db

;; run this one in a transaction where first check if host:port is taken
(define (db:register-server dbstruct host port servkey pid ipaddr dbpath)
  (db:with-db
   dbstruct
   #f #f
   (lambda (db)









     (sqlite3:execute db "INSERT INTO servers (host,port,servkey,pid,ipaddr,dbpath) VALUES (?,?,?,?,?,?);"
		      host port servkey pid ipaddr dbpath))))


(define (db:get-server-info dbstruct apath dbname)
  (db:with-db
   dbstruct
   #f #f
   (lambda (db)
     (sqlite3:fold-row
      (lambda (res host port servkey pid ipaddr dbpath)
	(list host port servkey pid ipaddr dbpath))
      #f
      db
      "SELECT host,port,servkey,pid,ipaddr,dbpath FROM servers WHERE dbpath=?;"
      (conc apath "/" dbname)))))

)







|




>
>
>
>
>
>
>
>
>
|
|
>
|






|
|


|
|


5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
;;======================================================================
;; S E R V E R   R E C O R D S
;;======================================================================

;; these are all intended to be run against main.db

;; run this one in a transaction where first check if host:port is taken
(define (db:register-server dbstruct host port servkey pid ipaddr apath dbname)
  (db:with-db
   dbstruct
   #f #f
   (lambda (db)
     (sqlite3:with-transaction
      db
      (lambda ()
	(let* ((sinfo      (db:get-server-info dbstruct apath dbname)))
	  (if sinfo
	      (begin
		(debug:print-info 0 *default-log-port* "Server already running at "sinfo ", while trying to register server " host":"port)
		#f) ;; server already registered
	      (begin
		(sqlite3:execute db "INSERT INTO servers (host,port,servkey,pid,ipaddr,apath,dbname) VALUES (?,?,?,?,?,?,?);"
				 host port servkey pid ipaddr apath dbname)
		(db:get-server-info dbstruct apath dbname)))))))))
  
(define (db:get-server-info dbstruct apath dbname)
  (db:with-db
   dbstruct
   #f #f
   (lambda (db)
     (sqlite3:fold-row
      (lambda (res host port servkey pid ipaddr apath dbpath)
	(list host port servkey pid ipaddr apath dbpath))
      #f
      db
      "SELECT host,port,servkey,pid,ipaddr,apath,dbname FROM servers WHERE apath=? AND dbname=?;"
      apath dbname))))

)