Spark 源码浅读-任务提交SparkSubmit

main方法

main方法主要用于初始化日志,然后接着调用doSubmit方法。

override def main(args: Array[String]): Unit = {
/*
初始化日志
*/
val submit = new SparkSubmit() {
self => override protected def parseArguments(args: Array[String]): SparkSubmitArguments = {
new SparkSubmitArguments(args) {
override protected def logInfo(msg: => String): Unit = self.logInfo(msg) override protected def logWarning(msg: => String): Unit = self.logWarning(msg) .......   /**
*
*提交任务
*/ submit.doSubmit(args)
}

  doSubmit方法

def doSubmit(args: Array[String]): Unit = {
// Initialize logging if it hasn't been done yet. Keep track of whether logging needs to
// be reset before the application starts.
val uninitLog = initializeLogIfNecessary(true, silent = true) val appArgs = parseArguments(args)
if (appArgs.verbose) {
logInfo(appArgs.toString)
}
appArgs.action match {
case SparkSubmitAction.SUBMIT => submit(appArgs, uninitLog)
case SparkSubmitAction.KILL => kill(appArgs)
case SparkSubmitAction.REQUEST_STATUS => requestStatus(appArgs)
case SparkSubmitAction.PRINT_VERSION => printVersion()
}
}

  doSubmit方法最终会调用runMain方法

private def runMain(args: SparkSubmitArguments, uninitLog: Boolean): Unit = {
/*
childArgs包含任务设置的各项参数 以及mainClass等
childMainClass 为下图 STANDALONE_CLUSTER_SUBMIT_CLASS
创建Driver 和Master通信
*/
val (childArgs, childClasspath, sparkConf, childMainClass) = prepareSubmitEnvironment(args)
// Let the main class re-initialize the logging system once it starts.
if (uninitLog) {
Logging.uninitialize()
} if (args.verbose) {
logInfo(s"Main class:\n$childMainClass")
logInfo(s"Arguments:\n${childArgs.mkString("\n")}")
// sysProps may contain sensitive information, so redact before printing
logInfo(s"Spark config:\n${Utils.redact(sparkConf.getAll.toMap).mkString("\n")}")
logInfo(s"Classpath elements:\n${childClasspath.mkString("\n")}")
logInfo("\n")
}
val loader = getSubmitClassLoader(sparkConf)
for (jar <- childClasspath) {
addJarToClasspath(jar, loader)
} var mainClass: Class[_] = null try {
mainClass = Utils.classForName(childMainClass)
} catch {
case e: ClassNotFoundException =>
logError(s"Failed to load class $childMainClass.")
if (childMainClass.contains("thriftserver")) {
logInfo(s"Failed to load main class $childMainClass.")
logInfo("You need to build Spark with -Phive and -Phive-thriftserver.")
}
throw new SparkUserAppException(CLASS_NOT_FOUND_EXIT_STATUS)
case e: NoClassDefFoundError =>
logError(s"Failed to load $childMainClass: ${e.getMessage()}")
if (e.getMessage.contains("org/apache/hadoop/hive")) {
logInfo(s"Failed to load hive class.")
logInfo("You need to build Spark with -Phive and -Phive-thriftserver.")
}
throw new SparkUserAppException(CLASS_NOT_FOUND_EXIT_STATUS)
}

  

Spark 源码浅读-SparkSubmit的更多相关文章

  1. Spark源码分析之Spark-submit和Spark-class

    有了前面spark-shell的经验,看这两个脚本就容易多啦.前面总结的Spark-shell的分析可以参考: Spark源码分析之Spark Shell(上) Spark源码分析之Spark She ...

  2. Handlebars模板引擎中的each嵌套及源码浅读

    若显示效果不佳,可移步到愚安的小窝 Handlebars模板引擎作为时下最流行的模板引擎之一,已然在开发中为我们提供了无数便利.作为一款无语义的模板引擎,Handlebars只提供极少的helper函 ...

  3. MyBatis 之源码浅读

    环境简介与入口 记录一下尝试阅读Mybatis源码的过程,这篇笔记是我一边读,一遍记录下来的,虽然内容也不多,对Mybatis整体的架构体系也没有摸的很清楚,起码也能把这个过程整理下来,这也是我比较喜 ...

  4. Java集合&Spring源码浅读

    记录自己现在知道的,以后了解了更多的话,再继续补上来 Java集合类 Collection 接口 说明:是List,set 的父类.定义了集合初始模样.集合只存储对象. Jdk8文档,内部方法定义有: ...

  5. Layui 源码浅读(模块加载原理)

    经典开场 // Layui ;! function (win) { var Lay = function () { this.v = '2.5.5'; }; win.layui = new Lay() ...

  6. Spark源码分析之Spark Shell(上)

    终于开始看Spark源码了,先从最常用的spark-shell脚本开始吧.不要觉得一个启动脚本有什么东东,其实里面还是有很多知识点的.另外,从启动脚本入手,是寻找代码入口最简单的方法,很多开源框架,其 ...

  7. Spark源码分析之Spark Shell(下)

    继上次的Spark-shell脚本源码分析,还剩下后面半段.由于上次涉及了不少shell的基本内容,因此就把trap和stty放在这篇来讲述. 上篇回顾:Spark源码分析之Spark Shell(上 ...

  8. spark源码分析以及优化

    第一章.spark源码分析之RDD四种依赖关系 一.RDD四种依赖关系 RDD四种依赖关系,分别是 ShuffleDependency.PrunDependency.RangeDependency和O ...

  9. Apache Spark源码剖析

    Apache Spark源码剖析(全面系统介绍Spark源码,提供分析源码的实用技巧和合理的阅读顺序,充分了解Spark的设计思想和运行机理) 许鹏 著   ISBN 978-7-121-25420- ...

随机推荐

  1. SAP PI接口ESR IA配置,几种常用的 XSL 转换文档模板

    在PI开发配置中字段映射一般分为Message Mapping(MM)和Imported Archives(IA)这两种形式.MM这种拉线的形式虽然看似方便,但是当接口更新和传输时往往比较麻烦,同时无 ...

  2. 类虚拟机软件CrossOver是什么?它的优势在哪里?

    虚拟机软件对于很多人来说已经不是一个陌生的词汇了.我们可以通过软件来模拟具有完整硬件系统功能的计算机系统.比如我们可以在Mac OS系统上模拟Windows 7 的系统,以此来安装我们想要使用的应用程 ...

  3. 2020 CSP-J 多校赛 Day 2 T2 题解

    0x01 引入 在考场时想了一个错误算法,口胡一下,或许对理解正解有点帮助. 我们考虑交换两个数产生的代价,你会发现我们需要让大的数重复被交换的次数尽可能少,减少它对后面的代价. 那么不难构思出一个按 ...

  4. P2943 [USACO09MAR]Cleaning Up G

    一句话题意:将一个数列分成若干段,每段的不和谐度为该段内不同数字数量的平方,求不和谐度之和的最小值. 令 \(f_i\) 表示前 \(i\) 个数的最小答案,很容易就能写出暴力转移方程:\(f_i=\ ...

  5. AtCoder Beginner Contest 178 E - Dist Max 题解(推公式)

    题目链接 题目大意 给你n个点(n<=2e5)要你求所有点中两个点最短的曼哈顿距离 曼哈顿距离定义为d(i,j)=|x1-x2|+|y1-y2|. 题目思路 想了很久也没有什么思路,其实就是一个 ...

  6. 课时一:JS操作数据

    课时一:JS操作数据 JSAPI请求头 xmlhttp.setRequestHeader("Content-Type", "application/json; chars ...

  7. 区块链V1版本实现之二

    部分程序代码(生成并调用hash代码): 1 //创建区块,对Block的每一个字段填充数据 2 func NewBlock(data string, prevBlockHash []byte) *B ...

  8. java42

    1.Random类 随机生成某个整数 Random r = new Random(); System.out.println(r.nextInt()); 伪随机数:第一次打印为随机,再次运行,数字将保 ...

  9. Django 在test.py 中测试文件的配置

    import os import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTING ...

  10. 【VSA】One-shot video-based person re-identification with variance subsampling algorithm

    目录 解决了什么问题 主要贡献和创新点 基本框架 提出的方法 01 variance confidence方差置信度 02 Variance Subsampling Algorithm 方差二次采样算 ...