0

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

我使用以下代码将其添加到分布式缓存:

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:</p>

        @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作为路径,或者使用符号链接。但是这些也不起作用。如何解决这个问题?非常感谢。

4

1 回答 1

0

正如这里所说:

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

所以你应该尝试通过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");
于 2014-07-21T14:35:44.147 回答