From 492fda8e38bb34d55f3828bbfe1126028944f4c8 Mon Sep 17 00:00:00 2001 From: liuhaoyang Date: Tue, 10 Oct 2023 14:42:53 +0800 Subject: [PATCH 1/2] bugfix: When using JDBCStorage Plugin query table metadata, passing database is shown --- .../oap/server/library/client/jdbc/hikaricp/JDBCClient.java | 6 +++--- .../plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java | 2 +- .../plugin/jdbc/common/dao/JDBCHistoryDeleteDAOIT.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) 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 49539fb62605..65c83b9ac881 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 void registerChecker(HealthChecker healthChecker) { public boolean indexExists(final String table, final String index) throws SQLException { try (final var connection = getConnection(); - final var resultSet = connection.getMetaData().getIndexInfo(null, null, table, false, false)) { + final var resultSet = connection.getMetaData().getIndexInfo(connection.getCatalog(), null, table, false, false)) { while (resultSet.next()) { if (resultSet.getString("INDEX_NAME").equalsIgnoreCase(index)) { return true; @@ -164,14 +164,14 @@ public boolean indexExists(final String table, public boolean tableExists(final String table) throws SQLException { try (final var conn = getConnection(); - final var result = conn.getMetaData().getTables(null, null, table, null)) { + final var result = conn.getMetaData().getTables(conn.getCatalog(), null, table, null)) { return result.next(); } } public Set getTableColumns(final String table) throws SQLException { try (final var conn = getConnection(); - final var result = conn.getMetaData().getColumns(null, null, table, null)) { + final var result = conn.getMetaData().getColumns(conn.getCatalog(), null, table, null)) { final var columns = new HashSet(); 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 91c25ab76e6e..e91c474057f0 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 void deleteHistory(Model model, String timeBucketColumnName, int ttl) { final var tableName = TableHelper.getTableName(model); try (final var conn = jdbcClient.getConnection(); - final var result = conn.getMetaData().getTables(null, null, tableName + "%", new String[]{"TABLE"})) { + final var result = conn.getMetaData().getTables(conn.getCatalog(), null, 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/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 9783096b48fb..7e93d08c2764 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 @@ void test() throws SQLException { 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(null, null, "service_traffic_20230317", null)) { + final var rs = conn.getMetaData().getTables(conn.getCatalog(), null, "service_traffic_20230317", null)) { assertThat(rs.next()).isTrue(); } @@ -131,12 +131,12 @@ void test() throws SQLException { 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(null, null, "service_traffic_20230317", null)) { + final var rs = conn.getMetaData().getTables(conn.getCatalog(), null, "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(null, null, "service_traffic_20230322", null)) { + final var rs = conn.getMetaData().getTables(conn.getCatalog(), null, "service_traffic_20230322", null)) { assertThat(rs.next()).isTrue(); } } From d16f342c3263ec626baf7083424868e43a7c50fb Mon Sep 17 00:00:00 2001 From: liuhaoyang Date: Tue, 10 Oct 2023 14:49:27 +0800 Subject: [PATCH 2/2] Update changelog --- docs/en/changes/changes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md index a6ede4f0eb29..38d759b04e6c 100644 --- a/docs/en/changes/changes.md +++ b/docs/en/changes/changes.md @@ -17,6 +17,7 @@ * Update BanyanDB Java Client to 0.5.0. * Fix getInstances query in the BanyanDB Metadata DAO. * BanyanDBStorageClient: Add `keepAliveProperty` API. +* Fix table exists check in the JDBC Storage Plugin. #### UI