分析 在 YARN 模式下的 Spark 里 BlockManager 的 LOCAL_DIRS

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

一、前言

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) {
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值