Skip to content
Snippets Groups Projects
Commit 40528602 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

add a new optional driver method for `notify-database-updated` which allows...

add a new optional driver method for `notify-database-updated` which allows drivers to be informed when their databases are updated. then implement this method on the generic-sql driver and use it to actively shutdown any open connection pool on the updated database so that we can recreate it as needed.
parent 0959d2af
No related branches found
No related tags found
No related merge requests found
......@@ -166,6 +166,10 @@
"*OPTIONAL*. Return a humanized (user-facing) version of an connection error message string.
Generic error messages are provided in the constant `connection-error-messages`; return one of these whenever possible.")
(notify-database-updated [this, ^DatabaseInstance database]
"*OPTIONAL*. Notify the driver that the attributes of the DATABASE have changed. This is specifically relevant in
the event that the driver was doing some caching or connection pooling.")
(process-native [this, {^Integer database-id :database, {^String native-query :query} :native, :as ^Map query}]
"Process a native QUERY. This function is called by `metabase.driver/process-query`.
......@@ -253,6 +257,7 @@
:describe-table-fks (constantly nil)
:features (constantly nil)
:humanize-connection-error-message (u/drop-first-arg identity)
:notify-database-updated (constantly nil)
:process-query-in-context (u/drop-first-arg identity)
:sync-in-context (fn [_ _ f] (f))
:table-rows-seq (constantly nil)})
......
......@@ -104,6 +104,17 @@
;; prevent overly large pools by condensing them when connections are idle for 15m+
:excess-timeout (* 15 60)))))
(defn- notify-database-updated
"We are being informed that a DATABASE has been updated, so lets shut down the connection pool (if it exists) under
the assumption that the connection details have changed."
[_ {:keys [id]}]
(log/debug (u/format-color 'red "Closing connection pool for database %d ..." id))
(when-let [pool (get @connection-pools id)]
;; remove the cached reference to the pool so we don't try to use it anymore
(reset! connection-pools (dissoc @connection-pools id))
;; now actively shut down the pool so that any open connections are closed
(.close (:datasource pool))))
(defn db->pooled-connection-spec
"Return a JDBC connection spec that includes a cp30 `ComboPooledDataSource`.
Theses connection pools are cached so we don't create multiple ones to the same DB."
......@@ -328,16 +339,17 @@
(require 'metabase.driver.generic-sql.native
'metabase.driver.generic-sql.query-processor)
(merge driver/IDriverDefaultsMixin
{:analyze-table analyze-table
:can-connect? can-connect?
:describe-database describe-database
:describe-table describe-table
:describe-table-fks describe-table-fks
:features features
:field-values-lazy-seq field-values-lazy-seq
:process-native (resolve 'metabase.driver.generic-sql.native/process-and-run)
:process-structured (resolve 'metabase.driver.generic-sql.query-processor/process-structured)
:table-rows-seq table-rows-seq}))
{:analyze-table analyze-table
:can-connect? can-connect?
:describe-database describe-database
:describe-table describe-table
:describe-table-fks describe-table-fks
:features features
:field-values-lazy-seq field-values-lazy-seq
:notify-database-updated notify-database-updated
:process-native (resolve 'metabase.driver.generic-sql.native/process-and-run)
:process-structured (resolve 'metabase.driver.generic-sql.query-processor/process-structured)
:table-rows-seq table-rows-seq}))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment