Megatest

Diff
Login

Differences From Artifact [133c3d1663]:

To Artifact [50f8ec9e6b]:


1141
1142
1143
1144
1145
1146
1147
1148
1149
1150


1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
	      (loop (+ count 1))))))
    (with-output-to-file crumbn
      (lambda ()
	(print fname" run-id="run-id" params="params)
	))
    crumbn))

;; (db:with-db dbstruct run-id sqlite3:exec "select blah fgrom blaz;")
;; r/w is a flag to indicate if the db is modified by this query #t = yes, #f = no
;;


(define (dbfile:with-db dbstruct run-id r/w proc params)
  (assert dbstruct "FATAL: db:with-db called with dbstruct "#f)
  (assert (dbr:dbstruct? dbstruct) "FATAL: dbstruct is "dbstruct)
  ;; Testing 2023, March 14th. I went from full time use of the mutext to no use at all and
  ;; didn't see much change in the frequency of the messages:
  ;; Warning (#<thread: thread14974>): in thread: (bind!) bad parameter or other API misuse
  ;; allowing request count to go up to 1000 and other crashes showed up:
  ;; Warning (#<thread: thread1889>): in thread: (deserialize) unexpected end of input: #<input port "(tcp)">
  ;;
  ;; leave it fully on for now, test later if there is a performance issue
  ;;
  (let* ((use-mutex   #t) ;;(> *api-process-request-count* 50)) ;; risk of db corruption
	 (have-struct (dbr:dbstruct? dbstruct))
         (dbdat       (if have-struct                ;; this stuff just allows us to call with a db handle directly
			  (db:open-db dbstruct run-id (dbfile:db-init-proc)) ;; (dbfile:get-subdb dbstruct run-id)
			  #f))
	 (db          (if have-struct                ;; this stuff just allows us to call with a db handle directly
			  (dbr:dbdat-dbh dbdat)
			  dbstruct))
	 (fname       (if dbdat
			  (dbr:dbdat-dbfile dbdat)
			  "nofilenameavailable"))
	 (jfile       (conc fname"-journal"))
	 (qryproc     (lambda ()
			(if use-mutex (mutex-lock! *db-with-db-mutex*))
			(let ((res (apply proc dbdat db params))) ;; the actual call is here.
			  (if use-mutex (mutex-unlock! *db-with-db-mutex*))
			  ;; (if (vector? dbstruct)(db:done-with dbstruct run-id r/w))
			  (if dbdat
			      (dbfile:add-dbdat dbstruct run-id dbdat))
			  ;; (delete-file* crumbfile)
			  res)))
	 (stop-train  (conc (dbr:dbstruct-areapath dbstruct)"/stop-the-train")))

    (assert (sqlite3:database? db) "FATAL: db:with-db, db is not a database, db="db
	    ", fname="fname)
    (if (file-exists? jfile)
	(begin
	  (dbfile:print-err "INFO: "jfile" exists, delaying to reduce database load")
	  (thread-sleep! 0.2)))
    (if (and use-mutex
	     (common:low-noise-print 120 "over-50-parallel-api-requests"))
	(dbfile:print-err *api-process-request-count*
			  " parallel api requests being processed in process "
			  (current-process-id))) ;;  ", throttling access"))
    (case (no-condition-db-with-db)
      ((production)(qryproc))
      ((suicide-mode)
       (handle-exceptions
	exn
	(with-output-to-file stop-train
	  (lambda ()
	    (db:generic-error-printout exn "Stop train mode, run-id: "run-id
				       " params: "params" proc: "proc)))
	(qryproc)))
      (else
       (condition-case
	(qryproc)
	(exn (io-error)
	     (db:generic-error-printout exn "ERROR: i/o error with "fname
					". Check permissions, disk space etc. and try again."))
	(exn (corrupt)
	     (db:generic-error-printout exn "ERROR: database "fname
					" is corrupt. Repair it to proceed."))
	(exn (busy)
	     (db:generic-error-printout exn "ERROR: database "fname
					" is locked. Try copying to another location,"
					" remove original and copy back."))
	(exn (permission)(db:generic-error-printout exn "ERROR: database "fname
						    " has some permissions problem."))
	(exn ()
	     (db:generic-error-printout exn "ERROR: Unknown error with database "fname
					" message: "
					((condition-property-accessor 'exn 'message) exn))))))))

;;======================================================================
;; another attempt at a transactionized queue
;;======================================================================

;; ;; ;; (define *transaction-queues* (make-hash-table))
;; ;; ;; 







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







1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
	      (loop (+ count 1))))))
    (with-output-to-file crumbn
      (lambda ()
	(print fname" run-id="run-id" params="params)
	))
    crumbn))

