This is an automated email from the ASF dual-hosted git repository.
yuqi4733 pushed a commit to branch branch-1.1
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-1.1 by this push:
new b4442bca69 [#9383] fix(iceberg): fix connect IRC failed after idle
time (#9421)
b4442bca69 is described below
commit b4442bca698e9c1c271c7be58a4af2de8c07f255
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Dec 9 16:11:54 2025 +0800
[#9383] fix(iceberg): fix connect IRC failed after idle time (#9421)
### What changes were proposed in this pull request?
Doesn't deregister the JDBC driver for Iceberg REST server, because IRC
use the same classloader to recreate catalog wrapper, if the driver is
deregistered, it couldn't be register again.
### Why are the changes needed?
Fix: #9383
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
testing in the local environment
Co-authored-by: FANNG <[email protected]>
---
.../iceberg/common/ops/IcebergCatalogWrapper.java | 21 +++++++++++++++++++++
.../iceberg/service/CatalogWrapperForREST.java | 5 +++++
2 files changed, 26 insertions(+)
diff --git
a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java
b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java
index 54513e9a15..04c0627dfb 100644
---
a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java
+++
b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java
@@ -281,6 +281,7 @@ public class IcebergCatalogWrapper implements AutoCloseable
{
@Override
public void close() throws Exception {
+ LOG.info("Closing IcebergCatalogWrapper for catalog: {}", catalog.name());
if (catalog instanceof AutoCloseable) {
// JdbcCatalog and ClosableHiveCatalog implement AutoCloseable and will
handle their own
// cleanup
@@ -288,6 +289,26 @@ public class IcebergCatalogWrapper implements
AutoCloseable {
}
metadataCache.close();
+ // For Iceberg REST server which use the same classloader when recreating
catalog wrapper, the
+ // Driver couldn't be reloaded after deregister()
+ if (useDifferentClassLoader()) {
+ closeJdbcDriverResources();
+ }
+ }
+
+ /**
+ * Whether the wrapper is recreated with a different classloader.
+ *
+ * <p>Returning {@code true} allows JDBC drivers loaded by an isolated
classloader to be
+ * deregistered when the wrapper closes so the classloader can be garbage
collected. Implementors
+ * that intentionally reuse the same classloader (for example, an Iceberg
REST server instance)
+ * should override and return {@code false} to skip deregistration.
+ */
+ protected boolean useDifferentClassLoader() {
+ return true;
+ }
+
+ private void closeJdbcDriverResources() {
// Because each catalog in Gravitino has its own classloader, after a
catalog is no longer used
// for a long time or dropped, the instance of classloader needs to be
released. In order to
// let JVM GC remove the classloader, we need to release the resources of
the classloader. The
diff --git
a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/CatalogWrapperForREST.java
b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/CatalogWrapperForREST.java
index 2c96cfd5f8..1d93f1a424 100644
---
a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/CatalogWrapperForREST.java
+++
b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/CatalogWrapperForREST.java
@@ -174,6 +174,11 @@ public class CatalogWrapperForREST extends
IcebergCatalogWrapper {
return catalogConfigToClients;
}
+ @Override
+ protected boolean useDifferentClassLoader() {
+ return false;
+ }
+
private LoadTableResponse injectCredentialConfig(
TableIdentifier tableIdentifier,
LoadTableResponse loadTableResponse,