Megatest

Check-in [9361d9fe7b]
Login
Overview
Comment:db2db works (at least with attach mode syncing)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.80-servload
Files: files | file ages | folders
SHA1: 9361d9fe7be79df87a86971dee1c3f5c3eddccf6
User & Date: matt on 2023-05-01 09:00:32
Other Links: branch diff | manifest | tags
Context
2023-05-01
10:02
wip check-in: 9b4499570c user: matt tags: v1.80-servload
09:00
db2db works (at least with attach mode syncing) check-in: 9361d9fe7b user: matt tags: v1.80-servload
2023-04-30
20:59
db2db sync almost working check-in: 2a182fc8db user: matt tags: v1.80-servload
Changes

Modified dbmod.scm from [6ce3b69143] to [f2c3610f44].

448
449
450
451
452
453
454
455


456
457
458
459
460
461
462
448
449
450
451
452
453
454

455
456
457
458
459
460
461
462
463







-
+
+







			   (mode 'full)
			   (no-update '("keys")) ;; do
			   )
  (debug:print 0 *default-log-port* "Doing sync "direction" "destdbfile)
  (if (not (sqlite3:auto-committing? dbh))
      (debug:print 0 *default-log-port* "Skipping sync due to transaction in flight.")
      (let* ((table-names  (map car tables))
	     (dest-exists  (file-exists? destdbfile)))
	     (dest-exists  (file-exists? destdbfile))
	     (start-time   (current-milliseconds)))
	(assert dest-exists "FATAL: sync called with non-existant file, "destdbfile)
	;; attach the destdbfile
	;; for each table
	;;    insert into dest.<table> select * from src.<table> where last_update>last_update
	;; done
	(debug:print 0 *default-log-port* "Attaching "destdbfile" as auxdb")
	(sqlite3:execute dbh (conc "ATTACH '"destdbfile"' AS auxdb;"))
485
486
487
488
489
490
491
492

493
494
495
496


497
498
499
500
501
502
503
504
505
506
507



508
509
510
511
512
513
514
486
487
488
489
490
491
492

493
494
495


496
497
498
499
500
501
502
503
504
505
506
507

508
509
510
511
512
513
514
515
516
517







-
+


-
-
+
+










-
+
+
+







	     ;; (debug:print 0 *default-log-port* "stmt8="stmt8)
	     ;; (if (sqlite3:auto-committing? dbh)
	     ;; (begin
	     (mutex-lock! *db-transaction-mutex*)
	     (sqlite3:with-transaction
	      dbh
	      (lambda ()
		(debug:print-info 0 *default-log-port* "Sync from "fromdb table" to "todb table" using "stmt1)
		(debug:print-info 0 *default-log-port* "Sync from "fromdb table" to "todb table" using INSERT OR UPDATE")
		(sqlite3:execute dbh stmt1)    ;; get all new rows
		
		#;(if (member "last_update" fields)
		(sqlite3:execute dbh stmt8))    ;; get all updated rows
		(if (member "last_update" fields)
		    (sqlite3:execute dbh stmt8))    ;; get all updated rows
		;; (sqlite3:execute dbh stmt5)
		;; (sqlite3:execute dbh stmt4) ;; if it worked this would be better for incremental up
		;; (sqlite3:execute dbh stmt6)
		))
	     (debug:print 0 *default-log-port* "Synced table "table
			  " in "(- (current-milliseconds) start-ms)"ms") ;; )
	     (mutex-unlock! *db-transaction-mutex*)))
	     
	 ;; (debug:print 0 *default-log-port* "Skipping sync of table "table" due to transaction in flight."))))
	 table-names)
	(sqlite3:execute dbh "DETACH auxdb;"))))
	(sqlite3:execute dbh "DETACH auxdb;")
	(debug:print-info 0 *default-log-port* "Total sync time: "(- (current-milliseconds) start-time)"ms")
	-1)))

;; FAILED ATTEMPTS

	     ;; (if (not (has-last-update dbh table))
	     ;;     (sqlite3:execute dbh (conc "ALTER TABLE "table" ADD COLUMN last_update INTEGER;")))
	     ;; (if (not (has-last-update dbh (conc "auxdb."table)))
	     ;;     (sqlite3:execute dbh (conc "ALTER TABLE auxdb."table" ADD COLUMN last_update INTEGER;")))
793
794
795
796
797
798
799
800
801
802
803





804
805
806
807
808
809
796
797
798
799
800
801
802




803
804
805
806
807
808
809
810
811
812
813







-
-
-
-
+
+
+
+
+






;;======================================================================

