Megatest

Check-in [23bde8f1b3]
Login
Overview
Comment:Cherrypicked 5a53
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.7001-rebase-wip | v1.7001-multi-db-rb01
Files: files | file ages | folders
SHA1: 23bde8f1b3b8c6d77de5549da683a56576ed45be
User & Date: matt on 2022-04-21 20:03:56
Other Links: branch diff | manifest | tags
Context
2022-04-21
20:06
Cherrypicked 7f0a and 98e7 check-in: 6d400573c0 user: matt tags: v1.7001-rebase-wip, v1.7001-multi-db-rb01
20:03
Cherrypicked 5a53 check-in: 23bde8f1b3 user: matt tags: v1.7001-rebase-wip, v1.7001-multi-db-rb01
19:36
Cherrypicked bd65 and a82e check-in: 0b155d7512 user: matt tags: v1.7001-rebase-wip, v1.7001-multi-db-rb01
Changes

Modified dbfile.scm from [8191885fae] to [1fd4f57fed].

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
;;

;; Open the classic megatest.db file (defaults to open in toppath)
;;
;;   NOTE: returns a dbdat not a dbstruct!
;;
(define (dbfile:open-sqlite3-db dbpath init-proc)
  (let* ((dbexists     (file-exists? dbpath))
	 (db           ;; need locking here so multiple open
	  ;; do not collide
	  (begin
	    
	    (let* ((db (sqlite3:open-database dbpath)))
	      (sqlite3:set-busy-handler! db (sqlite3:make-busy-timeout 10000))
	      (if (not dbexists)
		  (init-proc db))

	      db))
	  #;(dbfile:lock-create-open dbpath
	  (lambda (db)
	  (init-proc db))))
	 (write-access (file-write-access? dbpath)))
    #;(if (and dbexists (not write-access))
	(set! *db-write-access* #f))
    ;; (cons db dbpath)))

    (make-dbr:dbdat dbfile: dbpath dbh: db read-only: (not write-access))))

(define (dbfile:print-and-exit . params)
  (with-output-to-port
      (current-error-port)
    (lambda ()
      (apply print params)))







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







270
271
272
273
274
275
276














277



278
279
280
281
282
283
284
285
;;

;; Open the classic megatest.db file (defaults to open in toppath)
;;
;;   NOTE: returns a dbdat not a dbstruct!
;;
(define (dbfile:open-sqlite3-db dbpath init-proc)














  (let* ((write-access (file-write-access? dbpath))



	 (db           (dbfile:cautious-open-database dbpath init-proc)))
    (make-dbr:dbdat dbfile: dbpath dbh: db read-only: (not write-access))))

(define (dbfile:print-and-exit . params)
  (with-output-to-port
      (current-error-port)
    (lambda ()
      (apply print params)))
449
450
451
452
453
454
455
456
457
458
459
460
461

462




463
464
465
466
467
468
469
    tmpdb))
		
;;======================================================================
;; no-sync.db - small bits of data to be shared between servers
;;======================================================================


(define (dbfile:cautious-open-database fname #!optional (tries-left 5))
  (let* ((retry (lambda ()
		  (thread-sleep! 0.5)
		  (if (> tries-left 0)
		      (dbfile:cautious-open-database fname (- tries-left 1))))))
    (condition-case

	(sqlite3:open-database fname)




      (exn (io-error)
	   (dbfile:print-err exn "ERROR: i/o error with " fname ". Check permissions, disk space etc. and try again.")
	   (retry))
      (exn (corrupt)
	   (dbfile:print-err exn "ERROR: database " fname " is corrupt. Repair it to proceed.")
	   (retry))
      (exn (busy)







|



|

>
|
>
>
>
>







433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
    tmpdb))
		
;;======================================================================
;; no-sync.db - small bits of data to be shared between servers
;;======================================================================


(define (dbfile:cautious-open-database fname init-proc #!optional (tries-left 10))
  (let* ((retry (lambda ()
		  (thread-sleep! 0.5)
		  (if (> tries-left 0)
		      (dbfile:cautious-open-database fname init-proc (- tries-left 1))))))
    (condition-case
	(let* ((db-exists (file-exists? fname))
               (db        (sqlite3:open-database fname)))
	    (if (and init-proc (not db-exists))
	        (init-proc db))
            (sqlite3:set-busy-handler! db (sqlite3:make-busy-timeout 136000))
		 db)
      (exn (io-error)
	   (dbfile:print-err exn "ERROR: i/o error with " fname ". Check permissions, disk space etc. and try again.")
	   (retry))
      (exn (corrupt)
	   (dbfile:print-err exn "ERROR: database " fname " is corrupt. Repair it to proceed.")
	   (retry))
      (exn (busy)
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
	   (retry)))))

(define (dbfile:open-no-sync-db dbpath)
  (if (not (file-exists? dbpath))
      (create-directory dbpath #t))
  (let* ((dbname    (conc dbpath "/no-sync.db"))
	 (db-exists (file-exists? dbname))
	 (db        (dbfile:cautious-open-database dbname))) ;; (sqlite3:open-database dbname)))
    (sqlite3:set-busy-handler! db (sqlite3:make-busy-timeout 136000))
    (if (not db-exists)
	(begin
	  (sqlite3:execute db "PRAGMA synchronous = 0;")
	  (sqlite3:execute db "CREATE TABLE IF NOT EXISTS no_sync_metadat (var TEXT,val TEXT, CONSTRAINT no_sync_metadat_constraint UNIQUE (var));")
	  #;(sqlite3:execute db "PRAGMA journal_mode=WAL;")))
    db))

(define (db:no-sync-set db var val)
  (sqlite3:execute db "INSERT OR REPLACE INTO no_sync_metadat (var,val) VALUES (?,?);" var val))

(define (db:no-sync-del! db var)
  (sqlite3:execute db "DELETE FROM no_sync_metadat WHERE var=?;" var))







|




|
|







467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
	   (retry)))))

(define (dbfile:open-no-sync-db dbpath)
  (if (not (file-exists? dbpath))
      (create-directory dbpath #t))
  (let* ((dbname    (conc dbpath "/no-sync.db"))
	 (db-exists (file-exists? dbname))
	 (db        (dbfile:cautious-open-database dbname)))
    (sqlite3:set-busy-handler! db (sqlite3:make-busy-timeout 136000))
    (if (not db-exists)
	(begin
	  (sqlite3:execute db "PRAGMA synchronous = 0;")
	  (sqlite3:execute db "CREATE TABLE IF NOT EXISTS no_sync_metadat (var TEXT,val TEXT, CONSTRAINT no_sync_metadat_constraint UNIQUE (var));")))
	  ;; (sqlite3:execute db "PRAGMA journal_mode=WAL;")))
    db))

(define (db:no-sync-set db var val)
  (sqlite3:execute db "INSERT OR REPLACE INTO no_sync_metadat (var,val) VALUES (?,?);" var val))

(define (db:no-sync-del! db var)
  (sqlite3:execute db "DELETE FROM no_sync_metadat WHERE var=?;" var))