spark任务在执行期间,有时候会遇到临时目录创建失败,导致任务执行错误。
java.io.IOException: Failed to create local dir in ……
spark执行过程的文件夹
- spark创建临时文件机制
spark作为并行计算框架,同一个作业会被划分为多个任务在多个节点执行,reduce的输入可能存在于多个节点,因此需要shuffle将所有reduce的输入汇总起来;而shuffle时需要通过diskBlockManage将map结果写入本地,优先写入memory store,在memore store空间不足时会创建临时文件。 - 临时文件夹配置
memory store的大小取决于spark.excutor.memory参数,默认为spark.excutor.memory*0.6;可通过spark.env中添加配置SPARK_LOCAL_DIRS或程序中设定spark.local.dir,可配置多个路径,逗号分隔增强io效率。
SPARK_LOCAL_DIRS:
Directory to use for "scratch" space in Spark, including map output files and RDDs that get stored on disk.
This should be on a fast, local disk in your system.
It can also be a comma-separated list of multiple directories on different disks.