From dec1188ccecb463c2e7b5fdb9724984ed777f3e5 Mon Sep 17 00:00:00 2001 From: Jesse Tuglu Date: Mon, 16 Dec 2024 09:09:34 -0800 Subject: [PATCH] Fix Hadoop Indexing CLI for versions JDK v9+ For JDK v9+ this job will fail as URLClassloader is no longer the default classloader. Additionally, with the introduction of the jmod system, the job failed to find the correct JDK-included modules because the new classloader constructed for the job didn't reference the system classloader. Adding ClassLoader.getSystemClassLoader() as the parent classloader fixes this. --- .../org/apache/druid/cli/CliHadoopIndexer.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/services/src/main/java/org/apache/druid/cli/CliHadoopIndexer.java b/services/src/main/java/org/apache/druid/cli/CliHadoopIndexer.java index 30534ccafff7..a1a382318112 100644 --- a/services/src/main/java/org/apache/druid/cli/CliHadoopIndexer.java +++ b/services/src/main/java/org/apache/druid/cli/CliHadoopIndexer.java @@ -29,6 +29,7 @@ import org.apache.druid.indexing.common.config.TaskConfig; import org.apache.druid.indexing.common.task.Initialization; import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.utils.JvmUtils; import java.io.File; import java.lang.reflect.Method; @@ -39,6 +40,7 @@ import java.util.List; /** + * */ @Command( name = "hadoop", @@ -55,12 +57,12 @@ public class CliHadoopIndexer implements Runnable private String argumentSpec; @Option(name = {"-c", "--coordinate", "hadoopDependencies"}, - description = "extra dependencies to pull down (e.g. non-default hadoop coordinates or extra hadoop jars)") + description = "extra dependencies to pull down (e.g. non-default hadoop coordinates or extra hadoop jars)") @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") private List coordinates; @Option(name = "--no-default-hadoop", - description = "don't pull down the default hadoop version") + description = "don't pull down the default hadoop version") public boolean noDefaultHadoop; @Inject @@ -84,9 +86,7 @@ public void run() extensionURLs.addAll(Arrays.asList(extensionLoader.getURLs())); } - final List nonHadoopURLs = Arrays.asList( - ((URLClassLoader) CliHadoopIndexer.class.getClassLoader()).getURLs() - ); + final List nonHadoopURLs = JvmUtils.systemClassPath(); final List driverURLs = new ArrayList<>(nonHadoopURLs); // put hadoop dependencies last to avoid jets3t & apache.httpcore version conflicts @@ -95,7 +95,10 @@ public void run() driverURLs.addAll(Arrays.asList(hadoopLoader.getURLs())); } - final URLClassLoader loader = new URLClassLoader(driverURLs.toArray(new URL[0]), null); + final URLClassLoader loader = new URLClassLoader( + driverURLs.toArray(new URL[0]), + ClassLoader.getSystemClassLoader() + ); Thread.currentThread().setContextClassLoader(loader); final List jobUrls = new ArrayList<>();