From 4f0f5a546ce29169df34034622249b8fc9acf370 Mon Sep 17 00:00:00 2001 From: Jia Fan Date: Sat, 3 Feb 2024 22:48:52 +0800 Subject: [PATCH] HADOOP-19049. Fix StatisticsDataReferenceCleaner classloader leak (#6488) Contributed by Jia Fan --- .../src/main/java/org/apache/hadoop/fs/FileSystem.java | 1 + .../hadoop/fs/TestFileSystemStorageStatistics.java | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java index 0213772ab6..768fd5b5e1 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java @@ -4077,6 +4077,7 @@ private interface StatisticsAggregator { STATS_DATA_CLEANER. setName(StatisticsDataReferenceCleaner.class.getName()); STATS_DATA_CLEANER.setDaemon(true); + STATS_DATA_CLEANER.setContextClassLoader(null); STATS_DATA_CLEANER.start(); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemStorageStatistics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemStorageStatistics.java index e99f0f2348..5710049afb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemStorageStatistics.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemStorageStatistics.java @@ -34,6 +34,7 @@ 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 void testGetLong() { } } + @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. *