Skip to content

Conversation

@sarutak
Copy link
Member

@sarutak sarutak commented Jul 26, 2019

Launcher is implemented as a Java application and sometimes I'd like to apply Java options.
One situation I have met is the time I try to attach debugger to Launcher.

Launcher is launched from bin/spark-class but there is no room to apply Java options.

build_command() {
  "$RUNNER" -Xmx128m -cp "$LAUNCH_CLASSPATH" org.apache.spark.launcher.Main "$@"
  printf "%d\0" $?
}

Considering that it's not so many times to apply Java options to Launcher, one compromise would just modify spark-class by user like as follows.

build_command() {
  "$RUNNER" -Xmx128m $SPARK_LAUNCHER_OPTS -cp "$LAUNCH_CLASSPATH" org.apache.spark.launcher.Main "$@"
  printf "%d\0" $?
}

But it doesn't work when any text related to Java options is output to standard output because whole output is used as command-string for spark-shell and spark-submit in current implementation.

One example is jdwp. When apply agentlib option to use jdwp for debug, we will get output like as follows.

Listening for transport dt_socket at address: 9876

The output shown above is not a command-string so spark-submit and spark-shell will fail.
To enable Java options for Launcher, we need treat command-string and others.

I changed launcher/Main.java and bin/spark-class to print separator-character and treat it.

How was this patch tested?

Tested manually using Spark Shell with / without LAUNCHER_JAVA_OPTIONS like as follows.

SPARK_LAUNCHER_OPTS="-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:9876,server=y" bin/spark-shell

@SparkQA
Copy link

SparkQA commented Jul 26, 2019

Test build #108234 has finished for PR 25265 at commit bafd2a6.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jul 27, 2019

Test build #108250 has finished for PR 25265 at commit 9e8a06a.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sarutak
Copy link
Member Author

sarutak commented Jul 27, 2019

retest this please.

@SparkQA
Copy link

SparkQA commented Jul 27, 2019

Test build #108252 has finished for PR 25265 at commit 9e8a06a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@xuanyuanking
Copy link
Member

Is the SPARK_SUBMIT_OPTS parameter cover your requirement?

@sarutak
Copy link
Member Author

sarutak commented Jul 29, 2019

@xuanyuanking Launcher and SparkSubmit run on different JVM processes so we can't use SPARK_SUBMIT_OPTS for this purpose.

bin/spark-class Outdated
CMD+=("$ARG")
DELIM=$'\n'
while IFS= read -d "$DELIM" -r ARG; do
if [ -n "$CMD_START_FLAG" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to initialize CMD_START_FLAG to an empty string before the loop.

Or you could use DELIM for the same effect.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll initialize the flag.

@kiszk
Copy link
Member

kiszk commented Jul 29, 2019

Do we want to update configuration.md?

@sarutak
Copy link
Member Author

sarutak commented Jul 30, 2019

@kiszk I think this environment variable is for developers so how about update spark-env.sh.template rather?

@SparkQA
Copy link

SparkQA commented Jul 30, 2019

Test build #108364 has finished for PR 25265 at commit f151fbf.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sarutak
Copy link
Member Author

sarutak commented Jul 30, 2019

retest this please.

@SparkQA
Copy link

SparkQA commented Jul 30, 2019

Test build #108369 has finished for PR 25265 at commit f151fbf.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sarutak
Copy link
Member Author

sarutak commented Jul 30, 2019

retest this please.

@SparkQA
Copy link

SparkQA commented Jul 30, 2019

Test build #108372 has finished for PR 25265 at commit f151fbf.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sarutak
Copy link
Member Author

sarutak commented Jul 30, 2019

Lots of flaky tests...

@sarutak
Copy link
Member Author

sarutak commented Jul 30, 2019

retest this please.

@SparkQA
Copy link

SparkQA commented Jul 30, 2019

Test build #108383 has finished for PR 25265 at commit f151fbf.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor

vanzin commented Jul 30, 2019

Merging to master. (Hopefully nobody will ask for this on Windows...)

@vanzin vanzin closed this in 121f933 Jul 30, 2019
@maropu
Copy link
Member

maropu commented Jul 31, 2019

I fetched this commit and my spark-shell seemed to be broken... do I miss something?

(py27) maropu@~/Repositories/spark/spark-master: (master $%>)$./bin/spark-shell
NOTE: SPARK_PREPEND_CLASSES is set, placing locally compiled Spark classes ahead of assembly.
/Users/maropu/Repositories/spark/spark-master/bin/spark-class: line 96: CMD: bad array subscript
head: illegal line count -- -1

@kiszk
Copy link
Member

kiszk commented Jul 31, 2019

In my environment (Ubuntu 18.04), it works well.

$ /usr/bin/env bash --version
GNU bash, version 4.4.19(1)-release (powerpc64le-unknown-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ git log | head -1
commit dba4375359a2dfed1f009edc3b1bcf6b3253fe02
$ ./bin/spark-shell 
19/07/31 13:01:44 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
Spark context Web UI available at http://foo.trl.ibm.com:4040
Spark context available as 'sc' (master = local[*], app id = local-1564545717751).
Spark session available as 'spark'.
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 3.0.0-SNAPSHOT
      /_/
         
Using Scala version 2.12.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_212)
Type in expressions to have them evaluated.
Type :help for more information.

scala>

@maropu
Copy link
Member

maropu commented Jul 31, 2019

oh, I see. I'll check again later, thx!

@maropu
Copy link
Member

maropu commented Jul 31, 2019

It seems my bash is too old;

$bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.

@sarutak
Copy link
Member Author

sarutak commented Jul 31, 2019

It's strange. I use bash of same version for you.

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)
Copyright (C) 2007 Free Software Foundation, Inc.

But the version of macOS is different. Is this the cause?

@vanzin
Copy link
Contributor

vanzin commented Jul 31, 2019

/Users/maropu/Repositories/spark/spark-master/bin/spark-class: line 96: CMD: bad array subscript

That's also interesting because that line hasn't changed.

@vanzin
Copy link
Contributor

vanzin commented Jul 31, 2019

Takeshi, I can see that happening if you have the new script with an old build of the launcher jar. Otherwise, the logic seems right (and works for me).

@maropu
Copy link
Member

maropu commented Aug 1, 2019

That's it! You're right; I rebuilt the package, then the problem has gone. Thx!

@alfozan
Copy link

alfozan commented Oct 25, 2019

I also had the same issue as @maropu

/Users/maropu/Repositories/spark/spark-master/bin/spark-class: line 96: CMD: bad array subscript

Solution: rebuild

 ./build/mvn -Phive -Phive-thriftserver -DskipTests clean package

@jahidhasanlinix
Copy link

I have this problem when trying to run spark shell, my java env path seems ok, but its still giving me this error>:
echo $JAVA_HOME
/usr/bin/java:/usr/lib/jvm/java-11-openjdk-amd64

Here's the error while trying to run the shell
#./spark-shell
/usr/local/spark/spark-3.2.0-bin-hadoop3.2/bin/spark-class: line 71: /usr/bin/java:/usr/lib/jvm/java-11-openjdk-amd64/bin/java: No such file or directory
/usr/local/spark/spark-3.2.0-bin-hadoop3.2/bin/spark-class: line 96: CMD: bad array subscript

@sarutak
Copy link
Member Author

sarutak commented Nov 25, 2021

@jahidhasanlinix
Maybe, your JAVA_HOME is wrong.
Please set /usr/lib/jvm/java-11-openjdk-amd64 to JAVA_HOME.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants