Skip to content

Commit

Permalink
Fixes JDBCRepository improper handling of H2database in memory mode (
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian authored Oct 17, 2024
1 parent 15604a3 commit a03f58d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<String>getValue(JDBCRepositoryPropertyKey.JDBC_URL).contains("h2:mem:")) {
try {
Expand All @@ -74,7 +75,6 @@ public void init(final Properties props) {
}
}
// Finish TODO
statement.execute(repositorySQL.getCreateTableSQL());
}
}

Expand Down Expand Up @@ -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())) {
Expand Down

0 comments on commit a03f58d

Please sign in to comment.