Fix hadoop task jdk11 compatible (#8799)

* Fix hadoop task jdk11 compatible

* Fix HadoopTaskTest
This commit is contained in:
chencb 2019-11-13 18:32:46 +08:00 committed by Clint Wylie
parent 8cb213aa9f
commit cc2bdb5f51
2 changed files with 29 additions and 5 deletions

View File

@ -171,9 +171,19 @@ public abstract class HadoopTask extends AbstractBatchIndexTask
localClassLoaderURLs.addAll(Arrays.asList(hadoopLoader.getURLs()));
}
ClassLoader parent = null;
if (JvmUtils.isIsJava9Compatible()) {
try {
// See also https://docs.oracle.com/en/java/javase/11/migrate/index.html#JSMIG-GUID-A868D0B9-026F-4D46-B979-901834343F9E
parent = (ClassLoader) ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null);
}
catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
final ClassLoader classLoader = new URLClassLoader(
localClassLoaderURLs.toArray(new URL[0]),
null
parent
);
final String hadoopContainerDruidClasspathJars;

View File

@ -29,6 +29,7 @@ import org.apache.druid.indexing.common.config.TaskConfig;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.granularity.Granularity;
import org.apache.druid.timeline.DataSegment;
import org.apache.druid.utils.JvmUtils;
import org.apache.hadoop.yarn.util.ApplicationClassLoader;
import org.easymock.EasyMock;
import org.joda.time.Interval;
@ -125,18 +126,31 @@ public class HadoopTaskTest
final Class<?> hadoopClazz = Class.forName("org.apache.hadoop.fs.FSDataInputStream", false, classLoader);
assertClassLoaderIsSingular(hadoopClazz.getClassLoader());
final Class<?> druidHadoopConfigClazz = Class.forName("org.apache.druid.indexer.HadoopDruidIndexerConfig", false, classLoader);
final Class<?> druidHadoopConfigClazz = Class.forName(
"org.apache.druid.indexer.HadoopDruidIndexerConfig",
false,
classLoader
);
assertClassLoaderIsSingular(druidHadoopConfigClazz.getClassLoader());
}
public static void assertClassLoaderIsSingular(ClassLoader classLoader)
{
// This is a check against the current HadoopTask which creates a single URLClassLoader with null parent
Assert.assertNull(classLoader.getParent());
if (JvmUtils.isIsJava9Compatible()) {
// See also https://docs.oracle.com/en/java/javase/11/migrate/index.html#JSMIG-GUID-A868D0B9-026F-4D46-B979-901834343F9E
Assert.assertEquals("PlatformClassLoader", classLoader.getParent().getClass().getSimpleName());
} else {
// This is a check against the current HadoopTask which creates a single URLClassLoader with null parent
Assert.assertNull(classLoader.getParent());
}
Assert.assertFalse(classLoader instanceof ApplicationClassLoader);
Assert.assertTrue(classLoader instanceof URLClassLoader);
final ClassLoader appLoader = HadoopDruidIndexerConfig.class.getClassLoader();
Assert.assertNotEquals(StringUtils.format("ClassLoader [%s] is not isolated!", classLoader), appLoader, classLoader);
Assert.assertNotEquals(
StringUtils.format("ClassLoader [%s] is not isolated!", classLoader),
appLoader,
classLoader
);
}
}