This is an automated email from the ASF dual-hosted git repository.
jshao pushed a commit to branch branch-0.8
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-0.8 by this push:
new 28b60afd92 [#6506] fix(core): fix SQLExceptionConverterFactory of
entity storage not close (#6631)
28b60afd92 is described below
commit 28b60afd92eec5a1d4827924d52414b840462d0c
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Mar 7 16:27:21 2025 +0800
[#6506] fix(core): fix SQLExceptionConverterFactory of entity storage not
close (#6631)
### What changes were proposed in this pull request?
fix SQLExceptionConverterFactory of entity storage not close
### Why are the changes needed?
Fix: #6506
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
CI pass
Co-authored-by: mchades <[email protected]>
Co-authored-by: Jerry Shao <[email protected]>
---
.../org/apache/gravitino/storage/relational/JDBCBackend.java | 1 +
.../storage/relational/converters/H2ExceptionConverter.java | 4 +++-
.../relational/converters/MySQLExceptionConverter.java | 2 +-
.../relational/converters/SQLExceptionConverterFactory.java | 12 +++++++++++-
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
b/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
index 8e3cf5c871..a089251297 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
@@ -377,6 +377,7 @@ public class JDBCBackend implements RelationalBackend {
@Override
public void close() throws IOException {
SqlSessionFactoryHelper.getInstance().close();
+ SQLExceptionConverterFactory.close();
if (jdbcDatabase != null) {
jdbcDatabase.close();
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/converters/H2ExceptionConverter.java
b/core/src/main/java/org/apache/gravitino/storage/relational/converters/H2ExceptionConverter.java
index a64db131a1..ff297d8d27 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/converters/H2ExceptionConverter.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/converters/H2ExceptionConverter.java
@@ -37,10 +37,12 @@ public class H2ExceptionConverter implements
SQLExceptionConverter {
throws IOException {
switch (se.getErrorCode()) {
case DUPLICATED_ENTRY_ERROR_CODE:
+ // compatible with H2 in MySQL mode
+ case MySQLExceptionConverter.DUPLICATED_ENTRY_ERROR_CODE:
throw new EntityAlreadyExistsException(
se, "The %s entity: %s already exists.", type.name(), name);
default:
- throw new IOException(se);
+ throw new IOException("error code: " + se.getErrorCode(), se);
}
}
}
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/converters/MySQLExceptionConverter.java
b/core/src/main/java/org/apache/gravitino/storage/relational/converters/MySQLExceptionConverter.java
index 1190f9ce4b..6b5035f23a 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/converters/MySQLExceptionConverter.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/converters/MySQLExceptionConverter.java
@@ -30,7 +30,7 @@ import org.apache.gravitino.EntityAlreadyExistsException;
*/
public class MySQLExceptionConverter implements SQLExceptionConverter {
/** It means found a duplicated primary key or unique key entry in MySQL. */
- private static final int DUPLICATED_ENTRY_ERROR_CODE = 1062;
+ static final int DUPLICATED_ENTRY_ERROR_CODE = 1062;
@SuppressWarnings("FormatStringAnnotation")
@Override
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/converters/SQLExceptionConverterFactory.java
b/core/src/main/java/org/apache/gravitino/storage/relational/converters/SQLExceptionConverterFactory.java
index feb0fb0d7d..66b4213047 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/converters/SQLExceptionConverterFactory.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/converters/SQLExceptionConverterFactory.java
@@ -26,7 +26,7 @@ import org.apache.gravitino.Configs;
public class SQLExceptionConverterFactory {
private static final Pattern TYPE_PATTERN = Pattern.compile("jdbc:(\\w+):");
- private static SQLExceptionConverter converter;
+ private static volatile SQLExceptionConverter converter;
private SQLExceptionConverterFactory() {}
@@ -56,4 +56,14 @@ public class SQLExceptionConverterFactory {
Preconditions.checkState(converter != null, "Exception converter is not
initialized.");
return converter;
}
+
+ public static void close() {
+ if (converter != null) {
+ synchronized (SQLExceptionConverterFactory.class) {
+ if (converter != null) {
+ converter = null;
+ }
+ }
+ }
+ }
}