我的sparkDF.persist(DISK_ONLY)数据存储在哪里?

时间:2018-01-24 19:37:57

标签: hadoop apache-spark persist

我想更多地了解hadoop的火花持久策略。

当我使用DISK_ONLY策略持有数据帧时,我的数据存储在哪里(路径/文件夹...)?我在哪里指定这个位置?

2 个答案:

答案 0 :(得分:5)

对于简短的回答,我们可以查看关于spark.local.dir的{​​{3}}:

  

用于" scratch"的目录Spark中的空间,包括映射输出文件和存储在磁盘上的RDD。这应该位于系统中的快速本地磁盘上。它也可以是不同磁盘上多个目录的逗号分隔列表。注意:在Spark 1.0及更高版本中,这将由集群管理器设置的SPARK_LOCAL_DIRS(Standalone,Mesos)或LOCAL_DIRS(YARN)环境变量覆盖。

为了更深入地理解,我们可以查看代码:DataFrame(只是Dataset[Row])基于the documentation并且它利用相同的持久性机制。 RDD将此代理委托给RDD,后者将其标记为持久性。然后,SparkContext包中的几个类实际上处理了该任务:首先,org.apache.spark.storage只管理要保留的数据块以及如何执行该策略的策略,将实际持久性委派给a BlockManager(当然在磁盘上写时)代表了一个高级别的写入界面,而后者又有一个DiskStore用于更低级别的操作。

希望您了解现在的位置,以便我们继续前进并了解数据实际持久的位置以及我们如何配置它:DiskBlockManager调用助手DiskBlockManager ,为了实用性我将在这里复制(取自链接的2.2.1版本,在撰写本文时的最新版本):

def getConfiguredLocalDirs(conf: SparkConf): Array[String] = {
    val shuffleServiceEnabled = conf.getBoolean("spark.shuffle.service.enabled", false)
    if (isRunningInYarnContainer(conf)) {
        // If we are in yarn mode, systems can have different disk layouts so we must set it
        // to what Yarn on this system said was available. Note this assumes that Yarn has
        // created the directories already, and that they are secured so that only the
        // user has access to them.
        getYarnLocalDirs(conf).split(",")
    } else if (conf.getenv("SPARK_EXECUTOR_DIRS") != null) {
        conf.getenv("SPARK_EXECUTOR_DIRS").split(File.pathSeparator)
    } else if (conf.getenv("SPARK_LOCAL_DIRS") != null) {
        conf.getenv("SPARK_LOCAL_DIRS").split(",")
    } else if (conf.getenv("MESOS_DIRECTORY") != null && !shuffleServiceEnabled) {
        // Mesos already creates a directory per Mesos task. Spark should use that directory
        // instead so all temporary files are automatically cleaned up when the Mesos task ends.
        // Note that we don't want this if the shuffle service is enabled because we want to
        // continue to serve shuffle files after the executors that wrote them have already exited.
        Array(conf.getenv("MESOS_DIRECTORY"))
    } else {
        if (conf.getenv("MESOS_DIRECTORY") != null && shuffleServiceEnabled) {
        logInfo("MESOS_DIRECTORY available but not using provided Mesos sandbox because " +
            "spark.shuffle.service.enabled is enabled.")
        }
        // In non-Yarn mode (or for the driver in yarn-client mode), we cannot trust the user
        // configuration to point to a secure directory. So create a subdirectory with restricted
        // permissions under each listed directory.
        conf.get("spark.local.dir", System.getProperty("java.io.tmpdir")).split(",")
    }
}

我认为代码非常不言自明,评论很好(并且完全符合文档的内容):在Yarn上运行时,有一个特定的策略依赖于Yarn容器的存储,在Mesos中它要么使用Mesos沙箱(除非启用了随机服务),在所有其他情况下,它将转到spark.local.dir下或java.io.tmpdir下设置的位置(可能是/tmp/)。

因此,如果您只是在玩数据很可能存储在/tmp/下,否则它很大程度上取决于您的环境和配置。

答案 1 :(得分:2)

总结我的YARN环境:

在@stefanobaghino的指导下,我可以在加载纱线配置的代码中更进一步。

val localDirs = Option(conf.getenv("LOCAL_DIRS")).getOrElse("")

yarn-default.xml

中的 yarn.nodemanager.local-dirs 选项中设置

我的问题的背景是由错误引起的

2018-01-23 16:57:35,229 WARN org.apache.hadoop.yarn.server.nodemanager.DirectoryCollection: Directory /data/1/yarn/local error, used space above threshold of 98.5%, removing from list of valid directories

我的火花工作有时会被杀死我想知道这个磁盘在运行作业时是否也用于我的持久数据(这实际上是一个很大的数量)。

事实证明,这正是使用DISK策略保存数据时数据所在的文件夹。

非常感谢您在此问题上提供的所有有用指导!

相关问题