Java Hadoop MapReduce分布式缓存使用率

Java Hadoop MapReduce分布式缓存使用率,java,hadoop,mapreduce,distributed-caching,bloom-filter,Java,Hadoop,Mapreduce,Distributed Caching,Bloom Filter,我试图重现MapReduce设计模式的Bloom过滤示例。 在以下内容中,我将仅显示感兴趣的代码: public static class BloomFilteringMapper extends Mapper<Object, Text, Text, NullWritable> { private BloomFilter filter = new BloomFilter(); protected void setup( Context context ) throw

我试图重现MapReduce设计模式的Bloom过滤示例。
在以下内容中,我将仅显示感兴趣的代码:

public static class BloomFilteringMapper extends Mapper<Object, Text, Text, NullWritable>
{
    private BloomFilter filter = new BloomFilter();

    protected void setup( Context context ) throws IOException
    {
        URI[] files = DistributedCache.getCacheFiles( context.getConfiguration() );
        String path = files[0].getPath();
        System.out.println( "Reading Bloom Filter from: " + path );
        DataInputStream strm = new DataInputStream( new FileInputStream( path ) );
        filter.readFields( strm );
        strm.close();
    }
    //...
}
public static void main( String[] args ) throws Exception
{
    Job job = new Job( new Configuration(), "description" );
    URI uri = new URI("hdfs://localhost:9000/user/draxent/comment.bloomfilter");
    DistributedCache.addCacheFile( uri, job.getConfiguration() );
    //...
}
我可以看到文件:

-rw-r--r--   1 draxent supergroup        405 2015-11-25 17:12 /user/draxent/comment.bloomfilter
因此,我很确定问题就在眼前:

URI uri = new URI("hdfs://localhost:9000/user/draxent/comment.bloomfilter");
但我尝试了几种不同的配置,如:
"hdfs://user/draxent/comment.bloomfilter“
“/user/draxent/comment.bloomfilter”
“comment.bloomfilter”

没有人工作

我曾试着抬头看问题,但没能解决我的问题

回答评论:

  • ravindra:URI文件[0]包含在main中传递的字符串元素
  • 曼朱纳斯·巴卢:是的,你是对的。但由于文件存在(您可以从bin/hadoop fs-ls中看到),这意味着传递给FileInputStream的字符串路径存在问题。但我总是像往常一样把绳子传给它。我选中了,路径值是:comment.bloomfilter。。。所以它必须是正确的
以下各项应起作用: 删除带有
URI=new URI(…
的行,并将下一行更改为:

DistributedCache.addCacheFile(new Path("/user/draxent/comment.bloomfilter").toUri(), job.getConfiguration());

分布式缓存API已被弃用

您可以使用新API扩展相同的功能。请查看此处的文档:

在驱动程序代码中:-

Job Job=新作业();
...
job.addCacheFile(新路径(文件名).toUri());

在映射器设置方法中:-

Path[] localPaths = context.getLocalCacheFiles();

您能调试从URI[]文件调用收到的值吗?。我怀疑上下文设置不正确。问题不在第行:URI=新URI(“hdfs://localhost:9000/user/draxent/comment.bloomfilter)。此行只能抛出“URISyntaxException”。问题似乎出在第行:DataInputStream strm=new DataInputStream(new FileInputStream(path));。FileInputStream()抛出FileNotFoundException
Path[] localPaths = context.getLocalCacheFiles();