1

我正在尝试将文件放在分布式缓存中。为了做到这一点,我使用 -files 选项调用我的驱动程序类,例如:

   hadoop jar job.jar my.driver.class -files MYFILE input output

getCacheFiles()和包含 MYFILE 的 URI/路径的返回getLocalCacheFiles()数组。(例如: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.xmlmapred.cache.files属性中,并且似乎存在本地文件。尽管如此,还是会抛出 FileNotFoundException。

4

1 回答 1

1

首先检查mapred.cache.files作业的 xml 以查看文件是否在缓存中。您可以在映射器中检索它:

...
Path[] files = DistributedCache.getLocalCacheFiles(context.getConfiguration());
File myFile = new File(files[0].getName());
//read your file content
...
于 2012-08-28T12:35:15.223 回答