访问hadoop分布式缓存中的文件

Pet*_*gan 8 hadoop

我想使用分布式缓存来允许我的映射器访问数据.主要是,我正在使用该命令

DistributedCache.addCacheFile(new URI("/user/peter/cacheFile/testCache1"), conf);
Run Code Online (Sandbox Code Playgroud)

其中/ user/peter/cacheFile/testCache1是hdfs中存在的文件

然后,我的设置功能如下所示:

public void setup(Context context) throws IOException, InterruptedException{
    Configuration conf = context.getConfiguration();
    Path[] localFiles = DistributedCache.getLocalCacheFiles(conf);
    //etc
}
Run Code Online (Sandbox Code Playgroud)

但是,此localFiles数组始终为null.

我最初在单主机群集上运行以进行测试,但我读到这将阻止分布式缓存工作.我尝试使用伪分布式,但这也不起作用

我正在使用hadoop 1.0.3

谢谢彼得

Pet*_*gan 35

这里的问题是我正在做以下事情:

Configuration conf = new Configuration();
Job job = new Job(conf, "wordcount");
DistributedCache.addCacheFile(new URI("/user/peter/cacheFile/testCache1"), conf);
Run Code Online (Sandbox Code Playgroud)

由于Job构造函数生成conf实例的内部副本,因此之后添加缓存文件不会影响事物.相反,我应该这样做:

Configuration conf = new Configuration();
DistributedCache.addCacheFile(new URI("/user/peter/cacheFile/testCache1"), conf);
Job job = new Job(conf, "wordcount");
Run Code Online (Sandbox Code Playgroud)

现在它有效.感谢hadoop用户列表上的Harsh帮助.


小智 11

Configuration conf = new Configuration();  
Job job = new Job(conf, "wordcount");
DistributedCache.addCacheFile(new URI("/userpetercacheFiletestCache1"),job.getConfiguration());
Run Code Online (Sandbox Code Playgroud)

你也可以这样做.