hadoop - 分布式缓存 Hadoop - FileNotFound

标签 hadoop filenotfoundexception distributed-caching distributed-cache

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

相关文章:

hadoop - hadoop的工作是ThreadSafe吗?

hadoop - 等效YARN MRv2 JobClient

c# - Copy local = false file not found 异常问题

caching - Azure 本地缓存与分布式缓存

hadoop - yarn 的好处

mongodb - 使用 MongoDB 的 Hive 表映射

java - 文件存在时出现 FileNotFoundException

java - 如何在 "D:\"中创建 TrueZip 存档?

java - AWS Elastic Beanstalk 缓存?

java - 为什么 Hazelcast Map 违反了 Map 的一般契约,该契约要求在比较对象时使用 equals 方法