Przeglądaj źródła

HADOOP-19049. Fix StatisticsDataReferenceCleaner classloader leak (#6488)

Contributed by Jia Fan
Jia Fan 1 rok temu
rodzic
commit
d6c66f76ae

+ 1 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java

@@ -4077,6 +4077,7 @@ public abstract class FileSystem extends Configured
       STATS_DATA_CLEANER.
           setName(StatisticsDataReferenceCleaner.class.getName());
       STATS_DATA_CLEANER.setDaemon(true);
+      STATS_DATA_CLEANER.setContextClassLoader(null);
       STATS_DATA_CLEANER.start();
     }
 

+ 9 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemStorageStatistics.java

@@ -34,6 +34,7 @@ import java.util.concurrent.TimeUnit;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 /**
  * This tests basic operations of {@link FileSystemStorageStatistics} class.
@@ -102,6 +103,14 @@ public class TestFileSystemStorageStatistics {
     }
   }
 
+  @Test
+  public void testStatisticsDataReferenceCleanerClassLoader() {
+    Thread thread = Thread.getAllStackTraces().keySet().stream()
+        .filter(t -> t.getName().contains("StatisticsDataReferenceCleaner")).findFirst().get();
+    ClassLoader classLoader = thread.getContextClassLoader();
+    assertNull(classLoader);
+  }
+
   /**
    * Helper method to retrieve the specific FileSystem.Statistics value by name.
    *