From d92a2d391f3545b966c9d510a6002b6950f62894 Mon Sep 17 00:00:00 2001 From: aiceflower Date: Fri, 16 Jun 2023 20:36:48 +0800 Subject: [PATCH 1/3] fix jdbc connection cache --- .../jdbc/executor/JDBCEngineConnExecutor.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala b/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala index 511a626c88..a71c05e94a 100644 --- a/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala +++ b/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala @@ -115,7 +115,13 @@ class JDBCEngineConnExecutor(override val outputPrintLimit: Int, val id: Int) var resultSet: ResultSet = null logger.info(s"The data source properties is $properties") Utils.tryCatch({ - val dataSourceIdentifier = s"$dataSourceName-$dataSourceMaxVersionId" + val jdbcUrl: String = properties.get(JDBCEngineConnConstant.JDBC_URL) + val execUser: String = properties.get(JDBCEngineConnConstant.JDBC_SCRIPTS_EXEC_USER) + val proxyUser: String = properties.get(JDBCEngineConnConstant.JDBC_PROXY_USER_PROPERTY) + var dataSourceIdentifier = s"$jdbcUrl-$execUser-$proxyUser" + if (dataSourceName != null) { + dataSourceIdentifier = s"$dataSourceName-$dataSourceMaxVersionId" + } connection = connectionManager.getConnection(dataSourceIdentifier, properties) logger.info("The jdbc connection has created successfully!") }) { e: Throwable => From ee1c960be5fa41f274e623bccae2183387ac5547 Mon Sep 17 00:00:00 2001 From: aiceflower Date: Fri, 16 Jun 2023 20:43:31 +0800 Subject: [PATCH 2/3] Modify the nonnull judgment --- .../engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala b/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala index a71c05e94a..b57f486475 100644 --- a/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala +++ b/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala @@ -119,7 +119,7 @@ class JDBCEngineConnExecutor(override val outputPrintLimit: Int, val id: Int) val execUser: String = properties.get(JDBCEngineConnConstant.JDBC_SCRIPTS_EXEC_USER) val proxyUser: String = properties.get(JDBCEngineConnConstant.JDBC_PROXY_USER_PROPERTY) var dataSourceIdentifier = s"$jdbcUrl-$execUser-$proxyUser" - if (dataSourceName != null) { + if (StringUtils.isNotBlank(dataSourceName)) { dataSourceIdentifier = s"$dataSourceName-$dataSourceMaxVersionId" } connection = connectionManager.getConnection(dataSourceIdentifier, properties) From 46c2a2b54218d9283c4009d0806d11de8fee6435 Mon Sep 17 00:00:00 2001 From: aiceflower Date: Mon, 19 Jun 2023 01:28:11 +0800 Subject: [PATCH 3/3] Update JDBCEngineConnExecutor.scala add annotation --- .../engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala b/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala index b57f486475..336d1197f7 100644 --- a/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala +++ b/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala @@ -115,10 +115,12 @@ class JDBCEngineConnExecutor(override val outputPrintLimit: Int, val id: Int) var resultSet: ResultSet = null logger.info(s"The data source properties is $properties") Utils.tryCatch({ + /* url + user as the cache key */ val jdbcUrl: String = properties.get(JDBCEngineConnConstant.JDBC_URL) val execUser: String = properties.get(JDBCEngineConnConstant.JDBC_SCRIPTS_EXEC_USER) val proxyUser: String = properties.get(JDBCEngineConnConstant.JDBC_PROXY_USER_PROPERTY) var dataSourceIdentifier = s"$jdbcUrl-$execUser-$proxyUser" + /* If datasource is used, use datasource name as the cache key */ if (StringUtils.isNotBlank(dataSourceName)) { dataSourceIdentifier = s"$dataSourceName-$dataSourceMaxVersionId" }