MAPREDUCE在任务中的classPath读取文件



我与我的胖罐捆绑了一个文件" xxx.txt.gz"

我需要在每个地图任务内的每个纱线容器中引用此文件。

因此,如果您在我的罐子里看:

你会看到xxx.txt.gz*

我正在尝试通过

访问此文件
File mappingFile = new File(getClass().getClassLoader().getResource("xxx.txt.gz").getFile())

但是,在运行时,我会从所有任务尝试中从日志中获得以下错误

java.io.FileNotFoundException: file:/local/hadoop/1/yarn/local/usercache/USER/appcache/application_1431608807540_0071/filecache/10/job.jar/job.jar!/xxx.txt.gz (No such file or directory)

换句话说,即使我的胖罐有文件,job.jar也没有。

我该如何解决这个问题?

预先感谢。

还有另一种方法可以从映射器/还原器访问文件。希望这个想法在MapReduce中可能是理想的。

您可以使用MapReduce中可用的分布式高速缓存选项。通过这种方式,您可以使Hadoop将您的文件分配给工作的映射器/还原器将执行的所有容器。

我实际上意识到在hadoop 2.7中,distributedcache被弃用。但是,对于小型实用程序/查找文件,可以将它们添加到HDF中,然后使用常规机制将它们加载到映射器/还原器JVM中。

ex:

public void setup(Context ctx) {
   // gets the job config, therefore, handles the case where the file is located on the local FS or HDFS)
   Configuration jobConf = context.getConfiguration();
   Path filePath = new Path(jobConf.get("my.mapping.file"));
   FileSystem.get(conf).open(filePath);
}

最新更新