分布式缓存hadoop-filenotfound

i7uq4tfw  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(512)

我正试图在分布式缓存中放置一个文件。为此,我使用-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。

yrwegjxp

yrwegjxp1#

第一次检查 mapred.cache.files 以查看文件是否在缓存中。您可以在Map器中检索它:

...
Path[] files = DistributedCache.getLocalCacheFiles(context.getConfiguration());
File myFile = new File(files[0].getName());
//read your file content
...

相关问题