Repository: spark
Updated Branches:
  refs/heads/master fcad3fae6 -> d61f2c15b


[SPARK-3658][SQL] Start thrift server as a daemon

https://issues.apache.org/jira/browse/SPARK-3658

And keep the `CLASS_NOT_FOUND_EXIT_STATUS` and exit message in 
`SparkSubmit.scala`.

Author: WangTaoTheTonic <[email protected]>
Author: WangTao <[email protected]>

Closes #2509 from WangTaoTheTonic/thriftserver and squashes the following 
commits:

5dcaab2 [WangTaoTheTonic] issue about coupling
8ad9f95 [WangTaoTheTonic] generalization
598e21e [WangTao] take thrift server as a daemon


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/d61f2c15
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/d61f2c15
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/d61f2c15

Branch: refs/heads/master
Commit: d61f2c15bb22253bfdda77462b1bd383987d2f5a
Parents: fcad3fa
Author: WangTaoTheTonic <[email protected]>
Authored: Wed Oct 1 15:15:09 2014 -0700
Committer: Michael Armbrust <[email protected]>
Committed: Wed Oct 1 15:15:24 2014 -0700

----------------------------------------------------------------------
 bin/spark-sql                                   | 12 +---------
 .../org/apache/spark/deploy/SparkSubmit.scala   |  4 ++++
 sbin/spark-daemon.sh                            | 16 +++++++++----
 sbin/start-thriftserver.sh                      | 16 ++-----------
 sbin/stop-thriftserver.sh                       | 25 ++++++++++++++++++++
 5 files changed, 43 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/d61f2c15/bin/spark-sql
----------------------------------------------------------------------
diff --git a/bin/spark-sql b/bin/spark-sql
index 9d66140..63d0043 100755
--- a/bin/spark-sql
+++ b/bin/spark-sql
@@ -24,7 +24,6 @@
 set -o posix
 
 CLASS="org.apache.spark.sql.hive.thriftserver.SparkSQLCLIDriver"
-CLASS_NOT_FOUND_EXIT_STATUS=101
 
 # Figure out where Spark is installed
 FWDIR="$(cd "`dirname "$0"`"/..; pwd)"
@@ -53,13 +52,4 @@ source "$FWDIR"/bin/utils.sh
 SUBMIT_USAGE_FUNCTION=usage
 gatherSparkSubmitOpts "$@"
 
-"$FWDIR"/bin/spark-submit --class $CLASS "${SUBMISSION_OPTS[@]}" 
spark-internal "${APPLICATION_OPTS[@]}"
-exit_status=$?
-
-if [[ exit_status -eq CLASS_NOT_FOUND_EXIT_STATUS ]]; then
-  echo
-  echo "Failed to load Spark SQL CLI main class $CLASS."
-  echo "You need to build Spark with -Phive."
-fi
-
-exit $exit_status
+exec "$FWDIR"/bin/spark-submit --class $CLASS "${SUBMISSION_OPTS[@]}" 
spark-internal "${APPLICATION_OPTS[@]}"

http://git-wip-us.apache.org/repos/asf/spark/blob/d61f2c15/core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala 
b/core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala
index 580a439..f97bf67 100644
--- a/core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala
+++ b/core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala
@@ -320,6 +320,10 @@ object SparkSubmit {
     } catch {
       case e: ClassNotFoundException =>
         e.printStackTrace(printStream)
+        if (childMainClass.contains("thriftserver")) {
+          println(s"Failed to load main class $childMainClass.")
+          println("You need to build Spark with -Phive.")
+        }
         System.exit(CLASS_NOT_FOUND_EXIT_STATUS)
     }
 

http://git-wip-us.apache.org/repos/asf/spark/blob/d61f2c15/sbin/spark-daemon.sh
----------------------------------------------------------------------
diff --git a/sbin/spark-daemon.sh b/sbin/spark-daemon.sh
index bd476b4..cba475e 100755
--- a/sbin/spark-daemon.sh
+++ b/sbin/spark-daemon.sh
@@ -62,7 +62,7 @@ then
   shift
 fi
 
