Megatest

Check-in [74cbbcdf44]
Login
Overview
Comment:Fixed dying thread. Servers exit cleanly now
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.60
Files: files | file ages | folders
SHA1: 74cbbcdf440a313acc690f34d0c64d38f09ac630
User & Date: matt on 2014-08-27 23:47:08
Other Links: branch diff | manifest | tags
Context
2014-08-28
00:04
Reuse ports when possible check-in: 4382ee655e user: matt tags: v1.60
2014-08-27
23:47
Fixed dying thread. Servers exit cleanly now check-in: 74cbbcdf44 user: matt tags: v1.60
21:53
Marking ports as taken/released/failed now working. One race condtion taken care of but one remains. check-in: 5051742e65 user: matt tags: v1.60
Changes

Modified http-transport.scm from [92e5cfe525] to [be1bf45760].

405
406
407
408
409
410
411

412
413
414
415
416
417
418
419
      ;; no_traffic, no running tests, if server 0, no running servers
      ;;
      (if (and *server-run*
	       (or (> (+ last-access server-timeout)
		      (current-seconds))
		   (and (eq? run-id 0)
			(> (tasks:num-servers-non-zero-running tdb) 0))

		   (> (db:get-count-tests-running *inmemdb* run-id) 0)
		   ))
	  (begin
	    (debug:print-info 0 "Server continuing, seconds since last db access: " (- (current-seconds) last-access))
	    ;;
	    ;; Consider implementing some smarts here to re-insert the record or kill self is
	    ;; the db indicates so
	    ;;







>
|







405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
      ;; no_traffic, no running tests, if server 0, no running servers
      ;;
      (if (and *server-run*
	       (or (> (+ last-access server-timeout)
		      (current-seconds))
		   (and (eq? run-id 0)
			(> (tasks:num-servers-non-zero-running tdb) 0))
		   (and (not (eq? run-id 0)) ;; only makes sense in non-zero run-id servers
			(> (db:get-count-tests-running *inmemdb* run-id) 0))
		   ))
	  (begin
	    (debug:print-info 0 "Server continuing, seconds since last db access: " (- (current-seconds) last-access))
	    ;;
	    ;; Consider implementing some smarts here to re-insert the record or kill self is
	    ;; the db indicates so
	    ;;

Modified portlogger.scm from [456633ae98] to [1cb5fd6090].

27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    (sqlite3:execute db "PRAGMA synchronous = 0;")
    (if (not exists)
	(sqlite3:execute 
	 db
	 "CREATE TABLE ports (
            port INTEGER PRIMARY KEY,
            state TEXT DEFAULT 'not-used',
            fail_count INTEGER DEFAULT 0);"))

    db))

(define (portlogger:open-run-close proc . params)
  (handle-exceptions
   exn
   (print "ERROR: portlogger:open-run-close failed. " proc " " params)
   (let* ((db  (portlogger:open-db (conc "/tmp/." (current-user-name) "-portlogger.db")))
	  (res (apply proc db params)))
     (sqlite3:finalize! db)
     res)))

;; (fold-row PROC INIT DATABASE SQL . PARAMETERS) 
(define (portlogger:take-port db portnum)
  (let* ((qry1 (sqlite3:prepare db "INSERT INTO ports (port,state) VALUES (?,?);"))
	 (qry2 (sqlite3:prepare db "UPDATE ports SET state=? WHERE port=?;"))
	 (qry3 (sqlite3:prepare db "SELECT state FROM ports WHERE port=?;"))
	 (res  (sqlite3:with-transaction
		db
		(lambda ()
		  ;; (fold-row (lambda (var curr) (or var curr)) #f db "SELECT var FROM foo WHERE id=100;")
		  (let* ((curr #f)
			 (res  #f))







|
>














|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    (sqlite3:execute db "PRAGMA synchronous = 0;")
    (if (not exists)
	(sqlite3:execute 
	 db
	 "CREATE TABLE ports (
            port INTEGER PRIMARY KEY,
            state TEXT DEFAULT 'not-used',
            fail_count INTEGER DEFAULT 0,
            update_time TIMESTAMP DEFAULT (strftime('%s','now')) );"))
    db))

(define (portlogger:open-run-close proc . params)
  (handle-exceptions
   exn
   (print "ERROR: portlogger:open-run-close failed. " proc " " params)
   (let* ((db  (portlogger:open-db (conc "/tmp/." (current-user-name) "-portlogger.db")))
	  (res (apply proc db params)))
     (sqlite3:finalize! db)
     res)))

;; (fold-row PROC INIT DATABASE SQL . PARAMETERS) 
(define (portlogger:take-port db portnum)
  (let* ((qry1 (sqlite3:prepare db "INSERT INTO ports (port,state) VALUES (?,?);"))
	 (qry2 (sqlite3:prepare db "UPDATE ports SET state=?,update_time=strftime('%s','now') WHERE port=?;"))
	 (qry3 (sqlite3:prepare db "SELECT state FROM ports WHERE port=?;"))
	 (res  (sqlite3:with-transaction
		db
		(lambda ()
		  ;; (fold-row (lambda (var curr) (or var curr)) #f db "SELECT var FROM foo WHERE id=100;")
		  (let* ((curr #f)
			 (res  #f))
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    (sqlite3:finalize! qry2)
    (sqlite3:finalize! qry3)
    res))

;; set port to "released", "failed" etc.
;; 
(define (portlogger:set-port db portnum value)
  (sqlite3:execute db "UPDATE ports SET state=? WHERE port=?;" value portnum))

;; set port to failed (attempted to take but got error)
;;
(define (portlogger:set-failed db portnum)
  (sqlite3:execute db "UPDATE ports SET state='failed',fail_count=fail_count+1 WHERE port=?;" portnum))

;;======================================================================
;; MAIN
;;======================================================================










|




|







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    (sqlite3:finalize! qry2)
    (sqlite3:finalize! qry3)
    res))

;; set port to "released", "failed" etc.
;; 
(define (portlogger:set-port db portnum value)
  (sqlite3:execute db "UPDATE ports SET state=?,update_time=strftime('%s','now') WHERE port=?;" value portnum))

;; set port to failed (attempted to take but got error)
;;
(define (portlogger:set-failed db portnum)
  (sqlite3:execute db "UPDATE ports SET state='failed',fail_count=fail_count+1,update_time=strftime('%s','now') WHERE port=?;" portnum))

;;======================================================================
;; MAIN
;;======================================================================



Modified tasks.scm from [5715ae88f8] to [d75535da29].

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

(define (tasks:num-servers-non-zero-running mdb)
  (let ((res 0))
    (sqlite3:for-each-row
     (lambda (num-running)
       (set! res num-running))
     mdb
     "SELECT count(id) FROM servers WHERE run_id != 0 AND state = 'running';"
     run-id)
    res))

(define (tasks:server-clean-out-old-records-for-run-id mdb run-id tag)
  (sqlite3:execute mdb "UPDATE servers SET state=?,heartbeat=strftime('%s','now') WHERE state in ('available','shutting-down') AND (strftime('%s','now') - start_time) > 50 AND run_id=?;"
		   (conc "defunct" tag) run-id))

(define (tasks:server-force-clean-running-records-for-run-id mdb run-id tag)







|
<







146
147
148
149
150
151
152
153

154
155
156
157
158
159
160

(define (tasks:num-servers-non-zero-running mdb)
  (let ((res 0))
    (sqlite3:for-each-row
     (lambda (num-running)
       (set! res num-running))
     mdb
     "SELECT count(id) FROM servers WHERE run_id != 0 AND state = 'running';")

    res))

(define (tasks:server-clean-out-old-records-for-run-id mdb run-id tag)
  (sqlite3:execute mdb "UPDATE servers SET state=?,heartbeat=strftime('%s','now') WHERE state in ('available','shutting-down') AND (strftime('%s','now') - start_time) > 50 AND run_id=?;"
		   (conc "defunct" tag) run-id))

(define (tasks:server-force-clean-running-records-for-run-id mdb run-id tag)