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

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new a61b3bb1f7 Fix table exists check in the JDBC Storage Plugin. (#11897)
a61b3bb1f7 is described below

commit a61b3bb1f760c5dc91650a1f4fb3704f527b3e16
Author: Chen Ziyan <clairelove.c...@gmail.com>
AuthorDate: Tue Feb 20 15:01:11 2024 +0800

    Fix table exists check in the JDBC Storage Plugin. (#11897)
---
 docs/en/changes/changes.md                                          | 1 +
 .../oap/server/library/client/jdbc/hikaricp/JDBCClient.java         | 6 +++---
 .../server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java | 2 +-
 .../oap/server/storage/plugin/jdbc/common/dao/JDBCSQLExecutor.java  | 2 +-
 .../storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAOIT.java      | 6 +++---
 5 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index fde1695012..f63a3cd727 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -51,6 +51,7 @@
   - ROCKETMQ -> K8S_SERVICE
   - VIRTUAL_MQ -> ROCKETMQ
 * Fix ServiceInstance `in` query.
+* Fix table exists check in the JDBC Storage Plugin.
 
 #### UI
 
diff --git 
a/oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/jdbc/hikaricp/JDBCClient.java
 
b/oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/jdbc/hikaricp/JDBCClient.java
index 65c83b9ac8..f84bbeede8 100644
--- 
a/oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/jdbc/hikaricp/JDBCClient.java
+++ 
b/oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/jdbc/hikaricp/JDBCClient.java
@@ -152,7 +152,7 @@ public class JDBCClient implements Client, HealthCheckable {
     public boolean indexExists(final String table,
                                final String index) throws SQLException {
         try (final var connection = getConnection();
-             final var resultSet = 
connection.getMetaData().getIndexInfo(connection.getCatalog(), null, table, 
false, false)) {
+             final var resultSet = 
connection.getMetaData().getIndexInfo(connection.getCatalog(), 
connection.getSchema(), table, false, false)) {
             while (resultSet.next()) {
                 if (resultSet.getString("INDEX_NAME").equalsIgnoreCase(index)) 
{
                     return true;
@@ -164,14 +164,14 @@ public class JDBCClient implements Client, 
HealthCheckable {
 
     public boolean tableExists(final String table) throws SQLException {
         try (final var conn = getConnection();
-             final var result = 
conn.getMetaData().getTables(conn.getCatalog(), null, table, null)) {
+             final var result = 
conn.getMetaData().getTables(conn.getCatalog(), conn.getSchema(), table, null)) 
{
             return result.next();
         }
     }
 
     public Set<String> getTableColumns(final String table) throws SQLException 
{
         try (final var conn = getConnection();
-             final var result = 
conn.getMetaData().getColumns(conn.getCatalog(), null, table, null)) {
+             final var result = 
conn.getMetaData().getColumns(conn.getCatalog(), conn.getSchema(), table, 
null)) {
             final var columns = new HashSet<String>();
             while (result.next()) {
                 columns.add(result.getString("COLUMN_NAME").toLowerCase());
diff --git 
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java
 
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java
index e91c474057..0270a76c27 100644
--- 
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java
+++ 
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java
@@ -78,7 +78,7 @@ public class JDBCHistoryDeleteDAO implements 
IHistoryDeleteDAO {
         final var tableName = TableHelper.getTableName(model);
 
         try (final var conn = jdbcClient.getConnection();
-             final var result = 
conn.getMetaData().getTables(conn.getCatalog(), null, tableName + "%", new 
String[]{"TABLE"})) {
+             final var result = 
conn.getMetaData().getTables(conn.getCatalog(), conn.getSchema(), tableName + 
"%", new String[]{"TABLE"})) {
             while (result.next()) {
                 tablesToDrop.add(result.getString("TABLE_NAME"));
             }
diff --git 
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCSQLExecutor.java
 
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCSQLExecutor.java
index 5697712a1f..bc422dcb61 100644
--- 
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCSQLExecutor.java
+++ 
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCSQLExecutor.java
@@ -257,7 +257,7 @@ public class JDBCSQLExecutor {
         final var tableNamePattern = TableHelper.getTableName(model) + "%";
         final var tables = new ArrayList<String>();
         try (final var connection = h2Client.getConnection();
-             final var resultSet = 
connection.getMetaData().getTables(connection.getCatalog(), null, 
tableNamePattern, new String[]{"TABLE"})) {
+             final var resultSet = 
connection.getMetaData().getTables(connection.getCatalog(), 
connection.getSchema(), tableNamePattern, new String[]{"TABLE"})) {
             while (resultSet.next()) {
                 tables.add(resultSet.getString("TABLE_NAME"));
             }
diff --git 
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAOIT.java
 
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAOIT.java
index 7e93d08c27..c0a729ba29 100644
--- 
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAOIT.java
+++ 
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAOIT.java
@@ -122,7 +122,7 @@ class JDBCHistoryDeleteDAOIT {
         var jdbcHistoryDeleteDAO = new JDBCHistoryDeleteDAO(jdbcClient, 
tableHelper, tableInstaller, clock);
         jdbcHistoryDeleteDAO.deleteHistory(model, "time_bucket", 3);
         try (final var conn = jdbcClient.getConnection();
-             final var rs = conn.getMetaData().getTables(conn.getCatalog(), 
null, "service_traffic_20230317", null)) {
+             final var rs = conn.getMetaData().getTables(conn.getCatalog(), 
conn.getSchema(), "service_traffic_20230317", null)) {
             assertThat(rs.next()).isTrue();
         }
 
@@ -131,12 +131,12 @@ class JDBCHistoryDeleteDAOIT {
         jdbcHistoryDeleteDAO = new JDBCHistoryDeleteDAO(jdbcClient, 
tableHelper, tableInstaller, clock);
         jdbcHistoryDeleteDAO.deleteHistory(model, "time_bucket", 3);
         try (final var conn = jdbcClient.getConnection();
-             final var rs = conn.getMetaData().getTables(conn.getCatalog(), 
null, "service_traffic_20230317", null)) {
+             final var rs = conn.getMetaData().getTables(conn.getCatalog(), 
conn.getSchema(), "service_traffic_20230317", null)) {
             assertThat(rs.next()).isFalse();
         }
         // ... and should create the new table
         try (final var conn = jdbcClient.getConnection();
-             final var rs = conn.getMetaData().getTables(conn.getCatalog(), 
null, "service_traffic_20230322", null)) {
+             final var rs = conn.getMetaData().getTables(conn.getCatalog(), 
conn.getSchema(), "service_traffic_20230322", null)) {
             assertThat(rs.next()).isTrue();
         }
     }

Reply via email to