【问题标题】:DistributedCache Hadoop - FileNotFound分布式缓存 Hadoop - FileNotFound
【发布时间】:2012-08-28 00:16:39
【问题描述】:

我正在尝试在分布式缓存中放置一个文件。为了做到这一点,我使用 -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。

【问题讨论】:

    标签: hadoop filenotfoundexception distributed-caching distributed-cache


    【解决方案1】:

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

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

    【讨论】:

    • 你能看一下更新吗?它仍然找不到文件
    • 如何从 URIs/Paths 获取文件?
    • 是的,我解决了这个问题。我试图使用使用该 uri 实例化的 FS 实例从 uri 中获取它。我应该尝试在本地获取,我最终做到了,现在可以了。谢谢!
    猜你喜欢
    • 2014-12-02
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多