使用distributedcache访问mapfile时发生filenotfoundexception

kmynzznz  于 2021-06-04  发布在  Hadoop
关注(0)|答案(1)|浏览(440)

我正在使用hadoopcdf4.7在Yarn模式下运行。中有一个Map文件 hdfs://test1:9100/user/tagdict_builder_output/part-00000 它有两个文件 index 以及 data 我使用以下代码将其添加到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 作为路径,或使用符号链接。但是这些也不起作用。如何解决这个问题?非常感谢。

ncgqoxb0

ncgqoxb01#

正如这里所说:
分布式缓存使用符号链接将缓存文件关联到Map器和还原器的当前工作目录。
所以你应该试着通过 File 对象:

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

编辑1
我最后的建议是:

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

相关问题