spark-core_01: $SPARK_HOME/bin/spark-shell

29 篇文章 4 订阅

sparkshell脚本的作用:调用spark-submit脚本,并给spark-submit脚本 带上参数如下参数

--classorg.apache.spark.repl.Main --name "Spark shell" "$@"

 具体流程是:

#1 捕获终端信号,执行退出方法,恢复一些操作

#2 保存终端配置,当cygwin时关闭回显,之后再恢复

#3 执行spark-submit,调用repl.Main

#!/usr/bin/envbash

#Shell script for starting the Spark Shell REPL

#先检测系统是否属于cygwin,即是否为windows系统

#-------uname在Centos中是Liunx,使用uname -r 可以查看内核版本; 使用uname -a 可以查看所有的信息

cygwin=false

case"`uname`" in 

  CYGWIN*) cygwin=true;;

esac

 

#Enter posix mode for bash

#-------post设置shell的模式为POSIX标准模式,不同的模式对于一些命令和操作不一样。

set-o posix

#如果没有设置SPARK_HOME,shell会将当前脚本的上一级目录做为spark_home

# -z表示当串长度为0时,条件为真。  而$()和`` 都表示在shell中执行命令同时将结果返回

if [-z "${SPARK_HOME}" ]; then

  export SPARK_HOME="$(cd "`dirname"$0"`"/..; pwd)"

fi

 

export_SPARK_CMD_USAGE="Usage: ./bin/spark-shell [options]"

 

#SPARK-4161: scala does not assume use of the java classpath,

# sowe need to add the "-Dscala.usejavacp=true" flag manually. We

# dothis specifically for the Spark shell because the scala REPL

#has its own class loader, and any additional classpath specified

#through spark.driver.extraClassPath is not automatically propagated.

#这段的意思是因为scala默认不会使用java classpath,因此这里需要手动设置一下,让scala使用java。

SPARK_SUBMIT_OPTS="$SPARK_SUBMIT_OPTS-Dscala.usejavacp=true"


functionmain() {

  if $cygwin; then

    stty -icanon min 1 -echo > /dev/null2>&1

    exportSPARK_SUBMIT_OPTS="$SPARK_SUBMIT_OPTS -Djline.terminal=unix"

    "${SPARK_HOME}"/bin/spark-submit--class org.apache.spark.repl.Main --name "Spark shell""$@"

    stty icanon echo > /dev/null 2>&1

  else

    #如果不是cygwin系统,执行spark_home/bin/spark-submit的脚本,指定--class是org.apache.spark.repl.Main

    #spark_shell 后面通常会跟着--master spark://host:7077

    export SPARK_SUBMIT_OPTS

    "${SPARK_HOME}"/bin/spark-submit--class org.apache.spark.repl.Main --name "Spark shell""$@"

  fi

}

 

#Copy restore-TTY-on-exit functions from Scala script so spark-shell exitsproperly even in

#binary distribution of Spark where Scala is not installed

exit_status=127

saved_stty=""

 

#restore stty settings (echo in particular)

functionrestoreSttySettings() {

  stty $saved_stty

  saved_stty=""

}

 

functiononExit() {

  if [[ "$saved_stty" != ""]]; then

    restoreSttySettings

  fi

  exit $exit_status

}

 

# toreenable echo if we are interrupted before completing.

#这句是说,捕获INT信号,INT表示中断线程或进程,就会回调执行onExit方法。onExit中判断是否恢复终端设置。

traponExit INT

 

#save terminal settings http://www.cnblogs.com/xing901022/p/6415289.html

######改变终端的显示,比如说关闭一些按键,开启一些特殊字符的输入等等。

#----stty-g 表示将当前终端的回显保存起来(stty -g,--save 表示以stty可读的方式打印当前所有设置)

saved_stty=$(stty-g 2>/dev/null)

 

#clear on error so we don't later try to restore them

#-----如果stty -g执行错误,需要将saved_stty设置成空串

if[[ ! $? ]]; then

  saved_stty=""

fi

 

#######此处会将spark-shell后面的所有参数,都给main方法

main"$@"

######################################################

#运行test.sh 1 2 3后

#"$*"的意思为"1 2 3"(一起被引号包住)

#"$@"为"1""2" "3"(分别被包住,好处就是传给main方法就不用再做切分了)

#$#:表示脚本参数个数

######################################################

#record the exit status lest it be overwritten:

#then reenable echo and propagate the code.

exit_status=$?

onExit 

下面分析一下%spark_home/bin/spark-submit脚本

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值