Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Stop ClickHouse connection retries when the server is down (#85512)

Riley Thompson119a46ad7c1d
diff --git a/modules/drivers/clickhouse/src/metabase/driver/clickhouse.clj b/modules/drivers/clickhouse/src/metabase/driver/clickhouse.clj
index 5df7c48fd54..b38ead37423 100644
--- a/modules/drivers/clickhouse/src/metabase/driver/clickhouse.clj
+++ b/modules/drivers/clickhouse/src/metabase/driver/clickhouse.clj
@@ -191,6 +191,18 @@
:jdbc_metadata_use_show_statements false}
(sql-jdbc.common/handle-additional-options details :separator-style :url))))
+(defmethod sql-jdbc.conn/data-warehouse-connection-pool-properties :clickhouse
+ [driver database]
+ ;; A ClickHouse connection is an HTTP client that does not contact the server when c3p0 acquires
+ ;; it, so it will succeed even if the server is down, whereas other drivers would fail here.
+ ;; However the `testConnectionOnCheckout` test does contact the server, so it will fail if the
+ ;; server is down. Then c3p0 will continue to acquire and test new connections, flooding the logs
+ ;; and causing a stack overflow. Since the connection is an HTTP client, there's no server state
+ ;; that can go stale on the connection so the test can be disabled (#85512).
+ (merge
+ ((get-method sql-jdbc.conn/data-warehouse-connection-pool-properties :sql-jdbc) driver database)
+ {"testConnectionOnCheckout" false}))
+
(defmethod driver/database-supports? [:clickhouse :uploads] [_driver _feature db]
(let [{:keys [cloud single-node]} (clickhouse-version/dbms-version db)]
(boolean (or cloud single-node))))
diff --git a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_test.clj b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_test.clj
index 13444edb601..ef5acb863b8 100644
--- a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_test.clj
+++ b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_test.clj
@@ -6,6 +6,7 @@
[clojure.string :as str]
[clojure.test :refer :all]
[metabase.driver :as driver]
+ [metabase.driver-api.core :as driver-api]
[metabase.driver.clickhouse :as clickhouse]
[metabase.driver.clickhouse-qp :as clickhouse-qp]
[metabase.driver.sql :as driver.sql]
@@ -494,6 +495,10 @@
(testing "pretty"
(is (= "SELECT\n `test_data`.`venues`.`id` AS `id`\nFROM\n `test_data`.`venues`\nORDER BY\n `test_data`.`venues`.`id` ASC\nLIMIT\n 5" pretty))))))
+(deftest pool-does-not-test-connections-on-checkout-test
+ (with-redefs [driver-api/is-test? false]
+ (is (false? (get (sql-jdbc.conn/data-warehouse-connection-pool-properties :clickhouse (mt/db)) "testConnectionOnCheckout")))))
+
(deftest ^:parallel clickhouse-can-connect
(mt/test-driver :clickhouse
(doall