-startStop=$1
+option=$1
 shift
 command=$1
 shift
@@ -122,9 +122,9 @@ if [ "$SPARK_NICENESS" = "" ]; then
 fi
 
 
-case $startStop in
+case $option in
 
-  (start)
+  (start|spark-submit)
 
     mkdir -p "$SPARK_PID_DIR"
 
@@ -142,8 +142,14 @@ case $startStop in
 
     spark_rotate_log "$log"
     echo starting $command, logging to $log
-    cd "$SPARK_PREFIX"
-    nohup nice -n $SPARK_NICENESS "$SPARK_PREFIX"/bin/spark-class $command 
"$@" >> "$log" 2>&1 < /dev/null &
+    if [ $option == spark-submit ]; then
+      source "$SPARK_HOME"/bin/utils.sh
+      gatherSparkSubmitOpts "$@"
+      nohup nice -n $SPARK_NICENESS "$SPARK_PREFIX"/bin/spark-submit --class 
$command \
+        "${SUBMISSION_OPTS[@]}" spark-internal "${APPLICATION_OPTS[@]}" >> 
"$log" 2>&1 < /dev/null &
+    else
+      nohup nice -n $SPARK_NICENESS "$SPARK_PREFIX"/bin/spark-class $command 
"$@" >> "$log" 2>&1 < /dev/null &
+    fi
     newpid=$!
     echo $newpid > $pid
     sleep 2

http://git-wip-us.apache.org/repos/asf/spark/blob/d61f2c15/sbin/start-thriftserver.sh
----------------------------------------------------------------------
diff --git a/sbin/start-thriftserver.sh b/sbin/start-thriftserver.sh
index ba953e7..50e8e06 100755
--- a/sbin/start-thriftserver.sh
+++ b/sbin/start-thriftserver.sh
@@ -27,7 +27,6 @@ set -o posix
 FWDIR="$(cd "`dirname "$0"`"/..; pwd)"
 
 CLASS="org.apache.spark.sql.hive.thriftserver.HiveThriftServer2"
-CLASS_NOT_FOUND_EXIT_STATUS=101
 
 function usage {
   echo "Usage: ./sbin/start-thriftserver [options] [thrift server options]"
@@ -49,17 +48,6 @@ if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then
   exit 0
 fi
 
-source "$FWDIR"/bin/utils.sh
-SUBMIT_USAGE_FUNCTION=usage
-gatherSparkSubmitOpts "$@"
+export SUBMIT_USAGE_FUNCTION=usage
 
-"$FWDIR"/bin/spark-submit --class $CLASS "${SUBMISSION_OPTS[@]}" 
spark-internal "${APPLICATION_OPTS[@]}"
-exit_status=$?
-
-if [[ exit_status -eq CLASS_NOT_FOUND_EXIT_STATUS ]]; then
-  echo
-  echo "Failed to load Hive Thrift server main class $CLASS."
-  echo "You need to build Spark with -Phive."
-fi
-
-exit $exit_status
+exec "$FWDIR"/sbin/spark-daemon.sh spark-submit $CLASS 1 "$@"

http://git-wip-us.apache.org/repos/asf/spark/blob/d61f2c15/sbin/stop-thriftserver.sh
----------------------------------------------------------------------
diff --git a/sbin/stop-thriftserver.sh b/sbin/stop-thriftserver.sh
new file mode 100755
index 0000000..4031a00
--- /dev/null
+++ b/sbin/stop-thriftserver.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Stops the thrift server on the machine this script is executed on.
+
+sbin="`dirname "$0"`"
+sbin="`cd "$sbin"; pwd`"
+
+"$sbin"/spark-daemon.sh stop 
org.apache.spark.sql.hive.thriftserver.HiveThriftServer2 1


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to