-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-45167][CONNECT][PYTHON] Python client must call release_all
#42929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1635f02
[SPARK-45167] Python client must call `release_all`
grundprinzip a065d3c
fix
grundprinzip a50835f
fix
grundprinzip 0cdbd1d
fix
grundprinzip 156b195
fix
grundprinzip 0f121db
Update test_client.py
grundprinzip f0b57a5
locks and style
grundprinzip fb2c464
style
grundprinzip 40e5985
style
grundprinzip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,9 +136,12 @@ def setUp(self) -> None: | |
| "jitter": 10, | ||
| "min_jitter_threshold": 10, | ||
| } | ||
| self.response = proto.ExecutePlanResponse() | ||
| self.response = proto.ExecutePlanResponse( | ||
| response_id="1", | ||
| ) | ||
| self.finished = proto.ExecutePlanResponse( | ||
| result_complete=proto.ExecutePlanResponse.ResultComplete() | ||
| result_complete=proto.ExecutePlanResponse.ResultComplete(), | ||
| response_id="2", | ||
| ) | ||
|
|
||
| def _stub_with(self, execute=None, attach=None): | ||
|
|
@@ -147,15 +150,33 @@ def _stub_with(self, execute=None, attach=None): | |
| attach_ops=ResponseGenerator(attach) if attach is not None else None, | ||
| ) | ||
|
|
||
| def assertEventually(self, callable, timeout_ms=1000): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| """Helper method that will continuously evaluate the callable to not raise an | ||
| exception.""" | ||
| import time | ||
|
|
||
| limit = time.monotonic_ns() + timeout_ms * 1000 * 1000 | ||
| while time.monotonic_ns() < limit: | ||
| try: | ||
| callable() | ||
| break | ||
| except Exception: | ||
| time.sleep(0.1) | ||
| callable() | ||
|
|
||
| def test_basic_flow(self): | ||
| stub = self._stub_with([self.response, self.finished]) | ||
| ite = ExecutePlanResponseReattachableIterator(self.request, stub, self.policy, []) | ||
| for b in ite: | ||
| pass | ||
|
|
||
| self.assertEqual(0, stub.attach_calls) | ||
| self.assertGreater(1, stub.release_calls) | ||
| self.assertEqual(1, stub.execute_calls) | ||
| def check_all(): | ||
| self.assertEqual(0, stub.attach_calls) | ||
| self.assertEqual(1, stub.release_until_calls) | ||
| self.assertEqual(1, stub.release_calls) | ||
| self.assertEqual(1, stub.execute_calls) | ||
|
|
||
| self.assertEventually(check_all, timeout_ms=1000) | ||
|
|
||
| def test_fail_during_execute(self): | ||
| def fatal(): | ||
|
|
@@ -167,9 +188,13 @@ def fatal(): | |
| for b in ite: | ||
| pass | ||
|
|
||
| self.assertEqual(0, stub.attach_calls) | ||
| self.assertEqual(0, stub.release_calls) | ||
| self.assertEqual(1, stub.execute_calls) | ||
| def check(): | ||
| self.assertEqual(0, stub.attach_calls) | ||
| self.assertEqual(1, stub.release_calls) | ||
| self.assertEqual(1, stub.release_until_calls) | ||
| self.assertEqual(1, stub.execute_calls) | ||
|
|
||
| self.assertEventually(check, timeout_ms=1000) | ||
|
|
||
| def test_fail_and_retry_during_execute(self): | ||
| def non_fatal(): | ||
|
|
@@ -182,9 +207,13 @@ def non_fatal(): | |
| for b in ite: | ||
| pass | ||
|
|
||
| self.assertEqual(1, stub.attach_calls) | ||
| self.assertEqual(1, stub.release_calls) | ||
| self.assertEqual(1, stub.execute_calls) | ||
| def check(): | ||
| self.assertEqual(1, stub.attach_calls) | ||
| self.assertEqual(1, stub.release_calls) | ||
| self.assertEqual(3, stub.release_until_calls) | ||
| self.assertEqual(1, stub.execute_calls) | ||
|
|
||
| self.assertEventually(check, timeout_ms=1000) | ||
|
|
||
| def test_fail_and_retry_during_reattach(self): | ||
| count = 0 | ||
|
|
@@ -204,9 +233,13 @@ def non_fatal(): | |
| for b in ite: | ||
| pass | ||
|
|
||
| self.assertEqual(2, stub.attach_calls) | ||
| self.assertEqual(2, stub.release_calls) | ||
| self.assertEqual(1, stub.execute_calls) | ||
| def check(): | ||
| self.assertEqual(2, stub.attach_calls) | ||
| self.assertEqual(3, stub.release_until_calls) | ||
| self.assertEqual(1, stub.release_calls) | ||
| self.assertEqual(1, stub.execute_calls) | ||
|
|
||
| self.assertEventually(check, timeout_ms=1000) | ||
|
|
||
|
|
||
| class TestException(grpc.RpcError, grpc.Call): | ||
|
|
@@ -257,6 +290,7 @@ def __init__(self, execute_ops=None, attach_ops=None): | |
| # Call counters | ||
| self.execute_calls = 0 | ||
| self.release_calls = 0 | ||
| self.release_until_calls = 0 | ||
| self.attach_calls = 0 | ||
|
|
||
| def ExecutePlan(self, *args, **kwargs): | ||
|
|
@@ -267,8 +301,12 @@ def ReattachExecute(self, *args, **kwargs): | |
| self.attach_calls += 1 | ||
| return self._attach_ops | ||
|
|
||
| def ReleaseExecute(self, *args, **kwargs): | ||
| self.release_calls += 1 | ||
| def ReleaseExecute(self, req: proto.ReleaseExecuteRequest, *args, **kwargs): | ||
| if req.HasField("release_all"): | ||
| self.release_calls += 1 | ||
| elif req.HasField("release_until"): | ||
| print("increment") | ||
| self.release_until_calls += 1 | ||
|
|
||
|
|
||
| class MockService: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen (and ignored for now...) the scala equivalent of this failing when we do
SparkConnectClient.shutdown, which doeschannel.shutdownNow(). In scala, we don't have a dedicated threadpool for that, but (ab)use a grpc thread in https://github.com/apache/spark/blob/master/connector/connect/common/src/main/scala/org/apache/spark/sql/connect/client/ExecutePlanResponseReattachableIterator.scala#L179I wonder if more graceful shutdown of the channel would fixed it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised https://issues.apache.org/jira/browse/SPARK-45206 to track