;; ;; (db:with-db dbstruct run-id sqlite3:exec "select blah fgrom blaz;")
;; ;; r/w is a flag to indicate if the db is modified by this query #t = yes, #f = no
;; ;;
;; ;; Used only with http - to be removed
;; ;;
;; (define (dbfile:with-db dbstruct run-id r/w proc params)
;;   (assert dbstruct "FATAL: db:with-db called with dbstruct "#f)
;;   (assert (dbr:dbstruct? dbstruct) "FATAL: dbstruct is "dbstruct)
;;   ;; Testing 2023, March 14th. I went from full time use of the mutext to no use at all and
;;   ;; didn't see much change in the frequency of the messages:
;;   ;; Warning (#<thread: thread14974>): in thread: (bind!) bad parameter or other API misuse
;;   ;; allowing request count to go up to 1000 and other crashes showed up:
;;   ;; Warning (#<thread: thread1889>): in thread: (deserialize) unexpected end of input: #<input port "(tcp)">
;;   ;;
;;   ;; leave it fully on for now, test later if there is a performance issue
;;   ;;
;;   (let* ((use-mutex   #t) ;;(> *api-process-request-count* 50)) ;; risk of db corruption
;; 	 (have-struct (dbr:dbstruct? dbstruct))
;;          (dbdat       (if have-struct                ;; this stuff just allows us to call with a db handle directly
;; 			  (db:open-db dbstruct run-id (dbfile:db-init-proc)) ;; (dbfile:get-subdb dbstruct run-id)
;; 			  #f))
;; 	 (db          (if have-struct                ;; this stuff just allows us to call with a db handle directly
;; 			  (dbr:dbdat-dbh dbdat)
;; 			  dbstruct))
;; 	 (fname       (if dbdat
;; 			  (dbr:dbdat-dbfile dbdat)
;; 			  "nofilenameavailable"))
;; 	 (jfile       (conc fname"-journal"))
;; 	 (qryproc     (lambda ()
;; 			(if use-mutex (mutex-lock! *db-with-db-mutex*))
;; 			(let ((res (apply proc dbdat db params))) ;; the actual call is here.
;; 			  (if use-mutex (mutex-unlock! *db-with-db-mutex*))
;; 			  ;; (if (vector? dbstruct)(db:done-with dbstruct run-id r/w))
;; 			  (if dbdat
;; 			      (dbfile:add-dbdat dbstruct run-id dbdat))
;; 			  ;; (delete-file* crumbfile)
;; 			  res)))
;; 	 (stop-train  (conc (dbr:dbstruct-areapath dbstruct)"/stop-the-train")))
;; 
;;     (assert (sqlite3:database? db) "FATAL: db:with-db, db is not a database, db="db
;; 	    ", fname="fname)
;;     (if (file-exists? jfile)
;; 	(begin
;; 	  (dbfile:print-err "INFO: "jfile" exists, delaying to reduce database load")
;; 	  (thread-sleep! 0.2)))
;;     (if (and use-mutex
;; 	     (common:low-noise-print 120 "over-50-parallel-api-requests"))
;; 	(dbfile:print-err *api-process-request-count*
;; 			  " parallel api requests being processed in process "
;; 			  (current-process-id))) ;;  ", throttling access"))
;;     (case (no-condition-db-with-db)
;;       ((production)(qryproc))
;;       ((suicide-mode)
;;        (handle-exceptions
;; 	exn
;; 	(with-output-to-file stop-train
;; 	  (lambda ()
;; 	    (db:generic-error-printout exn "Stop train mode, run-id: "run-id
;; 				       " params: "params" proc: "proc)))
;; 	(qryproc)))
;;       (else
;;        (condition-case
;; 	(qryproc)
;; 	(exn (io-error)
;; 	     (db:generic-error-printout exn "ERROR: i/o error with "fname
;; 					". Check permissions, disk space etc. and try again."))
;; 	(exn (corrupt)
;; 	     (db:generic-error-printout exn "ERROR: database "fname
;; 					" is corrupt. Repair it to proceed."))
;; 	(exn (busy)
;; 	     (db:generic-error-printout exn "ERROR: database "fname
;; 					" is locked. Try copying to another location,"
;; 					" remove original and copy back."))
;; 	(exn (permission)(db:generic-error-printout exn "ERROR: database "fname
;; 						    " has some permissions problem."))
;; 	(exn ()
;; 	     (db:generic-error-printout exn "ERROR: Unknown error with database "fname
;; 					" message: "
;; 					((condition-property-accessor 'exn 'message) exn))))))))

;;======================================================================
;; another attempt at a transactionized queue
;;======================================================================

;; ;; ;; (define *transaction-queues* (make-hash-table))
;; ;; ;;