This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-1.2-lts by this push:
     new f20664f709 [improvement](jdbc-catalog) Add Connection Keepalive and 
Detailed Error Messaging for Druid Pool in FE (#22502)
f20664f709 is described below

commit f20664f709152f09c79919379292465d527b0650
Author: zy-kkk <zhongy...@gmail.com>
AuthorDate: Fri Aug 4 14:06:30 2023 +0800

    [improvement](jdbc-catalog) Add Connection Keepalive and Detailed Error 
Messaging for Druid Pool in FE (#22502)
---
 .../java/org/apache/doris/external/jdbc/JdbcClient.java  | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java 
b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
index 51a18c67d6..c8f9346155 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
@@ -45,6 +45,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 @Getter
 public class JdbcClient {
@@ -109,6 +110,9 @@ public class JdbcClient {
             // to FE to get schema info, and may create connection here, if we 
set it too long and the url is invalid,
             // it may cause the thrift rpc timeout.
             dataSource.setMaxWait(5000);
+            dataSource.setTestWhileIdle(true);
+            dataSource.setTestOnBorrow(false);
+            setValidationQuery(dataSource, dbType);
         } catch (MalformedURLException e) {
             throw new JdbcClientException("MalformedURLException to load class 
about " + driverUrl, e);
         } finally {
@@ -116,6 +120,16 @@ public class JdbcClient {
         }
     }
 
+    private void setValidationQuery(DruidDataSource ds, String tableType) {
+        if (Objects.equals(tableType, JdbcResource.ORACLE)) {
+            ds.setValidationQuery("SELECT 1 FROM dual");
+        } else if (Objects.equals(tableType, JdbcResource.SAP_HANA)) {
+            ds.setValidationQuery("SELECT 1 FROM DUMMY");
+        } else {
+            ds.setValidationQuery("SELECT 1");
+        }
+    }
+
     public void closeClient() {
         dataSource.close();
     }
@@ -125,7 +139,7 @@ public class JdbcClient {
         try {
             conn = dataSource.getConnection();
         } catch (Exception e) {
-            throw new JdbcClientException("Can not connect to jdbc", e);
+            throw new JdbcClientException("Can not connect to jdbc due to 
error: %s", e, e.getMessage());
         }
         return conn;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to