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 8a021e95ff [#8741] improvement(catalog-common): Unload common logging 
in htrace. (#8742)
8a021e95ff is described below

commit 8a021e95ffa8feaae8b6a0fa03e9057c47349fee
Author: Mini Yu <[email protected]>
AuthorDate: Fri Oct 10 12:07:49 2025 +0800

    [#8741] improvement(catalog-common): Unload common logging in htrace. 
(#8742)
    
    ### What changes were proposed in this pull request?
    
    Unloaded common logging in htrace when catalogs are about to close.
    
    ### Why are the changes needed?
    
    We need to unload it or the class loader that loads it will not be
    cleaned
    
    Fix: #8741
    
    ### Does this PR introduce _any_ user-facing change?
    
    N/A.
    
    ### How was this patch tested?
    
    Test locally.
---
 .../utils/ClassLoaderResourceCleanerUtils.java     | 23 +++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git 
a/catalogs/catalog-common/src/main/java/org/apache/gravitino/utils/ClassLoaderResourceCleanerUtils.java
 
b/catalogs/catalog-common/src/main/java/org/apache/gravitino/utils/ClassLoaderResourceCleanerUtils.java
index 3601351e36..9ecece6eec 100644
--- 
a/catalogs/catalog-common/src/main/java/org/apache/gravitino/utils/ClassLoaderResourceCleanerUtils.java
+++ 
b/catalogs/catalog-common/src/main/java/org/apache/gravitino/utils/ClassLoaderResourceCleanerUtils.java
@@ -126,13 +126,13 @@ public class ClassLoaderResourceCleanerUtils {
       clearThreadLocalMap(thread, classLoader);
       // Close all threads that are using the FilesetCatalogOperations class 
loader
       if (runningWithClassLoader(thread, classLoader)) {
-        LOG.info("Interrupting thread: {}", thread.getName());
+        LOG.debug("Interrupting thread: {}", thread.getName());
         thread.setContextClassLoader(null);
         thread.interrupt();
         try {
           thread.join(500);
         } catch (InterruptedException e) {
-          LOG.warn("Failed to join thread: {}", thread.getName(), e);
+          LOG.debug("Failed to join thread: {}", thread.getName(), e);
         }
       }
     }
@@ -178,7 +178,7 @@ public class ClassLoaderResourceCleanerUtils {
             if (value != null
                 && value.getClass().getClassLoader() != null
                 && value.getClass().getClassLoader() == targetClassLoader) {
-              LOG.info(
+              LOG.debug(
                   "Cleaning up thread local {} for thread {} with custom class 
loader",
                   value,
                   thread.getName());
@@ -188,7 +188,7 @@ public class ClassLoaderResourceCleanerUtils {
         }
       }
     } catch (Exception e) {
-      LOG.warn("Failed to clean up thread locals for thread {}", 
thread.getName(), e);
+      LOG.debug("Failed to clean up thread locals for thread {}", 
thread.getName(), e);
     }
   }
 
@@ -221,6 +221,19 @@ public class ClassLoaderResourceCleanerUtils {
    */
   private static void releaseLogFactoryInCommonLogging(ClassLoader 
currentClassLoader)
       throws Exception {
+
+    // If we use fileset with the local file system, HTrace will be used, so 
we need to
+    // release the HTrace LogFactory as well.
+    try {
+      Class<?> htraceLogFactoryClass =
+          Class.forName(
+              "org.apache.htrace.shaded.commons.logging.LogFactory", true, 
currentClassLoader);
+      MethodUtils.invokeStaticMethod(htraceLogFactoryClass, "release", 
currentClassLoader);
+    } catch (Exception e) {
+      // Ignore if htrace is not used
+      LOG.debug("HTrace is not used, skipping release of HTrace 
LogFactory...");
+    }
+
     // Release the LogFactory for the FilesetCatalogOperations class loader
     Class<?> logFactoryClass =
         Class.forName("org.apache.commons.logging.LogFactory", true, 
currentClassLoader);
@@ -297,7 +310,7 @@ public class ClassLoaderResourceCleanerUtils {
     try {
       consumer.accept(value);
     } catch (Exception e) {
-      LOG.warn("Failed to execute consumer: ", e);
+      LOG.debug("Failed to execute consumer: ", e);
     }
   }
 }

Reply via email to