Refactor PostgreSQL conditions.

Use a single deftype postgresql-unavailable rather than copy/pasting the
same list of conditions in several places.
This commit is contained in:
Dimitri Fontaine 2017-06-29 14:08:52 +02:00
parent 60c1146e18
commit 1e436555a8
4 changed files with 21 additions and 39 deletions

View File

@ -362,6 +362,7 @@
#:pgsql-execute #:pgsql-execute
#:pgsql-execute-with-timing #:pgsql-execute-with-timing
#:pgsql-connect-and-execute-with-timing #:pgsql-connect-and-execute-with-timing
#:postgresql-unavailable
;; postgresql schema facilities ;; postgresql schema facilities
#:truncate-tables #:truncate-tables

View File

@ -48,6 +48,22 @@
(defvar *pgsql-client-key* "~/.postgresql/postgresql.key" (defvar *pgsql-client-key* "~/.postgresql/postgresql.key"
"File where to read the PostgreSQL Client Side SSL Private Key.") "File where to read the PostgreSQL Client Side SSL Private Key.")
;;;
;;;
;;;
(deftype postgresql-unavailable ()
"It might happen that PostgreSQL becomes unavailable in the middle of
our processing: it being restarted is an example."
`(or
cl-postgres-error::server-shutdown
cl-postgres-error::admin-shutdown
cl-postgres-error::crash-shutdown
cl-postgres-error::operator-intervention
cl-postgres-error::cannot-connect-now
cl-postgres-error::database-connection-error
cl-postgres-error::database-connection-lost
cl-postgres-error::database-socket-error))
;;; ;;;
;;; We need to distinguish some special cases of PostgreSQL errors within ;;; We need to distinguish some special cases of PostgreSQL errors within
;;; Class 53 — Insufficient Resources: in case of "too many connections" we ;;; Class 53 — Insufficient Resources: in case of "too many connections" we
@ -141,15 +157,7 @@
appropriate log level." appropriate log level."
`(handler-bind `(handler-bind
(((and cl-postgres:database-error (((and cl-postgres:database-error
(not (or (not postgresql-unavailable))
cl-postgres-error::server-shutdown
cl-postgres-error::admin-shutdown
cl-postgres-error::crash-shutdown
cl-postgres-error::operator-intervention
cl-postgres-error::cannot-connect-now
cl-postgres-error::database-connection-error
cl-postgres-error::database-connection-lost
cl-postgres-error::database-socket-error)))
#'(lambda (e) #'(lambda (e)
(log-message :error "~a" e))) (log-message :error "~a" e)))
(cl-postgres:postgresql-warning (cl-postgres:postgresql-warning
@ -249,16 +257,7 @@
(pomo:with-transaction () (pomo:with-transaction ()
(pgsql-execute-with-timing section label sql :count count))) (pgsql-execute-with-timing section label sql :count count)))
((or (postgresql-unavailable (condition)
cl-postgres-error::server-shutdown
cl-postgres-error::admin-shutdown
cl-postgres-error::crash-shutdown
cl-postgres-error::operator-intervention
cl-postgres-error::cannot-connect-now
cl-postgres-error::database-connection-error
cl-postgres-error::database-connection-lost
cl-postgres-error::database-socket-error)
(condition)
(log-message :error "~a" condition) (log-message :error "~a" condition)
(log-message :error "Reconnecting to PostgreSQL") (log-message :error "Reconnecting to PostgreSQL")

View File

@ -87,16 +87,7 @@
(log-message :error "~a" condition) (log-message :error "~a" condition)
(retry-batch table columns batch batch-rows condition)))) (retry-batch table columns batch batch-rows condition))))
((or (postgresql-unavailable (condition)
cl-postgres-error::server-shutdown
cl-postgres-error::admin-shutdown
cl-postgres-error::crash-shutdown
cl-postgres-error::operator-intervention
cl-postgres-error::cannot-connect-now
cl-postgres-error::database-connection-error
cl-postgres-error::database-connection-lost
cl-postgres-error::database-socket-error)
(condition)
(log-message :error "~a" condition) (log-message :error "~a" condition)
(log-message :error "Copy Batch reconnecting to PostgreSQL") (log-message :error "Copy Batch reconnecting to PostgreSQL")

View File

@ -173,16 +173,7 @@
:section :post :section :post
:label "Install Comments")) :label "Install Comments"))
((or (postgresql-unavailable (condition)
cl-postgres-error::server-shutdown
cl-postgres-error::admin-shutdown
cl-postgres-error::crash-shutdown
cl-postgres-error::operator-intervention
cl-postgres-error::cannot-connect-now
cl-postgres-error::database-connection-error
cl-postgres-error::database-connection-lost
cl-postgres-error::database-socket-error)
(condition)
(log-message :error "~a" condition) (log-message :error "~a" condition)
(log-message :error (log-message :error