我浏览了 Hadoop 代码。这些参数(mapreduce.job.cache.files.visibilities和mapreduce.job.cache.archives.visibilities)不能通过配置设置。
这些参数在MRJobConfig.java中定义:
public static final String CACHE_FILE_VISIBILITIES = "mapreduce.job.cache.files.visibilities";
public static final String CACHE_ARCHIVES_VISIBILITIES = "mapreduce.job.cache.archives.visibilities";
org.apache.hadoop.mapreduce.JobResourceUploader.java,有一个函数uploadFiles()。此函数将临时文件、jar 和存档上传到分布式缓存:
此函数通过调用以下函数确定文件和档案的可见性:
// set the public/private visibility of the archives and files
ClientDistributedCacheManager.determineTimestampsAndCacheVisibilities(conf);
上述函数调用,最终命中org.apache.hadoop.mapreduce.filecache.ClientDistributedCacheManager.java中的determineCacheVisibilities()函数
根据这个函数的描述:
/**
* Determines the visibilities of the distributed cache files and
* archives. The visibility of a cache path is "public" if the leaf component
* has READ permissions for others, and the parent subdirs have
* EXECUTE permissions for others
* @param job
* @throws IOException
*/
public static void determineCacheVisibilities(Configuration job,
所以可见性是根据叶子文件和父目录的权限来确定的。
在ClientDistributedCacheManager.java中,isPublic()方法有计算可见度的逻辑:
//the leaf level file should be readable by others
if (!checkPermissionOfOther(fs, current, FsAction.READ, statCache)) {
return false;
}
return ancestorsHaveExecutePermissions(fs, current.getParent(), statCache);
最后确定权限后,在以下函数中设置可见性:
static void setArchiveVisibilities(Configuration conf, String booleans) {
conf.set(MRJobConfig.CACHE_ARCHIVES_VISIBILITIES, booleans);
}
static void setFileVisibilities(Configuration conf, String booleans) {
conf.set(MRJobConfig.CACHE_FILE_VISIBILITIES, booleans);
}
所以,即使你在命令行中指定了这些配置,也不会考虑配置参数。这些配置由框架本身以编程方式设置。
另外,我检查了 mapred-default.xml。可见性没有默认配置参数。