52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
-
+
-
-
+
+
-
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
+
|
;;======================================================================
;; S U P P O R T F U N C T I O N S
;;======================================================================
(define *send-receive-mutex* (make-mutex)) ;; should have separate mutex per run-id
(define *runremote* (make-remote))
;; (define *runremote* (make-remote))
;; this entry point can decide based on cmd whether to dispatch to old api calls via remote or via ulex
;;
(define (rmt:send-receive cmd rid params #!key (attemptnum 1)(area-dat #f))
(let* ((areapath *toppath*);; TODO - resolve from dbstruct to be compatible with multiple areas
(runremote (or area-dat
*runremote*)))
(alldat (or area-dat
*alldat*)))
;; ensure we have a record for our connection for given area
(if (not (remote-hh-dat runremote))
(if (not (alldat-hh-dat alldat))
(begin
(remote-server-timeout-set! runremote (server:expiration-timeout))
(remote-hh-dat-set! runremote (common:get-homehost))
)) ;; new runremote will come from this on next iteration
(alldat-server-timeout-set! alldat (server:expiration-timeout))
(alldat-hh-dat-set! alldat (common:get-homehost))
)) ;; new alldat will come from this on next iteration
;; ensure we have a homehost record, do this here instead of in -orig
(if (or (not (remote-hh-dat runremote))
(not (pair? (remote-hh-dat runremote)))) ;; not on homehost
(remote-hh-dat-set! runremote (common:get-homehost)))
;; ensure we have a homehost record and mtconfig, do this here instead of in -orig
(if (or (not (alldat-mtconfig *alldat*))
(not (alldat-hh-dat alldat))
(not (pair? (alldat-hh-dat alldat)))) ;; not on homehost
(begin
(alldat-hh-dat-set! alldat (common:get-homehost))
(alldat-mtconfig-set! *alldat* *configdat*)
(alldat-areapath-set! *alldat* *toppath*)
(alldat-areadat-set! *alldat* alldat) ;; TODO: converge usage of alldat and area-dat
))
(if (member cmd '(blah))
(begin
(mutex-lock! *send-receive-mutex*)
(let ((ulex:conn (remote-ulex:conn runremote)))
(if (not ulex:conn)(remote-ulex:conn-set! runremote (rmtmod:setup-ulex areapath)))
(let ((ulex:conn (alldat-ulex:conn alldat)))
(if (not ulex:conn)(alldat-ulex:conn-set! alldat (rmtmod:setup-ulex areapath)))
(rmtmod:send-receive-ulex ulex:conn cmd rid params attemptnum area-dat)))
(rmt:send-receive-orig *default-log-port* alldat *rmt-mutex* areapath *db-multi-sync-mutex*
(rmt:send-receive-orig *default-log-port* runremote *rmt-mutex* areapath *db-multi-sync-mutex* cmd rid params *alldata* attemptnum: attemptnum area-dat: area-dat))))
cmd rid params *alldat* attemptnum: attemptnum area-dat: area-dat))))
;; bunch of small functions factored out of send-receive to make debug easier
;;
;; (define (rmt:update-db-stats run-id rawcmd params duration)
;; (mutex-lock! *db-stats-mutex*)
;; (handle-exceptions
|