我正在尝试将文件放入分布式缓存中。为了做到这一点,我使用 -files 选项调用我的驱动程序类,类似于:
hadoop jar job.jar my.driver.class -files MYFILE input output
getCacheFiles()
和 getLocalCacheFiles()
返回包含 MYFILE 的 URI/路径数组。
(例如:hdfs://localhost/tmp/hadoopuser/mapred/staging/knappy/.staging/job_201208262359_0005/files/histfile#histfile)
不幸的是,当试图在 map 任务中检索 MYFILE 时,它会抛出一个 FileNotFoundException
。
我在独立(本地)模式和伪分布式模式下都试过了。
你知道可能是什么原因吗?
更新:
下面三行:
System.out.println("cache files:"+ctx.getConfiguration().get("mapred.cache.files"));
uris = DistributedCache.getLocalCacheFiles(ctx.getConfiguration());
for(Path uri: uris){
System.out.println(uri.toString());
System.out.println(uri.getName());
if(uri.getName().contains(Constants.PATH_TO_HISTFILE)){
histfileName = uri.getName();
}
}
打印出来:
cache files:file:/home/knappy/histfile#histfile
/tmp/hadoop-knappy/mapred/local/archive/-7231_-1351_105/file/home/knappy/histfile
histfile
因此,该文件似乎列在 job.xml mapred.cache.files
属性中,并且本地文件似乎存在。尽管如此,还是会抛出 FileNotFoundException。
最佳答案
首先检查作业的 xml 中的 mapred.cache.files
以查看文件是否在缓存中。
您可以在映射器中检索它:
...
Path[] files = DistributedCache.getLocalCacheFiles(context.getConfiguration());
File myFile = new File(files[0].getName());
//read your file content
...
关于hadoop - 分布式缓存 Hadoop - FileNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12151249/