Megatest

Check-in [31c8ca7f78]
Login
Overview
Comment:coordinate multiple servers such that only one server will be syncing exclusively at any given momemt\
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.65
Files: files | file ages | folders
SHA1: 31c8ca7f7868fc612e50a40a8b336abfe59947c2
User & Date: bjbarcla on 2019-02-07 17:16:48
Other Links: branch diff | manifest | tags
Context
2019-02-11
11:35
merged brute force syncer check-in: 2aaccbd409 user: bjbarcla tags: v1.65, v1.6524
2019-02-07
22:53
Try Brandon's idea of using sqlite3 dump to sync to legacy megatest.db check-in: 542079c778 user: matt tags: v1.65-dump-for-sync
17:16
coordinate multiple servers such that only one server will be syncing exclusively at any given momemt\ check-in: 31c8ca7f78 user: bjbarcla tags: v1.65
17:13
add todo check-in: 081ae45cc8 user: bjbarcla tags: v1.65
Changes

Modified common.scm from [f3a824a935] to [c75d843fa5].

2481
2482
2483
2484
2485
2486
2487




2488
2489
2490
2491
2492
2493
2494
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498







+
+
+
+







        #t)
      #f))

;; simple lock. improve and converge on this one.
;;
(define (common:simple-lock keyname)
  (rmt:no-sync-get-lock keyname))

(define (common:simple-unlock keyname #!key (force #f))
  (rmt:no-sync-del! keyname))


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

(define (common:in-running-test?)
  (and (args:get-arg "-execute") (get-environment-variable "MT_CMDINFO")))

Modified server.scm from [8c943654ab] to [e8ffc74269].

479
480
481
482
483
484
485
















486
487
488
489
490
491
492
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	   (set! res adr)))
     ;; NOTE: This can fail when there is no mention of the host in /etc/hosts. FIXME
     (vector->list (hostinfo-addresses (hostname->hostinfo hostname))))
    (string-intersperse 
     (map number->string
	  (u8vector->list
	   (if res res (hostname->ip hostname)))) ".")))

(define server:sync-lock-token "SERVER_SYNC_LOCK")
(define (server:release-sync-lock)
  (db:no-sync-del! *no-sync-db* server:sync-lock-token))
(define (server:have-sync-lock?)
  (let* ((have-lock-pair (db:no-sync-get-lock *no-sync-db* server:sync-lock-token))
         (have-lock?     (car have-lock-pair))
         (lock-time      (cdr have-lock-pair))
         (lock-age       (- (current-seconds) lock-time)))
    (cond
     (have-lock? #t)
     ((>lock-age
       (* 3 (configf:lookup-number *configdat* "server" "minimum-intersync-delay" default: 180)))
      (server:release-sync-lock)
      (server:have-sync-lock?))
     (else #f))))

;; moving this here as it needs access to db and cannot be in common.
;;
(define (server:writable-watchdog dbstruct)
  (thread-sleep! 0.05) ;; delay for startup
  (let ((legacy-sync  (common:run-sync?))
        (sync-stale-seconds (configf:lookup-number *configdat* "server" "sync-stale-seconds" default: 300))
508
509
510
511
512
513
514
515


516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533


534
535
536
537








538
539
540
541
542
543
544
524
525
526
527
528
529
530

531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549

550
551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569







-
+
+

















-
+
+



-
+
+
+
+
+
+
+
+







	       (end-file   (conc tmp-area "/.end-sync")))
	  (debug:print-info 0 *default-log-port* "Server running, periodic sync started.")
	  (let loop ()
	    ;; sync for filesystem local db writes
	    ;;
	    (mutex-lock! *db-multi-sync-mutex*)
	    (let* ((need-sync        (>= *db-last-access* *db-last-sync*)) ;; no sync since last write
		   (sync-in-progress *db-sync-in-progress*)
                   (sync-in-progress *db-sync-in-progress*)
                   
                   (min-intersync-delay (configf:lookup-number *configdat* "server" "minimum-intersync-delay" default: 5))
		   (should-sync      (and (not *time-to-exit*)
                                          (> (- (current-seconds) *db-last-sync*) min-intersync-delay))) ;; sync every five seconds minimum, deprecated logic, can probably be removed
		   (start-time       (current-seconds))
                   (cpu-load-adj     (alist-ref 'adj-proc-load (common:get-normalized-cpu-load #f)))
		   (mt-mod-time      (file-modification-time mtpath))
		   (last-sync-start  (if (common:file-exists? start-file)
					 (file-modification-time start-file)
					 0))
		   (last-sync-end    (if (common:file-exists? end-file)
					 (file-modification-time end-file)
					 10))
                   (sync-period      (+ 3 (* cpu-load-adj 30))) ;; as adjusted load increases increase the sync period
		   (recently-synced  (and (< (- start-time mt-mod-time) sync-period) ;; not useful if sync didn't modify megatest.db!
					  (< mt-mod-time last-sync-start)))
		   (sync-done        (<= last-sync-start last-sync-end))
                   (sync-stale       (> start-time (+ last-sync-start sync-stale-seconds)))
		   (will-sync        (and (not *time-to-exit*)       ;; do not start a sync if we are in the process of exiting
		   (will-sync-pre        (and (not *time-to-exit*)       ;; do not start a sync if we are in the process of exiting
                                          have-lock?
                                          (or need-sync should-sync)
					  (or sync-done sync-stale)
					  (not sync-in-progress)
					  (not recently-synced))))
					  (not recently-synced)))
                   (will-sync        (if will-sync-pre
                                         ;; delay get lock until we decide to sync
                                         (server:have-sync-lock?) 
                                         #f)))
              ;; if another server is syncing, postpone sync
              (if (and will-sync-pre (not will-sync))
                  (set! *db-last-sync* start-time))
              (debug:print-info 13 *default-log-port* "WD writable-watchdog top of loop.  need-sync="need-sync" sync-in-progress=" sync-in-progress
				" should-sync="should-sync" start-time="start-time" mt-mod-time="mt-mod-time" recently-synced="recently-synced" will-sync="will-sync
				" sync-done=" sync-done " sync-period=" sync-period)
              (if (and (> sync-period 5)
                       (common:low-noise-print 30 "sync-period"))
                  (debug:print-info 0 *default-log-port* "Increased sync period due to long sync times, sync took: " sync-period " seconds."))
	      ;; (if recently-synced (debug:print-info 0 *default-log-port* "Skipping sync due to recently-synced flag=" recently-synced))
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603
614
615
616
617
618
619
620

621
622
623
624
625
626
627
628







-
+







		  (begin
		    (mutex-lock! *db-multi-sync-mutex*)
		    (set! *db-sync-in-progress* #f)
		    (set! *db-last-sync* start-time)
		    (with-output-to-file end-file (lambda ()(print (current-process-id))))

		    ;; release lock here

                    (server:release-sync-lock)
		    (mutex-unlock! *db-multi-sync-mutex*)))
	      (if (and debug-mode
		       (> (- start-time last-time) 60))
		  (begin
		    (set! last-time start-time)
		    (debug:print-info 4 *default-log-port* "timestamp -> " (seconds->time-string (current-seconds)) ", time since start -> " (seconds->hr-min-sec (- (current-seconds) *time-zero*))))))