You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "HyukjinKwon (via GitHub)" <gi...@apache.org> on 2023/02/07 10:31:14 UTC

[GitHub] [spark] HyukjinKwon opened a new pull request, #39928: [WIP][SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

HyukjinKwon opened a new pull request, #39928:
URL: https://github.com/apache/spark/pull/39928

   ### What changes were proposed in this pull request?
   
   This PR proposes to scripts to start and stop the Spark Connect server.
   
   ### Why are the changes needed?
   
   Currently, there is no proper way to start and stop the Spark Connect server. Now it requires you to start it with, for example, a Spark shell:
   
   ```bash
   # For development,
   ./bin/spark-shell \
      --jars `ls connector/connect/target/**/spark-connect*SNAPSHOT.jar` \
     --conf spark.plugins=org.apache.spark.sql.connect.SparkConnectPlugin
   ```
   
   ```bash
   # For released Spark versions
   ./bin/spark-shell \
     --packages org.apache.spark:spark-connect_2.12:3.4.0 \
     --conf spark.plugins=org.apache.spark.sql.connect.SparkConnectPlugin
   ```
   
   which is awkward.
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, it adds new scripts to start and stop Spark Connect server.
   
   ### How was this patch tested?
   
   Manually tested:
   
   ```bash
   sbin/start-connectserver.sh
   ```
   
   ```bash
   bin/pyspark --remote localhost
   ...
   ```
   
   ```bash
   sbin/stop-connectserver.sh
   ps -fe | grep Spark
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #39928:
URL: https://github.com/apache/spark/pull/39928#issuecomment-1421895695

   sure sgtm


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon closed pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server
URL: https://github.com/apache/spark/pull/39928


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39928:
URL: https://github.com/apache/spark/pull/39928#discussion_r1099503676


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectServer.scala:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package org.apache.spark.sql.connect.service
+
+import org.apache.spark.sql.SparkSession
+
+/**
+ * The Spark Connect server
+ */
+object SparkConnectServer {
+  def main(args: Array[String]): Unit = {
+    // Set the active Spark Session, and starts SparkEnv instance (via Spark Context)
+    val session = SparkSession.builder.getOrCreate()
+    try {
+      SparkConnectService.start()

Review Comment:
   Maybe, shall we add `logInfo` before this line?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39928:
URL: https://github.com/apache/spark/pull/39928#discussion_r1099494149


##########
sbin/start-connectserver.sh:
##########
@@ -0,0 +1,38 @@
+#!/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.
+#
+
+# Shell script for starting the Spark Connect server
+if [ -z "${SPARK_HOME}" ]; then
+  export SPARK_HOME="$(cd "`dirname "$0"`"/..; pwd)"
+fi
+
+# NOTE: This exact class name is matched downstream by SparkSubmit.
+# Any changes need to be reflected there.
+CLASS="org.apache.spark.sql.connect.service.SparkConnectServer"
+
+if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then
+  echo "Usage: ./sbin/start-connectserver.sh [options]"
+
+  "${SPARK_HOME}"/bin/spark-submit --help 2>&1 | grep -v Usage 1>&2
+  exit 1
+fi
+
+. "${SPARK_HOME}/bin/load-spark-env.sh"
+
+exec "${SPARK_HOME}/sbin"/spark-daemon.sh submit $CLASS 1 "$@"

Review Comment:
   Shall we quote `SPARK_HOME` only?
   https://github.com/apache/spark/blob/53c1c682acd619c6b3a4beeea53766dda08c7350/sbin/start-thriftserver.sh#L60



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39928:
URL: https://github.com/apache/spark/pull/39928#discussion_r1099505226


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectServer.scala:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package org.apache.spark.sql.connect.service
+
+import org.apache.spark.sql.SparkSession
+
+/**
+ * The Spark Connect server
+ */
+object SparkConnectServer {
+  def main(args: Array[String]): Unit = {
+    // Set the active Spark Session, and starts SparkEnv instance (via Spark Context)
+    val session = SparkSession.builder.getOrCreate()
+    try {
+      SparkConnectService.start()
+      SparkConnectService.server.awaitTermination()
+    } finally {

Review Comment:
   Could you add `catch` statement like the following?
   https://github.com/apache/spark/blob/53c1c682acd619c6b3a4beeea53766dda08c7350/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2.scala#L111-L112



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] pan3793 commented on pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #39928:
URL: https://github.com/apache/spark/pull/39928#issuecomment-1421890023

   Maybe `sbin/start-connect-server.sh`, `sbin/stop-connect-server.sh`?
   
   Currently all scripts under `sbin` use `-` except to `start-thriftserver.sh`, `stop-thriftserver.sh`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #39928:
URL: https://github.com/apache/spark/pull/39928#issuecomment-1428473402

   > it feels a bit odd to me to have a script in the sbin that user has to manually specify the location of the connect jars.
   
   > What is the plan for distribution, are connect jars going to be in the main distribution jars/ directory so it won't be needed at that point?
   
   Yes, the eventual plan is to move the whole connect jars to the main distribution jars/ around the next release (Apache Spark 3.5.0). For now, the Spark connect project is separated into the external project. It is located in `connector/` - that was `external/` before (see also https://github.com/apache/spark/pull/35874, I think actually we might have to revisit the top level name here).
   
   For a bit of more context, there are a couple of plans such as replacing Py4J to Spark Connect (so we can block arbitrary JVM access from Python side for security purpose), and I personally am thinking about replacing Thrift server in the far future (and don't use Hive's Thrift server).
   
   I plan to send another email to explain the whole context in the dev mailing list around .. right after the Spark 3.4 release.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39928:
URL: https://github.com/apache/spark/pull/39928#discussion_r1099492810


##########
sbin/start-connectserver.sh:
##########
@@ -0,0 +1,38 @@
+#!/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.
+#
+

Review Comment:
   Shall we use posix mode like Spark Thrift Server?
   https://github.com/apache/spark/blob/53c1c682acd619c6b3a4beeea53766dda08c7350/sbin/start-thriftserver.sh#L23-L24



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] tgravescs commented on pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "tgravescs (via GitHub)" <gi...@apache.org>.
tgravescs commented on PR #39928:
URL: https://github.com/apache/spark/pull/39928#issuecomment-1428264541

   it feels a bit odd to me to have a script in the sbin that user has to manually specify the location of the connect jars. What is the plan for distribution, are connect jars going to be in the main distribution jars/ directory so it won't be needed at that point?
   I don't think we do that with any of the other connectors but wasn't sure the plan and if it was mostly for initial development.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39928:
URL: https://github.com/apache/spark/pull/39928#discussion_r1099494149


##########
sbin/start-connectserver.sh:
##########
@@ -0,0 +1,38 @@
+#!/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.
+#
+
+# Shell script for starting the Spark Connect server
+if [ -z "${SPARK_HOME}" ]; then
+  export SPARK_HOME="$(cd "`dirname "$0"`"/..; pwd)"
+fi
+
+# NOTE: This exact class name is matched downstream by SparkSubmit.
+# Any changes need to be reflected there.
+CLASS="org.apache.spark.sql.connect.service.SparkConnectServer"
+
+if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then
+  echo "Usage: ./sbin/start-connectserver.sh [options]"
+
+  "${SPARK_HOME}"/bin/spark-submit --help 2>&1 | grep -v Usage 1>&2
+  exit 1
+fi
+
+. "${SPARK_HOME}/bin/load-spark-env.sh"
+
+exec "${SPARK_HOME}/sbin"/spark-daemon.sh submit $CLASS 1 "$@"

Review Comment:
   Shall we quote `SPARK_HOME` only by putting `/sbin` out from the quote?
   https://github.com/apache/spark/blob/53c1c682acd619c6b3a4beeea53766dda08c7350/sbin/start-thriftserver.sh#L60



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39928:
URL: https://github.com/apache/spark/pull/39928#discussion_r1099498122


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectService.scala:
##########
@@ -224,7 +224,7 @@ object SparkConnectService {
   // different or complex type easily.
   private type SessionCacheKey = (String, String)
 
-  private var server: Server = _
+  private[connect] var server: Server = _

Review Comment:
   It's used here.
   https://github.com/apache/spark/blob/ec9b71e2f0e137056951934491883a52a0f22ba8/connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectServer.scala#L31



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] hvanhovell commented on a diff in pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #39928:
URL: https://github.com/apache/spark/pull/39928#discussion_r1099479417


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectService.scala:
##########
@@ -224,7 +224,7 @@ object SparkConnectService {
   // different or complex type easily.
   private type SessionCacheKey = (String, String)
 
-  private var server: Server = _
+  private[connect] var server: Server = _

Review Comment:
   Why do we need to increase the visibility?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #39928: [SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect server

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #39928:
URL: https://github.com/apache/spark/pull/39928#issuecomment-1421896907

   Merged to master and branch-3.4.
   
   Actually CI doesn't verify none of the changes here (except the linter job that passed now).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org