一、前言
1. 版本:
Hadoop 源码版本: Version 2.7.1
Spark 源码版本: Version 2.4.1
二、分析
1. Spark 里 BlockManager 的 LOCAL_DIRS
在 DiskBlockManager里的成员变量 localDirs 代表了 BlockManager 写磁盘的本地目录列表,该成员变量的 DiskBlockManager.scala代码如下:
/* Create one local directory for each path mentioned in spark.local.dir; then, inside this
* directory, create multiple subdirectories that we will hash files into, in order to avoid
* having really large inodes at the top level. */
private[spark] val localDirs: Array[File] = createLocalDirs(conf)
if (localDirs.isEmpty) {
logError("Failed to create any local dir.")
System.exit(ExecutorExitCode.DISK_STORE_FAILED_TO_CREATE_DIR)
}
跟踪createLocalDirs的调用栈,如下:DiskBlockManager.createLocalDirs -> Utils.getConfiguredLocalDirs -> Utils.getYarnLocalDirs(conf).split(",") -> conf.getenv("LOCAL_DIRS")
Utils.scala源码:
/** Get the Yarn approved local directories. */
private def getYarnLocalDirs(conf: SparkConf): String = {
val localDirs = Option(conf.getenv("LOCAL_DIRS")).getOrElse("")
if (localDirs.isEmpty) {
throw new Exception("Yarn Local dirs can't be empty")
}
localDirs
}
那么LOCAL_DIRS的环境变量是什么时候设置的呢?是在Hadoop里先设置好的。
2. 回到Hadoop的源代码,我来看看。ContainerLaunch.call函数
public Integer call() {
...
List<String> localDirs = dirsHandler.getLocalDirs();
...
// /////////// Write out the container-script in the nmPrivate space.
List<Path> appDirs = new ArrayList<Path>(localDirs.size());
for (String localDir : localDirs) {

本文解析了Spark中BlockManager的LOCAL_DIRS配置项,详细介绍了其如何通过Hadoop的配置和资源定位机制来确定BlockManager的本地存储路径。
3827

被折叠的 条评论
为什么被折叠?



