|
17 | 17 | # limitations under the License. |
18 | 18 | # |
19 | 19 |
|
| 20 | +# NOTE: Any changes to this file must be reflected in SparkSubmitDriverBootstrapper.scala! |
| 21 | + |
20 | 22 | cygwin=false |
21 | 23 | case "`uname`" in |
22 | 24 | CYGWIN*) cygwin=true;; |
|
39 | 41 |
|
40 | 42 | if [ -n "$SPARK_MEM" ]; then |
41 | 43 | echo -e "Warning: SPARK_MEM is deprecated, please use a more specific config option" 1>&2 |
42 | | - echo -e "(e.g., spark.executor.memory or SPARK_DRIVER_MEMORY)." 1>&2 |
| 44 | + echo -e "(e.g., spark.executor.memory or spark.driver.memory)." 1>&2 |
43 | 45 | fi |
44 | 46 |
|
45 | 47 | # Use SPARK_MEM or 512m as the default memory, to be overridden by specific options |
@@ -73,11 +75,17 @@ case "$1" in |
73 | 75 | OUR_JAVA_MEM=${SPARK_EXECUTOR_MEMORY:-$DEFAULT_MEM} |
74 | 76 | ;; |
75 | 77 |
|
76 | | - # Spark submit uses SPARK_SUBMIT_OPTS and SPARK_JAVA_OPTS |
77 | | - 'org.apache.spark.deploy.SparkSubmit') |
78 | | - OUR_JAVA_OPTS="$SPARK_JAVA_OPTS $SPARK_SUBMIT_OPTS \ |
79 | | - -Djava.library.path=$SPARK_SUBMIT_LIBRARY_PATH" |
| 78 | + # Spark submit uses SPARK_JAVA_OPTS + SPARK_SUBMIT_OPTS + |
| 79 | + # SPARK_DRIVER_MEMORY + SPARK_SUBMIT_DRIVER_MEMORY. |
| 80 | + 'org.apache.spark.deploy.SparkSubmit') |
| 81 | + OUR_JAVA_OPTS="$SPARK_JAVA_OPTS $SPARK_SUBMIT_OPTS" |
80 | 82 | OUR_JAVA_MEM=${SPARK_DRIVER_MEMORY:-$DEFAULT_MEM} |
| 83 | + if [ -n "$SPARK_SUBMIT_LIBRARY_PATH" ]; then |
| 84 | + OUR_JAVA_OPTS="$OUR_JAVA_OPTS -Djava.library.path=$SPARK_SUBMIT_LIBRARY_PATH" |
| 85 | + fi |
| 86 | + if [ -n "$SPARK_SUBMIT_DRIVER_MEMORY" ]; then |
| 87 | + OUR_JAVA_MEM="$SPARK_SUBMIT_DRIVER_MEMORY" |
| 88 | + fi |
81 | 89 | ;; |
82 | 90 |
|
83 | 91 | *) |
|
101 | 109 | # Set JAVA_OPTS to be able to load native libraries and to set heap size |
102 | 110 | JAVA_OPTS="-XX:MaxPermSize=128m $OUR_JAVA_OPTS" |
103 | 111 | JAVA_OPTS="$JAVA_OPTS -Xms$OUR_JAVA_MEM -Xmx$OUR_JAVA_MEM" |
| 112 | + |
104 | 113 | # Load extra JAVA_OPTS from conf/java-opts, if it exists |
105 | 114 | if [ -e "$FWDIR/conf/java-opts" ] ; then |
106 | 115 | JAVA_OPTS="$JAVA_OPTS `cat $FWDIR/conf/java-opts`" |
107 | 116 | fi |
108 | | -export JAVA_OPTS |
| 117 | + |
109 | 118 | # Attention: when changing the way the JAVA_OPTS are assembled, the change must be reflected in CommandUtils.scala! |
110 | 119 |
|
111 | 120 | TOOLS_DIR="$FWDIR"/tools |
@@ -146,10 +155,28 @@ if $cygwin; then |
146 | 155 | fi |
147 | 156 | export CLASSPATH |
148 | 157 |
|
149 | | -if [ "$SPARK_PRINT_LAUNCH_COMMAND" == "1" ]; then |
150 | | - echo -n "Spark Command: " 1>&2 |
151 | | - echo "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@" 1>&2 |
152 | | - echo -e "========================================\n" 1>&2 |
| 158 | +# In Spark submit client mode, the driver is launched in the same JVM as Spark submit itself. |
| 159 | +# Here we must parse the properties file for relevant "spark.driver.*" configs before launching |
| 160 | +# the driver JVM itself. Instead of handling this complexity in Bash, we launch a separate JVM |
| 161 | +# to prepare the launch environment of this driver JVM. |
| 162 | + |
| 163 | +if [ -n "$SPARK_SUBMIT_BOOTSTRAP_DRIVER" ]; then |
| 164 | + # This is used only if the properties file actually contains these special configs |
| 165 | + # Export the environment variables needed by SparkSubmitDriverBootstrapper |
| 166 | + export RUNNER |
| 167 | + export CLASSPATH |
| 168 | + export JAVA_OPTS |
| 169 | + export OUR_JAVA_MEM |
| 170 | + export SPARK_CLASS=1 |
| 171 | + shift # Ignore main class (org.apache.spark.deploy.SparkSubmit) and use our own |
| 172 | + exec "$RUNNER" org.apache.spark.deploy.SparkSubmitDriverBootstrapper "$@" |
| 173 | +else |
| 174 | + # Note: The format of this command is closely echoed in SparkSubmitDriverBootstrapper.scala |
| 175 | + if [ -n "$SPARK_PRINT_LAUNCH_COMMAND" ]; then |
| 176 | + echo -n "Spark Command: " 1>&2 |
| 177 | + echo "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@" 1>&2 |
| 178 | + echo -e "========================================\n" 1>&2 |
| 179 | + fi |
| 180 | + exec "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@" |
153 | 181 | fi |
154 | 182 |
|
155 | | -exec "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@" |
|
0 commit comments