mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-08 07:16:58 +02:00
Handle empty tables in concurrency support for MySQL.
When the table is empty we get nil for min and max values of the id column. In that case we don't compute a set of ranges and “cancel” concurrency support for the empty table. Fixes #596.
This commit is contained in:
parent
b1fa3aec3c
commit
d37ad27754
@ -58,25 +58,31 @@
|
|||||||
(sql (format nil "select min(`~a`), max(`~a`) from `~a`"
|
(sql (format nil "select min(`~a`), max(`~a`) from `~a`"
|
||||||
col col (table-source-name (source mysql)))))
|
col col (table-source-name (source mysql)))))
|
||||||
(destructuring-bind (min max)
|
(destructuring-bind (min max)
|
||||||
(mapcar #'parse-integer (first (mysql-query sql)))
|
(let ((result (first (mysql-query sql))))
|
||||||
|
;; result is (min max), or (nil nil) if table is empty
|
||||||
|
(if (or (null (first result))
|
||||||
|
(null (second result)))
|
||||||
|
result
|
||||||
|
(mapcar #'parse-integer result)))
|
||||||
;; generate a list of ranges from min to max
|
;; generate a list of ranges from min to max
|
||||||
(let ((range-list (split-range min max *rows-per-range*)))
|
(when (and min max)
|
||||||
(unless (< (length range-list) concurrency)
|
(let ((range-list (split-range min max *rows-per-range*)))
|
||||||
;; affect those ranges to each reader, we have CONCURRENCY
|
(unless (< (length range-list) concurrency)
|
||||||
;; of them
|
;; affect those ranges to each reader, we have CONCURRENCY
|
||||||
(let ((partitions (distribute range-list concurrency)))
|
;; of them
|
||||||
(loop :for part :in partitions :collect
|
(let ((partitions (distribute range-list concurrency)))
|
||||||
(make-instance 'copy-mysql
|
(loop :for part :in partitions :collect
|
||||||
:source-db (clone-connection
|
(make-instance 'copy-mysql
|
||||||
(source-db mysql))
|
:source-db (clone-connection
|
||||||
:target-db (target-db mysql)
|
(source-db mysql))
|
||||||
:source (source mysql)
|
:target-db (target-db mysql)
|
||||||
:target (target mysql)
|
:source (source mysql)
|
||||||
:fields (fields mysql)
|
:target (target mysql)
|
||||||
:columns (columns mysql)
|
:fields (fields mysql)
|
||||||
:transforms (transforms mysql)
|
:columns (columns mysql)
|
||||||
:encoding (encoding mysql)
|
:transforms (transforms mysql)
|
||||||
:range-list (cons col part)))))))))))))
|
:encoding (encoding mysql)
|
||||||
|
:range-list (cons col part))))))))))))))
|
||||||
|
|
||||||
(defmacro with-encoding-handler (&body forms)
|
(defmacro with-encoding-handler (&body forms)
|
||||||
`(handler-bind
|
`(handler-bind
|
||||||
|
Loading…
Reference in New Issue
Block a user