yuqi1129 commented on code in PR #11431:
URL: https://github.com/apache/gravitino/pull/11431#discussion_r3356166441


##########
catalogs/catalog-common/src/main/java/org/apache/gravitino/utils/ClassLoaderResourceCleanerUtils.java:
##########
@@ -87,23 +87,44 @@ private static void 
closeStatsDataClearerInFileSystem(ClassLoader targetClassLoa
       throws Exception {
     Class<?> fileSystemClass =
         Class.forName("org.apache.hadoop.fs.FileSystem", true, 
targetClassLoader);
+
+    // If FileSystem was resolved from a parent/AppClassLoader rather than the 
catalog's own
+    // classloader, its CACHE, Statistics cleaner, and MutableQuantiles 
scheduler are shared
+    // across all catalogs in the JVM. Operating on shared static state here 
would close every
+    // catalog's FileSystems and permanently terminate the global scheduler, 
breaking any
+    // subsequent catalog that uses Hadoop metrics. Skip cleanup for shared 
classes and let
+    // the JVM manage them.
+    if (!isOwnedByClassLoader(fileSystemClass, targetClassLoader)) {
+      LOG.debug(
+          "Hadoop FileSystem is owned by {}, not the target classloader {}; 
skipping shared-class cleanup",
+          fileSystemClass.getClassLoader(),
+          targetClassLoader);
+      return;
+    }

Review Comment:
   Fixed. Made `isOwnedByClassLoader` `@VisibleForTesting` package-private and 
added `TestClassLoaderResourceCleanerUtils` with three focused tests:
   
   1. Returns `true` when the class is loaded by exactly the target classloader 
(cleanup proceeds).
   2. Returns `false` when the class was delegated to the parent (child 
`URLClassLoader` scenario — cleanup skipped).
   3. Returns `false` for bootstrap-loaded classes (`String.class`, whose 
`getClassLoader()` returns `null`).
   
   Note: per project guidelines, reflection into private members from tests is 
avoided — the `@VisibleForTesting` package-private accessor is the preferred 
pattern here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to