From b989a7054c394d0d8742cf29cadcb36247150a34 Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Thu, 10 Sep 2015 13:12:32 -0500 Subject: [PATCH] fix for "java.io.IOException: No FileSystem for scheme: hdfs" error aka workaround for https://issues.apache.org/jira/browse/HDFS-8750 --- .../storage/hdfs/HdfsStorageDruidModule.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/extensions/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsStorageDruidModule.java b/extensions/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsStorageDruidModule.java index 6df0b4969064..ee9a147ac320 100644 --- a/extensions/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsStorageDruidModule.java +++ b/extensions/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsStorageDruidModule.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.Version; import com.fasterxml.jackson.databind.Module; +import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.inject.Binder; import com.google.inject.Inject; @@ -31,7 +32,9 @@ import io.druid.storage.hdfs.tasklog.HdfsTaskLogs; import io.druid.storage.hdfs.tasklog.HdfsTaskLogsConfig; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import java.io.IOException; import java.util.List; import java.util.Properties; @@ -92,6 +95,18 @@ public void configure(Binder binder) // Set explicit CL. Otherwise it'll try to use thread context CL, which may not have all of our dependencies. conf.setClassLoader(getClass().getClassLoader()); + // Ensure that FileSystem class level initialization happens with correct CL + // See https://github.com/druid-io/druid/issues/1714 + ClassLoader currCtxCl = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); + FileSystem.get(conf); + } catch(IOException ex) { + throw Throwables.propagate(ex); + } finally { + Thread.currentThread().setContextClassLoader(currCtxCl); + } + if (props != null) { for (String propName : System.getProperties().stringPropertyNames()) { if (propName.startsWith("hadoop.")) {