From a03f58dca7e938515685e469de2d91f835f14432 Mon Sep 17 00:00:00 2001 From: Ling Hengqian Date: Thu, 17 Oct 2024 19:24:51 +0800 Subject: [PATCH] Fixes `JDBCRepository` improper handling of H2database in memory mode (#33282) --- RELEASE-NOTES.md | 4 +++- .../repository/standalone/jdbc/JDBCRepository.java | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 58d2eee17f509..f92f04a7c6513 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -6,9 +6,12 @@ ### Enhancement 1. Proxy: Add query parameters and check for mysql kill processId - [#33274](https://github.com/apache/shardingsphere/pull/33274) +1. Proxy Native: Change the Base Docker Image of ShardingSphere Proxy Native - [#33263](https://github.com/apache/shardingsphere/issues/33263) ### Bug Fix +1. Mode: Fixes `JDBCRepository` improper handling of H2database in memory mode - [#33281](https://github.com/apache/shardingsphere/issues/33281) + ### Change Log 1. [MILESTONE](https://github.com/apache/shardingsphere/milestone/30) @@ -59,7 +62,6 @@ 1. Infra: Support compiling and using ShardingSphere under OpenJDK 23 - [#33025](https://github.com/apache/shardingsphere/pull/33025) 1. Hive: Support Hive integration module to connect to HiveServer2 4.0.1 - [#33212](https://github.com/apache/shardingsphere/pull/33212) 1. Infra: Support building Example module with OpenJDK 23 - [#33224](https://github.com/apache/shardingsphere/pull/33224) -1. Proxy Native: Change the Base Docker Image of ShardingSphere Proxy Native - [#33263](https://github.com/apache/shardingsphere/issues/33263) ### Bug Fix diff --git a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java index 0c5ce8b14237d..098b9e965725c 100644 --- a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java +++ b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java @@ -66,6 +66,7 @@ public void init(final Properties props) { try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { + statement.execute(repositorySQL.getCreateTableSQL()); // TODO remove it later. Add for reset standalone test e2e's env. Need to close DataSource to release H2's memory data if (jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.JDBC_URL).contains("h2:mem:")) { try { @@ -74,7 +75,6 @@ public void init(final Properties props) { } } // Finish TODO - statement.execute(repositorySQL.getCreateTableSQL()); } } @@ -185,8 +185,18 @@ public void update(final String key, final String value) { } } + /** + * Delete the specified row. + * Once the database connection involved in this row of data has been closed by other threads and this row of data is located in the H2Database started in memory mode, + * the data is actually deleted. + * + * @param key key of data + */ @Override public void delete(final String key) { + if (dataSource.isClosed() && dataSource.getJdbcUrl().startsWith("jdbc:h2:mem:")) { + return; + } try ( Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(repositorySQL.getDeleteSQL())) {