Fix on-error-stop signaling.

To properly handle on-error-stop condition, make it a specific pgloader
condition with a specific handling behavior. In passing add some more log
messages for surprising conditions.

Fix #546.
This commit is contained in:
Dimitri Fontaine 2017-06-17 18:38:06 +02:00
parent 5faf8605ce
commit e11ccf7bb7
4 changed files with 28 additions and 19 deletions

View File

@ -299,6 +299,7 @@
(handler-bind
((condition
#'(lambda (condition)
(log-message :fatal "KABOOM!")
(log-message :fatal "~a"
(print-backtrace condition debug)))))
@ -349,6 +350,7 @@
(condition (c)
(declare (ignore c)) ; handler-bind printed it out
(log-message :log "What I am doing here?")
(sleep 0.3) ; wait until monitor stops...
(uiop:quit +os-code-error+)))))

View File

@ -8,6 +8,7 @@
(:export #:*version-string*
#:*dry-run*
#:*on-error-stop*
#:on-error-stop
#:*self-upgrade-immutable-systems*
#:*fd-path-root*
#:*root-dir*
@ -78,6 +79,14 @@
(defparameter *on-error-stop* nil
"Set to non-nil to for pgloader to refrain from handling errors, quitting instead.")
(define-condition on-error-stop ()
((on-condition :initarg :on-condition :reader on-error-condition
:documentation "Condition that triggered on-error-stop"))
(:report (lambda (condition stream)
(format stream
"On Error Stop: ~a"
(on-error-condition condition)))))
(defparameter *fd-path-root* nil
"Where to load files from, when loading from an archive or expanding regexps.")

View File

@ -78,9 +78,8 @@
(if on-error-stop
;; re-signal the condition to upper level
(progn
(log-message :fatal "~a" condition)
(error "Stop loading data for table ~s on first error."
(format-table-name table)))
(log-message :error "~a" condition)
(signal 'on-error-stop :on-condition condition))
;; normal behavior, on-error-stop being nil
;; clean the current transaction before retrying new ones

View File

@ -154,22 +154,21 @@
(lq:make-queue :fixed-capacity *concurrent-batches*))))
(lp:task-handler-bind
((error #'(lambda (condition)
(log-message :error "A thread failed with error: ~a"
condition)
#-pgloader-image
(if (member *client-min-messages* (list :debug :data))
(lp::invoke-debugger condition)
(lp::invoke-transfer-error condition))
#+pgloader-image
(if (member *client-min-messages* (list :debug :data))
(log-message :fatal "Backtrace: ~a"
(trivial-backtrace:print-backtrace
condition
:output nil
:verbose t))
(lp::invoke-transfer-error condition)))))
(log-message :notice "COPY ~s" table-name)
((on-error-stop
#'(lambda (condition)
;; everything has been handled already
(lp:invoke-transfer-error condition)))
(error
#'(lambda (condition)
(log-message :error "A thread failed with error: ~a" condition)
(if (member *client-min-messages* (list :debug :data))
#-pgloader-image
(log-message :error "~a"
(trivial-backtrace:print-backtrace condition
:output nil))
#+pgloader-image
(lp::invoke-debugger condition))
(lp::invoke-transfer-error condition))))
(log-message :notice "COPY ~a" table-name)
;; start a task to read data from the source into the queue