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

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腳本

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章