Clojure JDBC Different DB Connections in One Transaction

I use Clojure with JDBC to select and insert records from two different databases (notably MySQL and Vertica) in response to the event. I would like all this to happen as part of a single transaction that could be discarded if something went wrong with any team.

(defn handle-request
  [request]
  (jdbc/with-db-transaction [mysql-conn config/mysql-db-spec]
    (jdbc/with-db-transaction [vertica-conn config/vertica-db-spec]
      (let [record (query-some-data mysql-conn request)]
        (update-some-data! mysql-conn record)
        (insert-some-vertica-data! vertica-conn record)))))

I am worried that this could lead to a successful Vertica transaction, but not MySQL. What would be the most idiomatic Clojure way to handle this operation?

+4
source share
1 answer

- , , , / . , , "" , .

  • , - mysql tx, , , . , , vertica, ( ) . ():
(perform mysql tx) 
if (successful) then 
  (do vertica tx)
  1. / , :
(do tx in DB 1)
(try
  (do tx is DB 2)
  (catch Exception ex
    (rollback tx in DB 1)))

, DB-, ( , , ?).

  1. PostgreSQL, , Data Wrapper (FDW), №2 . , postgres Oracle DB "" DB-guarentees. , .
+4

All Articles