(define (dbmod:db-to-db-sync src-db dest-db last-update init-proc keys)
  (if (and (file-exists? src-db)
	   (file-read-access? src-db))
      (let* ((d-wr   (or (and (file-exists? dest-db)
			      (file-write-access? dest-db)) ;; exists and writable
			 (let* ((dirname (pathname-directory dest-db)))
			   (and dirname
				(file-exists? dirname)
				(file-write-access? dirname)))))
			 (let* ((dirname (or (pathname-directory dest-db)
					     ".")))
			   (if dirname
			       (file-exists? dirname)
			       (file-write-access? dirname)))))
	     (tables (db:sync-all-tables-list keys))
	     (sdb    (dbmod:safely-open-db src-db init-proc #t))
	     (ddb    (dbmod:safely-open-db dest-db init-proc d-wr)))
	(dbmod:sync-gasket tables last-update sdb ddb dest-db 'todest))))

)

Modified launch.scm from [aa8485d496] to [4dac8c9f9e].

1154
1155
1156
1157
1158
1159
1160
1161


1162
1163
1164
1165
1166





1167
1168
1169
1170
1171
1172
1173
1154
1155
1156
1157
1158
1159
1160

1161
1162
1163
1164
1165


1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177







-
+
+



-
-
+
+
+
+
+








	;; if have -append-config then read and append here
	(let ((cfname (args:get-arg "-append-config")))
	  (if (and cfname
		   (file-read-access? cfname))
	      (read-config cfname *configdat* #t))) ;; values are added to the hash, no need to do anything special.
	;; have config at this time, this is a good place to set params based on config file settings
	(let*  ((dbmode (configf:lookup *configdat* "setup" "dbcache-mode")))
	(let*  ((dbmode   (configf:lookup *configdat* "setup" "dbcache-mode"))
		(syncmode (configf:lookup *configdat* "setup" "sync-mode")))
	  (if dbmode
	      (begin
		(debug:print-info 0 *default-log-port* "Overriding dbmode to "dbmode)
		(dbcache-mode (string->symbol dbmode)))))
	
		(dbcache-mode (string->symbol dbmode))))
	  (if syncmode
	      (begin
		(debug:print-info 0 *default-log-port* "Overriding syncmode to "syncmode)
		(dbfile:sync-method (string->symbol syncmode)))))
	*toppath*)))


(define (get-best-disk confdat testconfig)
  (let* ((disks   (or (and testconfig (hash-table-ref/default testconfig "disks" #f))
		      (hash-table-ref/default confdat "disks" #f)))
	 (minspace (let ((m (configf:lookup confdat "setup" "minspace")))

Modified megatest.scm from [a35d824cd5] to [28717a0520].

2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573






2574
2575

2576
2577
2578
2579



2580
2581
2582
2583
2584
2585
2586
2563
2564
2565
2566
2567
2568
2569




2570
2571
2572
2573
2574
2575
2576

2577
2578



2579
2580
2581
2582
2583
2584
2585
2586
2587
2588







-
-
-
-
+
+
+
+
+
+

-
+

-
-
-
+
+
+







    (let ((toppath (launch:setup)))
      (tasks:sync-to-postgres *configdat* (args:get-arg "-sync-to"))
      (set! *didsomething* #t)))

;; use with -from and -to
;;
(if (args:get-arg "-db2db")
    (let* ((duh      (launch:setup))
	   (src-db   (args:get-arg "-from"))
	   (dest-db  (args:get-arg "-to"))
	   (lockfile (conc dest-db".lock"))
    (let* ((duh         (launch:setup))
	   (src-db      (args:get-arg "-from"))
	   (dest-db     (args:get-arg "-to"))
	   (sync-period (args:get-arg "-period"))    ;; NOT IMPLEMENTED YET
	   (sync-timeout (args:get-arg "-timeout"))  ;; NOT IMPLEMENTED YET
	   (lockfile    (conc dest-db".lock"))
	   ;; (locked   (common:simple-file-lock lockfile))
	   (keys     (db:get-keys #f))
	   (keys        (db:get-keys #f))
	   (res      ;; (if locked
			 (dbmod:db-to-db-sync src-db dest-db 0 (dbfile:db-init-proc) keys)
			 ;;	 #f)))
			 ))
	    (dbmod:db-to-db-sync src-db dest-db 0 (dbfile:db-init-proc) keys)
	    ;;	 #f)))
	    ))
      
      (if (and src-db dest-db)
	  (begin
	    (debug:print-info 0 *default-log-port* "Attempting to sync data from "src-db" to "dest-db"...")
	    (if res
		(begin
		  (common:simple-file-release-lock lockfile)