mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-08 15:27:00 +02:00
Fix a race condition in the monitor thread.
Startup log messages could be lost because the monitor would be started but not ready to process messages. Fix that by “warming up” the monitoring thread, having it execute a small computation and more importantly wait for the result to be received back, blocking. See #599 where parsing errors from a wrong URL were missed in the command line output, quite disturbingly.
This commit is contained in:
parent
370038a74e
commit
773dcaeca3
@ -31,7 +31,6 @@
|
||||
(defstruct start start-logger)
|
||||
(defstruct stop stop-logger)
|
||||
(defstruct report-summary reset)
|
||||
(defstruct noop)
|
||||
(defstruct log-message category description arguments)
|
||||
(defstruct new-label section label dbname)
|
||||
(defstruct update-stats section label read rows errs secs rs ws start stop)
|
||||
@ -140,9 +139,16 @@
|
||||
(setf *monitoring-kernel* kernel
|
||||
*monitoring-channel* (lp:make-channel))
|
||||
|
||||
;; warm up the channel to ensure we don't loose any event
|
||||
(lp:submit-task *monitoring-channel* '+ 1 2 3)
|
||||
(lp:receive-result *monitoring-channel*)
|
||||
|
||||
;; now that we know the channel is ready, start our long-running monitor
|
||||
(lp:submit-task *monitoring-channel* #'monitor *monitoring-queue*)
|
||||
(send-event (make-start :start-logger start-logger))
|
||||
|
||||
(sleep 0.2)
|
||||
|
||||
*monitoring-channel*))
|
||||
|
||||
(defun stop-monitor (&key
|
||||
@ -175,9 +181,7 @@
|
||||
;; process messages from the queue
|
||||
(loop :with start-time := (get-internal-real-time)
|
||||
|
||||
:for event := (multiple-value-bind (event available)
|
||||
(lq:try-pop-queue queue)
|
||||
(if available event (make-noop)))
|
||||
:for event := (lq:pop-queue queue)
|
||||
:do (typecase event
|
||||
(start
|
||||
(when (start-start-logger event)
|
||||
@ -201,9 +205,6 @@
|
||||
:data (make-pgstate)
|
||||
:post (make-pgstate)))))
|
||||
|
||||
(noop
|
||||
(sleep 0.2)) ; avoid buzy looping
|
||||
|
||||
(log-message
|
||||
;; cl-log:log-message is a macro, we can't use apply
|
||||
;; here, so we need to break a level of abstraction
|
||||
|
Loading…
Reference in New Issue
Block a user