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/11/23 01:25:44 UTC
[PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
HyukjinKwon opened a new pull request, #43965:
URL: https://github.com/apache/spark/pull/43965
### What changes were proposed in this pull request?
This PR adds the same test `ReleaseSession releases all queries and does not allow more requests in the session` added in SPARK-45798, to PySpark side.
### Why are the changes needed?
To identify an issue such as SPARK-46042.
_To clarify, Python side does not have the behaviour of sending a request early when you create an generator of the response_
This is caused by [SPARK-46039](https://issues.apache.org/jira/browse/SPARK-46039)
### Does this PR introduce _any_ user-facing change?
No, test-only. It includes a bit of bug fixes but they are pretty trivial and minor.
### How was this patch tested?
Unittests added.
### Was this patch authored or co-authored using generative AI tooling?
No.
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43965:
URL: https://github.com/apache/spark/pull/43965#discussion_r1402844776
##########
python/pyspark/sql/tests/connect/client/test_reattach.py:
##########
@@ -0,0 +1,124 @@
+#
+# 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.
+#
+
+import os
+import unittest
+
+from pyspark.sql import SparkSession as PySparkSession
+from pyspark.testing.connectutils import ReusedConnectTestCase
+from pyspark.testing.pandasutils import PandasOnSparkTestUtils
+from pyspark.testing.sqlutils import SQLTestUtils
+from pyspark.testing.utils import eventually
+
+
+class SparkConnectReattachTestCase(ReusedConnectTestCase, SQLTestUtils, PandasOnSparkTestUtils):
+ @classmethod
+ def setUpClass(cls):
+ super(SparkConnectReattachTestCase, cls).setUpClass()
+ # Disable the shared namespace so pyspark.sql.functions, etc point the regular
+ # PySpark libraries.
+ os.environ["PYSPARK_NO_NAMESPACE_SHARE"] = "1"
+
+ cls.connect = cls.spark # Switch Spark Connect session and regular PySpark session.
+ cls.spark = PySparkSession._instantiatedSession
+ assert cls.spark is not None
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ # Stopping Spark Connect closes the session in JVM at the server.
+ cls.spark = cls.connect
+ del os.environ["PYSPARK_NO_NAMESPACE_SHARE"]
+ finally:
+ super(SparkConnectReattachTestCase, cls).tearDownClass()
+
+ def test_release_sessions(self):
+ big_enough_query = "select * from range(1000000)"
+ query1 = self.connect.sql(big_enough_query).toLocalIterator()
+ query2 = self.connect.sql(big_enough_query).toLocalIterator()
+ query3 = self.connect.sql("select 1").toLocalIterator()
+
+ next(query1)
+ next(query2)
+
+ jvm = PySparkSession._instantiatedSession._jvm # type: ignore[union-attr]
+ service = getattr(
+ getattr(
+ jvm.org.apache.spark.sql.connect.service, # type: ignore[union-attr]
+ "SparkConnectService$",
+ ),
+ "MODULE$",
+ )
+
+ @eventually(catch_assertions=True)
+ def wait_for_requests():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 2)
+
+ wait_for_requests()
+
+ # Close session
+ self.connect.client.release_session()
+ # Calling release session again should be a no-op.
+ self.connect.client.release_session()
+
+ @eventually(catch_assertions=True)
+ def wait_for_responses():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 0)
+
+ wait_for_responses()
+
+ # query1 and query2 could get either an:
+ # OPERATION_CANCELED if it happens fast - when closing the session interrupted the queries,
+ # and that error got pushed to the client buffers before the client got disconnected.
+ # OPERATION_ABANDONED if it happens slow - when closing the session interrupted the client
+ # RPCs before it pushed out the error above. The client would then get an
+ # INVALID_CURSOR.DISCONNECTED, which it will retry with a ReattachExecute, and then get an
+ # INVALID_HANDLE.OPERATION_ABANDONED.
+
+ def check_error(q):
+ try:
+ list(q) # Iterate all.
+ except Exception as e: # noqa: F841
+ return e
+
+ e = check_error(query1)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+ e = check_error(query2)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+
+ # query3 has not been submitted before, so it should now fail with SESSION_CLOSED
+ e = check_error(query3)
Review Comment:
We did at https://github.com/apache/spark/commit/9c291e1165c145104becf69ecafcdba2914c29f1. That was because of the behaviour difference between Java and Python gRPC libraries:
- Java gRPC sends an early request when opening a response stream from a request (https://github.com/grpc/grpc-java/issues/10697)
- Python gRPC does not send an request when opening a response stream (generator).
So I preserved the old test case here.
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #43965:
URL: https://github.com/apache/spark/pull/43965#discussion_r1402843819
##########
python/pyspark/sql/tests/connect/client/test_reattach.py:
##########
@@ -0,0 +1,124 @@
+#
+# 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.
+#
+
+import os
+import unittest
+
+from pyspark.sql import SparkSession as PySparkSession
+from pyspark.testing.connectutils import ReusedConnectTestCase
+from pyspark.testing.pandasutils import PandasOnSparkTestUtils
+from pyspark.testing.sqlutils import SQLTestUtils
+from pyspark.testing.utils import eventually
+
+
+class SparkConnectReattachTestCase(ReusedConnectTestCase, SQLTestUtils, PandasOnSparkTestUtils):
+ @classmethod
+ def setUpClass(cls):
+ super(SparkConnectReattachTestCase, cls).setUpClass()
+ # Disable the shared namespace so pyspark.sql.functions, etc point the regular
+ # PySpark libraries.
+ os.environ["PYSPARK_NO_NAMESPACE_SHARE"] = "1"
+
+ cls.connect = cls.spark # Switch Spark Connect session and regular PySpark session.
+ cls.spark = PySparkSession._instantiatedSession
+ assert cls.spark is not None
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ # Stopping Spark Connect closes the session in JVM at the server.
+ cls.spark = cls.connect
+ del os.environ["PYSPARK_NO_NAMESPACE_SHARE"]
+ finally:
+ super(SparkConnectReattachTestCase, cls).tearDownClass()
+
+ def test_release_sessions(self):
+ big_enough_query = "select * from range(1000000)"
+ query1 = self.connect.sql(big_enough_query).toLocalIterator()
+ query2 = self.connect.sql(big_enough_query).toLocalIterator()
+ query3 = self.connect.sql("select 1").toLocalIterator()
+
+ next(query1)
+ next(query2)
+
+ jvm = PySparkSession._instantiatedSession._jvm # type: ignore[union-attr]
+ service = getattr(
+ getattr(
+ jvm.org.apache.spark.sql.connect.service, # type: ignore[union-attr]
+ "SparkConnectService$",
+ ),
+ "MODULE$",
+ )
+
+ @eventually(catch_assertions=True)
+ def wait_for_requests():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 2)
+
+ wait_for_requests()
+
+ # Close session
+ self.connect.client.release_session()
+ # Calling release session again should be a no-op.
+ self.connect.client.release_session()
+
+ @eventually(catch_assertions=True)
+ def wait_for_responses():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 0)
+
+ wait_for_responses()
+
+ # query1 and query2 could get either an:
+ # OPERATION_CANCELED if it happens fast - when closing the session interrupted the queries,
+ # and that error got pushed to the client buffers before the client got disconnected.
+ # OPERATION_ABANDONED if it happens slow - when closing the session interrupted the client
+ # RPCs before it pushed out the error above. The client would then get an
+ # INVALID_CURSOR.DISCONNECTED, which it will retry with a ReattachExecute, and then get an
+ # INVALID_HANDLE.OPERATION_ABANDONED.
+
+ def check_error(q):
+ try:
+ list(q) # Iterate all.
+ except Exception as e: # noqa: F841
+ return e
+
+ e = check_error(query1)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+ e = check_error(query2)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+
+ # query3 has not been submitted before, so it should now fail with SESSION_CLOSED
+ e = check_error(query3)
Review Comment:
We deleted `query3`, didn't we?
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #43965:
URL: https://github.com/apache/spark/pull/43965#issuecomment-1823785056
Merged to master.
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43965:
URL: https://github.com/apache/spark/pull/43965#discussion_r1402844776
##########
python/pyspark/sql/tests/connect/client/test_reattach.py:
##########
@@ -0,0 +1,124 @@
+#
+# 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.
+#
+
+import os
+import unittest
+
+from pyspark.sql import SparkSession as PySparkSession
+from pyspark.testing.connectutils import ReusedConnectTestCase
+from pyspark.testing.pandasutils import PandasOnSparkTestUtils
+from pyspark.testing.sqlutils import SQLTestUtils
+from pyspark.testing.utils import eventually
+
+
+class SparkConnectReattachTestCase(ReusedConnectTestCase, SQLTestUtils, PandasOnSparkTestUtils):
+ @classmethod
+ def setUpClass(cls):
+ super(SparkConnectReattachTestCase, cls).setUpClass()
+ # Disable the shared namespace so pyspark.sql.functions, etc point the regular
+ # PySpark libraries.
+ os.environ["PYSPARK_NO_NAMESPACE_SHARE"] = "1"
+
+ cls.connect = cls.spark # Switch Spark Connect session and regular PySpark session.
+ cls.spark = PySparkSession._instantiatedSession
+ assert cls.spark is not None
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ # Stopping Spark Connect closes the session in JVM at the server.
+ cls.spark = cls.connect
+ del os.environ["PYSPARK_NO_NAMESPACE_SHARE"]
+ finally:
+ super(SparkConnectReattachTestCase, cls).tearDownClass()
+
+ def test_release_sessions(self):
+ big_enough_query = "select * from range(1000000)"
+ query1 = self.connect.sql(big_enough_query).toLocalIterator()
+ query2 = self.connect.sql(big_enough_query).toLocalIterator()
+ query3 = self.connect.sql("select 1").toLocalIterator()
+
+ next(query1)
+ next(query2)
+
+ jvm = PySparkSession._instantiatedSession._jvm # type: ignore[union-attr]
+ service = getattr(
+ getattr(
+ jvm.org.apache.spark.sql.connect.service, # type: ignore[union-attr]
+ "SparkConnectService$",
+ ),
+ "MODULE$",
+ )
+
+ @eventually(catch_assertions=True)
+ def wait_for_requests():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 2)
+
+ wait_for_requests()
+
+ # Close session
+ self.connect.client.release_session()
+ # Calling release session again should be a no-op.
+ self.connect.client.release_session()
+
+ @eventually(catch_assertions=True)
+ def wait_for_responses():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 0)
+
+ wait_for_responses()
+
+ # query1 and query2 could get either an:
+ # OPERATION_CANCELED if it happens fast - when closing the session interrupted the queries,
+ # and that error got pushed to the client buffers before the client got disconnected.
+ # OPERATION_ABANDONED if it happens slow - when closing the session interrupted the client
+ # RPCs before it pushed out the error above. The client would then get an
+ # INVALID_CURSOR.DISCONNECTED, which it will retry with a ReattachExecute, and then get an
+ # INVALID_HANDLE.OPERATION_ABANDONED.
+
+ def check_error(q):
+ try:
+ list(q) # Iterate all.
+ except Exception as e: # noqa: F841
+ return e
+
+ e = check_error(query1)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+ e = check_error(query2)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+
+ # query3 has not been submitted before, so it should now fail with SESSION_CLOSED
+ e = check_error(query3)
Review Comment:
We did at https://github.com/apache/spark/commit/9c291e1165c145104becf69ecafcdba2914c29f1. That was because of the behaviour difference between Java and Python gRPC libraries:
- Java gRPC sends an early request when opening a response stream (iterator) from a request (https://github.com/grpc/grpc-java/issues/10697) before invoking `next` in the iterator.
- Python gRPC does not send an request when opening a response stream (generator) from a request, until we invoke `next` in the iterator.
So I preserved the old test case here.
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43965:
URL: https://github.com/apache/spark/pull/43965#discussion_r1402843097
##########
python/pyspark/sql/connect/client/core.py:
##########
@@ -1525,9 +1525,15 @@ def _display_server_stack_trace(self) -> bool:
from pyspark.sql.connect.conf import RuntimeConf
conf = RuntimeConf(self)
- if conf.get("spark.sql.connect.serverStacktrace.enabled") == "true":
+ try:
Review Comment:
I piggiy back a fix since I am here. This is tested together by the test added in `test_reattach`. cc @heyihong
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43965:
URL: https://github.com/apache/spark/pull/43965#discussion_r1402844776
##########
python/pyspark/sql/tests/connect/client/test_reattach.py:
##########
@@ -0,0 +1,124 @@
+#
+# 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.
+#
+
+import os
+import unittest
+
+from pyspark.sql import SparkSession as PySparkSession
+from pyspark.testing.connectutils import ReusedConnectTestCase
+from pyspark.testing.pandasutils import PandasOnSparkTestUtils
+from pyspark.testing.sqlutils import SQLTestUtils
+from pyspark.testing.utils import eventually
+
+
+class SparkConnectReattachTestCase(ReusedConnectTestCase, SQLTestUtils, PandasOnSparkTestUtils):
+ @classmethod
+ def setUpClass(cls):
+ super(SparkConnectReattachTestCase, cls).setUpClass()
+ # Disable the shared namespace so pyspark.sql.functions, etc point the regular
+ # PySpark libraries.
+ os.environ["PYSPARK_NO_NAMESPACE_SHARE"] = "1"
+
+ cls.connect = cls.spark # Switch Spark Connect session and regular PySpark session.
+ cls.spark = PySparkSession._instantiatedSession
+ assert cls.spark is not None
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ # Stopping Spark Connect closes the session in JVM at the server.
+ cls.spark = cls.connect
+ del os.environ["PYSPARK_NO_NAMESPACE_SHARE"]
+ finally:
+ super(SparkConnectReattachTestCase, cls).tearDownClass()
+
+ def test_release_sessions(self):
+ big_enough_query = "select * from range(1000000)"
+ query1 = self.connect.sql(big_enough_query).toLocalIterator()
+ query2 = self.connect.sql(big_enough_query).toLocalIterator()
+ query3 = self.connect.sql("select 1").toLocalIterator()
+
+ next(query1)
+ next(query2)
+
+ jvm = PySparkSession._instantiatedSession._jvm # type: ignore[union-attr]
+ service = getattr(
+ getattr(
+ jvm.org.apache.spark.sql.connect.service, # type: ignore[union-attr]
+ "SparkConnectService$",
+ ),
+ "MODULE$",
+ )
+
+ @eventually(catch_assertions=True)
+ def wait_for_requests():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 2)
+
+ wait_for_requests()
+
+ # Close session
+ self.connect.client.release_session()
+ # Calling release session again should be a no-op.
+ self.connect.client.release_session()
+
+ @eventually(catch_assertions=True)
+ def wait_for_responses():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 0)
+
+ wait_for_responses()
+
+ # query1 and query2 could get either an:
+ # OPERATION_CANCELED if it happens fast - when closing the session interrupted the queries,
+ # and that error got pushed to the client buffers before the client got disconnected.
+ # OPERATION_ABANDONED if it happens slow - when closing the session interrupted the client
+ # RPCs before it pushed out the error above. The client would then get an
+ # INVALID_CURSOR.DISCONNECTED, which it will retry with a ReattachExecute, and then get an
+ # INVALID_HANDLE.OPERATION_ABANDONED.
+
+ def check_error(q):
+ try:
+ list(q) # Iterate all.
+ except Exception as e: # noqa: F841
+ return e
+
+ e = check_error(query1)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+ e = check_error(query2)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+
+ # query3 has not been submitted before, so it should now fail with SESSION_CLOSED
+ e = check_error(query3)
Review Comment:
We did at https://github.com/apache/spark/commit/9c291e1165c145104becf69ecafcdba2914c29f1. That was because of the behaviour difference between Java and Python gRPC libraries:
- Java gRPC sends an early request when opening a response stream from a request (https://github.com/grpc/grpc-java/issues/10697)
- Python gRPC does not send an request when opening a response stream (generator) from a request.
So I preserved the old test case here.
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43965:
URL: https://github.com/apache/spark/pull/43965#discussion_r1402843475
##########
python/pyspark/sql/connect/client/core.py:
##########
@@ -1614,7 +1620,10 @@ def _verify_response_integrity(
f"{response.session_id} != {self._session_id}"
)
if self._server_session_id is not None:
- if response.server_side_session_id != self._server_session_id:
+ if (
+ response.server_side_session_id
+ and response.server_side_session_id != self._server_session_id
+ ):
Review Comment:
cc @grundprinzip FYI. Seems like `server_side_session_id` can be empty when the session does not exist, e.g. repeated `ReleaseSessionRequest` requests (see `SparkConnectReleaseSessionHandler`). This is also tested together with `test_reattach` test I added.
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43965:
URL: https://github.com/apache/spark/pull/43965#discussion_r1402844776
##########
python/pyspark/sql/tests/connect/client/test_reattach.py:
##########
@@ -0,0 +1,124 @@
+#
+# 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.
+#
+
+import os
+import unittest
+
+from pyspark.sql import SparkSession as PySparkSession
+from pyspark.testing.connectutils import ReusedConnectTestCase
+from pyspark.testing.pandasutils import PandasOnSparkTestUtils
+from pyspark.testing.sqlutils import SQLTestUtils
+from pyspark.testing.utils import eventually
+
+
+class SparkConnectReattachTestCase(ReusedConnectTestCase, SQLTestUtils, PandasOnSparkTestUtils):
+ @classmethod
+ def setUpClass(cls):
+ super(SparkConnectReattachTestCase, cls).setUpClass()
+ # Disable the shared namespace so pyspark.sql.functions, etc point the regular
+ # PySpark libraries.
+ os.environ["PYSPARK_NO_NAMESPACE_SHARE"] = "1"
+
+ cls.connect = cls.spark # Switch Spark Connect session and regular PySpark session.
+ cls.spark = PySparkSession._instantiatedSession
+ assert cls.spark is not None
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ # Stopping Spark Connect closes the session in JVM at the server.
+ cls.spark = cls.connect
+ del os.environ["PYSPARK_NO_NAMESPACE_SHARE"]
+ finally:
+ super(SparkConnectReattachTestCase, cls).tearDownClass()
+
+ def test_release_sessions(self):
+ big_enough_query = "select * from range(1000000)"
+ query1 = self.connect.sql(big_enough_query).toLocalIterator()
+ query2 = self.connect.sql(big_enough_query).toLocalIterator()
+ query3 = self.connect.sql("select 1").toLocalIterator()
+
+ next(query1)
+ next(query2)
+
+ jvm = PySparkSession._instantiatedSession._jvm # type: ignore[union-attr]
+ service = getattr(
+ getattr(
+ jvm.org.apache.spark.sql.connect.service, # type: ignore[union-attr]
+ "SparkConnectService$",
+ ),
+ "MODULE$",
+ )
+
+ @eventually(catch_assertions=True)
+ def wait_for_requests():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 2)
+
+ wait_for_requests()
+
+ # Close session
+ self.connect.client.release_session()
+ # Calling release session again should be a no-op.
+ self.connect.client.release_session()
+
+ @eventually(catch_assertions=True)
+ def wait_for_responses():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 0)
+
+ wait_for_responses()
+
+ # query1 and query2 could get either an:
+ # OPERATION_CANCELED if it happens fast - when closing the session interrupted the queries,
+ # and that error got pushed to the client buffers before the client got disconnected.
+ # OPERATION_ABANDONED if it happens slow - when closing the session interrupted the client
+ # RPCs before it pushed out the error above. The client would then get an
+ # INVALID_CURSOR.DISCONNECTED, which it will retry with a ReattachExecute, and then get an
+ # INVALID_HANDLE.OPERATION_ABANDONED.
+
+ def check_error(q):
+ try:
+ list(q) # Iterate all.
+ except Exception as e: # noqa: F841
+ return e
+
+ e = check_error(query1)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+ e = check_error(query2)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+
+ # query3 has not been submitted before, so it should now fail with SESSION_CLOSED
+ e = check_error(query3)
Review Comment:
We did at https://github.com/apache/spark/commit/9c291e1165c145104becf69ecafcdba2914c29f1. That was because of the behaviour difference between JVM and Python gRPC libraries:
- JVM sends an early request when opening a response stream from a request (https://github.com/grpc/grpc-java/issues/10697)
- Python does not send an request when opening a response stream (generator).
So I preserved the old test case here.
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #43965: [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case
URL: https://github.com/apache/spark/pull/43965
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #43965:
URL: https://github.com/apache/spark/pull/43965#issuecomment-1823720500
cc @juliuszsompolski @dongjoon-hyun FYI
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "juliuszsompolski (via GitHub)" <gi...@apache.org>.
juliuszsompolski commented on code in PR #43965:
URL: https://github.com/apache/spark/pull/43965#discussion_r1403368479
##########
python/pyspark/sql/connect/client/core.py:
##########
@@ -1614,7 +1620,10 @@ def _verify_response_integrity(
f"{response.session_id} != {self._session_id}"
)
if self._server_session_id is not None:
- if response.server_side_session_id != self._server_session_id:
+ if (
+ response.server_side_session_id
+ and response.server_side_session_id != self._server_session_id
+ ):
Review Comment:
I checked that scala was doing this check https://github.com/apache/spark/pull/43664/files#diff-bca41eacf4b96906693f0631af75db7b4c40e4d8ff21d081d038cba04dcd2809R43. I caught this during review in https://github.com/apache/spark/pull/43664#discussion_r1384861491, but didn't catch the same in the python side.
--
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
Re: [PR] [SPARK-46061][PYTHON][TESTS] Add the test party for reattach test case [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43965:
URL: https://github.com/apache/spark/pull/43965#discussion_r1402844776
##########
python/pyspark/sql/tests/connect/client/test_reattach.py:
##########
@@ -0,0 +1,124 @@
+#
+# 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.
+#
+
+import os
+import unittest
+
+from pyspark.sql import SparkSession as PySparkSession
+from pyspark.testing.connectutils import ReusedConnectTestCase
+from pyspark.testing.pandasutils import PandasOnSparkTestUtils
+from pyspark.testing.sqlutils import SQLTestUtils
+from pyspark.testing.utils import eventually
+
+
+class SparkConnectReattachTestCase(ReusedConnectTestCase, SQLTestUtils, PandasOnSparkTestUtils):
+ @classmethod
+ def setUpClass(cls):
+ super(SparkConnectReattachTestCase, cls).setUpClass()
+ # Disable the shared namespace so pyspark.sql.functions, etc point the regular
+ # PySpark libraries.
+ os.environ["PYSPARK_NO_NAMESPACE_SHARE"] = "1"
+
+ cls.connect = cls.spark # Switch Spark Connect session and regular PySpark session.
+ cls.spark = PySparkSession._instantiatedSession
+ assert cls.spark is not None
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ # Stopping Spark Connect closes the session in JVM at the server.
+ cls.spark = cls.connect
+ del os.environ["PYSPARK_NO_NAMESPACE_SHARE"]
+ finally:
+ super(SparkConnectReattachTestCase, cls).tearDownClass()
+
+ def test_release_sessions(self):
+ big_enough_query = "select * from range(1000000)"
+ query1 = self.connect.sql(big_enough_query).toLocalIterator()
+ query2 = self.connect.sql(big_enough_query).toLocalIterator()
+ query3 = self.connect.sql("select 1").toLocalIterator()
+
+ next(query1)
+ next(query2)
+
+ jvm = PySparkSession._instantiatedSession._jvm # type: ignore[union-attr]
+ service = getattr(
+ getattr(
+ jvm.org.apache.spark.sql.connect.service, # type: ignore[union-attr]
+ "SparkConnectService$",
+ ),
+ "MODULE$",
+ )
+
+ @eventually(catch_assertions=True)
+ def wait_for_requests():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 2)
+
+ wait_for_requests()
+
+ # Close session
+ self.connect.client.release_session()
+ # Calling release session again should be a no-op.
+ self.connect.client.release_session()
+
+ @eventually(catch_assertions=True)
+ def wait_for_responses():
+ self.assertEqual(service.executionManager().listExecuteHolders().length(), 0)
+
+ wait_for_responses()
+
+ # query1 and query2 could get either an:
+ # OPERATION_CANCELED if it happens fast - when closing the session interrupted the queries,
+ # and that error got pushed to the client buffers before the client got disconnected.
+ # OPERATION_ABANDONED if it happens slow - when closing the session interrupted the client
+ # RPCs before it pushed out the error above. The client would then get an
+ # INVALID_CURSOR.DISCONNECTED, which it will retry with a ReattachExecute, and then get an
+ # INVALID_HANDLE.OPERATION_ABANDONED.
+
+ def check_error(q):
+ try:
+ list(q) # Iterate all.
+ except Exception as e: # noqa: F841
+ return e
+
+ e = check_error(query1)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+ e = check_error(query2)
+ self.assertIsNotNone(e, "An exception has to be thrown")
+ self.assertTrue(
+ "OPERATION_CANCELED" in str(e) or "INVALID_HANDLE.OPERATION_ABANDONED" in str(e)
+ )
+
+ # query3 has not been submitted before, so it should now fail with SESSION_CLOSED
+ e = check_error(query3)
Review Comment:
We did at https://github.com/apache/spark/commit/9c291e1165c145104becf69ecafcdba2914c29f1. That was because of the behaviour difference between Java and Python gRPC libraries:
- Java gRPC sends an early request when opening a response stream (iterator) from a request (https://github.com/grpc/grpc-java/issues/10697) before invoking `next` in the iterator.
- Python gRPC does not send a request when opening a response stream (generator) from a request, until we invoke `next` in the iterator.
So I preserved the old test case here.
--
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