分享

${mapred.local.dir}的选择策略

gwgyk 发表于 2014-11-24 16:37:56 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 7 8166
不好意思,又来麻烦大家,这次是这么几个问题:1、core包下的org/apache/hadoop/fs/LocalDirAllocator.java这个类是不是用来管理${mapred.local.dir}的?

2、在上面那个类的getLocalPathForWrite()方法中是不是实现了${mapred.local.dir}的选择策略啊?


3、${mapred.local.dir}是怎么来选择的呢?


已有(7)人评论

跳转到指定楼层
bioger_hit 发表于 2014-11-24 19:30:43


楼主,可以参考下面,源码方面研究的人不多:

/** Get a path from the local FS for reading. We search through all the
* configured dirs for the file's existence and return the complete
* path to the file when we find one
*/
public synchronized Path getLocalPathToRead(String pathStr, Configuration conf) throws IOException {
confChanged(conf);
//推测应该是文件的个数
int numDirs = localDirsPath.length;
int numDirsSearched = 0;
//remove the leading slash from the path (to make sure that the uri
//resolution results in a valid path on the dir being checked)
//检测有效路径
if (pathStr.startsWith("/")) {
pathStr = pathStr.substring(1);
}
Path childPath = new Path(pathStr);
while (numDirsSearched < numDirs) {
//从文件数组中,根据路径找到文件
Path file = new Path(localDirsPath[numDirsSearched], childPath);
//找到返回文件
if (localFS.exists(file)) {
return file;
}
numDirsSearched++;
}


//no path found
throw new DiskErrorException ("Could not find " + pathStr +" in any of" +
" the configured local directories");
}



更多内容可以参考参考源码


回复

使用道具 举报

desehawk 发表于 2014-11-24 19:41:09
bioger_hit 发表于 2014-11-24 19:30
楼主,可以参考下面,源码方面研究的人不多:
显然采用的是循环,楼主可能想的复杂了
回复

使用道具 举报

gwgyk 发表于 2014-11-24 21:53:54
desehawk 发表于 2014-11-24 19:41
显然采用的是循环,楼主可能想的复杂了

有循环,但不仅仅是循环。在循环之前还得做一些工作,比如判断磁盘剩余量大小等等。

主要这一块涉及到的数据结构比较多,而且那些变量都不知道是怎么初始化的,所以不太好分析

如果有这方面的资料,麻烦给我一些啊,谢谢啦
回复

使用道具 举报

gwgyk 发表于 2014-11-24 22:35:24
bioger_hit 发表于 2014-11-24 19:30
楼主,可以参考下面,源码方面研究的人不多:

好的,如果你还有这方面的资料,麻烦分享下啦。谢谢啦
回复

使用道具 举报

desehawk 发表于 2014-11-24 23:31:57
gwgyk 发表于 2014-11-24 22:35
好的,如果你还有这方面的资料,麻烦分享下啦。谢谢啦



网上倒是还有些资料

链接

回复

使用道具 举报

gwgyk 发表于 2014-11-25 09:53:12
desehawk 发表于 2014-11-24 23:31
网上倒是还有些资料

链接

有没有详细一些的代码分析啊?
回复

使用道具 举报

bioger_hit 发表于 2014-11-26 19:50:32
gwgyk 发表于 2014-11-25 09:53
有没有详细一些的代码分析啊?


楼主,只有这些了。有的话,会在分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条