Hadoop 2.x的DistributedCache无法工作的问题
来源:互联网 发布:redis session共享 php 编辑:程序博客网 时间:2024/06/16 19:50
转自:http://www.codelast.com/?p=8131
现象:和这个帖子描述的一样,简单说来就是,在Hadoop 2.x上,用新的DistributedCache的API,在mapper中会获取不到这个cache文件。
下面就详细地描述一下新旧API的用法区别以及解决办法。
『1』旧API
将HDFS文件添加到distributed cache中:
Configuration conf = job.getConfiguration();
DistributedCache.addCacheFile(
new
URI(inputFileOnHDFS), conf);
// add file to distributed cache
其中,inputFileOnHDFS是一个HDFS文件的路径,也就是你要用作distribute cache的文件的路径,例如 /user/codelast/123.txt
在mapper的setup()方法中:
Configuration conf = context.getConfiguration();
Path[] localCacheFiles = DistributedCache.getLocalCacheFiles(conf);
readCacheFile(localCacheFiles[
0
]);
其中,readCacheFile()是我们自己的读取cache文件的方法,可能是这样做的(仅举个例子):
private
static
void
readCacheFile(Path cacheFilePath)
throws
IOException {
BufferedReader reader =
new
BufferedReader(
new
FileReader(cacheFilePath.toUri().getPath()));
String line;
while
((line = reader.readLine()) !=
null
) {
//TODO: your code here
}
reader.close();
}
文章来源:http://www.codelast.com/
『2』新API
上面的代码中,addCacheFile() 方法和 getLocalCacheFiles() 都已经被Hadoop 2.x标记为 @Deprecated 了。
因此,有一套新的API来实现同样的功能,这个链接里有示例,我在这里再详细地写一下。
将HDFS文件添加到distributed cache中:
job.addCacheFile(
new
Path(inputFileOnHDFS).toUri());
在mapper的setup()方法中:
Configuration conf = context.getConfiguration();
URI[] localCacheFiles = context.getCacheFiles();
readCacheFile(localCacheFiles[
0
]);
其中,readCacheFile()是我们自己的读取cache文件的方法,可能是这样做的(仅举个例子):
private
static
void
readCacheFile(URI cacheFileURI)
throws
IOException {
BufferedReader reader =
new
BufferedReader(
new
FileReader(cacheFileURI.getPath()));
String line;
while
((line = reader.readLine()) !=
null
) {
//TODO: your code here
}
reader.close();
}
但是就像文章开头的那个链接里所描述的问题一样,你可能会发现 context.getCacheFiles() 总是返回null,也就是你无法读到cache文件。
这个问题有可能是这个bug造成的,你可以对比一下你的Hadoop版本。
文章来源:http://www.codelast.com/
『3』解决办法
(1)打patch
(2)升级Hadoop版本
(3)使用旧的DistributedCache API,经测试OK
文章来源:http://www.codelast.com/
- 上一篇: [原创] 去除流氓插件“微度标签页”内置的“亿起发”返利链接跳转
- 下一篇: [原创] 再谈 共轭方向法/Conjugate Direction Method In Optimization
- Hadoop 2.x的DistributedCache无法工作的问题
- Hadoop 2.x的DistributedCache无法工作的问题
- hadoop DistributedCache的使用
- hadoop的DistributedCache
- Hadoop DistributedCache的使用解释
- 如何使用Hadoop的DistributedCache
- Hadoop-基于DistributedCache的复制联结
- Hadoop的分布式缓存DistributedCache使用方法
- hadoop 2.x yarn 的工作机制
- 在Eclipse上运行Hadoop程序,DistributedCache找不到文件缓存的问题
- Hadoop 学习笔记:DistributedCache.addCacheFile(URI, conf)的用法
- DistributedCache.Version #的作用
- DistributedCache的使用
- Hadoop DistributedCache
- Hadoop DistributedCache
- Hadoop DistributedCache
- hadoop DistributedCache
- Hadoop 无法启动的问题
- java笔记--关于线程同步(5种同步方式)
- 黑马程序员--Java之多线程09
- R cannot be resolved or is not a field
- 关于JAVA多线程同步
- java.lang.UnsatisfiedLinkError: Couldn't load x from loader dalvik.system.PathClassLoader
- Hadoop 2.x的DistributedCache无法工作的问题
- java线程同步的方法
- Qt--安装QWT
- qt---安装使用Qwtpolat
- Collections(集合操作的工具类)&集合的同步控制&不可变集合的设置
- qt--安装使用qwtplot3d
- 欢迎使用CSDN-markdown编辑器
- Bellman-ford算法
- VS常用快捷键