This is an automated email from the ASF dual-hosted git repository.

jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 4f192d6bd3 [#9383] fix(iceberg): fix connect IRC failed after idle 
time (#9410)
4f192d6bd3 is described below

commit 4f192d6bd3a4f438482e9ff4c46b7beadec63254
Author: FANNG <[email protected]>
AuthorDate: Tue Dec 9 15:27:31 2025 +0900

    [#9383] fix(iceberg): fix connect IRC failed after idle time (#9410)
    
    ### 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
---
 .../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,

Reply via email to