【问题标题】:FileNotFoundException when using DistributedCache to access MapFile使用 DistributedCache 访问 MapFile 时出现 FileNotFoundException
【发布时间】:2014-07-21 13:34:56
【问题描述】:

我正在使用以纱线模式运行的 hadoop cdf4.7。 hdfs://test1:9100/user/tagdict_builder_output/part-00000 中有一个 MapFile 它有两个文件indexdata

我使用以下代码将其添加到distributedCache:

Configuration conf = new Configuration();
Path tagDictFilePath = new Path("hdfs://test1:9100/user/tagdict_builder_output/part-00000");
DistributedCache.addCacheFile(tagDictFilePath.toUri(), conf);
Job job = new Job(conf);

并在Mapper设置时初始化一个MapFile.Reader:

        @Override
        protected void setup(Context context) throws IOException, InterruptedException {



            Path[] localFiles = DistributedCache.getLocalCacheFiles(context.getConfiguration());
            if (localFiles != null && localFiles.length > 0 && localFiles[0] != null) {
                String mapFileDir = localFiles[0].toString();
                LOG.info("mapFileDir " + mapFileDir);
                FileSystem fs = FileSystem.get(context.getConfiguration());
                reader = new MapFile.Reader(fs, mapFileDir, context.getConfiguration());
            }
            else {
                throw new IOException("Could not read lexicon file in DistributedCache");
            }
}

但它会抛出 FileNotFoundException:

Error: java.io.FileNotFoundException: File does not exist: /home/mps/cdh/local/usercache/mps/appcache/application_1405497023620_0045/container_1405497023620_0045_01_000012/part-00000/data
        at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:824)
        at org.apache.hadoop.io.SequenceFile$Reader.<init>(SequenceFile.java:1704)
        at org.apache.hadoop.io.MapFile$Reader.createDataFileReader(MapFile.java:452)
        at org.apache.hadoop.io.MapFile$Reader.open(MapFile.java:426)
        at org.apache.hadoop.io.MapFile$Reader.<init>(MapFile.java:396)
        at org.apache.hadoop.io.MapFile$Reader.<init>(MapFile.java:405)
        at aps.Cdh4MD5TaglistPreprocessor$Vectorizer.setup(Cdh4MD5TaglistPreprocessor.java:61)
        at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:142)
        at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:756)
        at org.apache.hadoop.mapred.MapTask.run(MapTask.java:338)
        at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:160)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:415)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1438)
        at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:155)

我也试过/user/tagdict_builder_output/part-00000 作为路径,或者使用符号链接。但是这些也不起作用。如何解决这个问题?非常感谢。

【问题讨论】:

    标签: hadoop mapreduce bigdata cloudera distributed-cache


    【解决方案1】:

    正如它所说的here

    分布式缓存使用符号链接将缓存文件与映射器和缩减器的当前工作目录相关联。

    所以你应该尝试通过File 对象来访问你的文件:

    File f = new File("./part-00000");
    

    EDIT1

    我最后的建议:

    DistributedCache.addCacheFile(new URI(tagDictFilePath.toString() + "#cache-file"), conf);
    DistributedCache.createSymlink(conf);
    ...
    // in mapper
    File f = new File("cache-file");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多