Commit d9c5f9d
[SPARK-45798][CONNECT] Assert server-side session ID
### What changes were proposed in this pull request?
Without this patch, when the server would restart because of an abnormal condition, the client would not realize that this be the case. For example, when a driver OOM occurs and the driver is restarted, the client would not realize that the server is restarted and a new session is assigned.
This patch fixes this behavior and asserts that the server side session ID does not change during the connection. If it does change it throws an exception like this:
```
>>> spark.range(10).collect()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/martin.grund/Development/spark/python/pyspark/sql/connect/dataframe.py", line 1710, in collect
table, schema = self._to_table()
File "/Users/martin.grund/Development/spark/python/pyspark/sql/connect/dataframe.py", line 1722, in _to_table
table, schema = self._session.client.to_table(query, self._plan.observations)
File "/Users/martin.grund/Development/spark/python/pyspark/sql/connect/client/core.py", line 839, in to_table
table, schema, _, _, _ = self._execute_and_fetch(req, observations)
File "/Users/martin.grund/Development/spark/python/pyspark/sql/connect/client/core.py", line 1295, in _execute_and_fetch
for response in self._execute_and_fetch_as_iterator(req, observations):
File "/Users/martin.grund/Development/spark/python/pyspark/sql/connect/client/core.py", line 1273, in _execute_and_fetch_as_iterator
self._handle_error(error)
File "/Users/martin.grund/Development/spark/python/pyspark/sql/connect/client/core.py", line 1521, in _handle_error
raise error
File "/Users/martin.grund/Development/spark/python/pyspark/sql/connect/client/core.py", line 1266, in _execute_and_fetch_as_iterator
yield from handle_response(b)
File "/Users/martin.grund/Development/spark/python/pyspark/sql/connect/client/core.py", line 1193, in handle_response
self._verify_response_integrity(b)
File "/Users/martin.grund/Development/spark/python/pyspark/sql/connect/client/core.py", line 1622, in _verify_response_integrity
raise SparkConnectException(
pyspark.errors.exceptions.connect.SparkConnectException: Received incorrect server side session identifier for request. Please restart Spark Session. (9493c83d-cfa4-488f-9522-838ef3df90bf != c5302e8f-170d-477e-908d-299927b68fd8)
```
### Why are the changes needed?
Stability
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
- Existing tests cover the basic invariant.
- Added new tests.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #43664 from grundprinzip/SPARK-45798.
Authored-by: Martin Grund <martin.grund@databricks.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>1 parent ce818ba commit d9c5f9d
30 files changed
Lines changed: 671 additions & 252 deletions
File tree
- connector/connect
- client/jvm/src/test/scala/org/apache/spark/sql/connect/client
- common/src/main
- protobuf/spark/connect
- scala/org/apache/spark/sql/connect/client
- server/src
- main/scala/org/apache/spark/sql/connect
- artifact
- execution
- planner
- service
- utils
- test/scala/org/apache/spark/sql/connect
- artifact
- service
- python/pyspark/sql/connect
- client
- proto
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
62 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
Lines changed: 57 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
200 | 201 | | |
201 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
202 | 206 | | |
203 | 207 | | |
204 | 208 | | |
| |||
317 | 321 | | |
318 | 322 | | |
319 | 323 | | |
| 324 | + | |
320 | 325 | | |
321 | 326 | | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
322 | 330 | | |
323 | 331 | | |
324 | 332 | | |
| |||
492 | 500 | | |
493 | 501 | | |
494 | 502 | | |
| 503 | + | |
495 | 504 | | |
496 | 505 | | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
497 | 509 | | |
498 | 510 | | |
499 | 511 | | |
| |||
584 | 596 | | |
585 | 597 | | |
586 | 598 | | |
| 599 | + | |
587 | 600 | | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
588 | 610 | | |
589 | 611 | | |
590 | 612 | | |
| |||
593 | 615 | | |
594 | 616 | | |
595 | 617 | | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | 618 | | |
600 | 619 | | |
601 | 620 | | |
| |||
626 | 645 | | |
627 | 646 | | |
628 | 647 | | |
| 648 | + | |
629 | 649 | | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
630 | 658 | | |
631 | 659 | | |
632 | 660 | | |
633 | 661 | | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | 662 | | |
638 | 663 | | |
639 | 664 | | |
| |||
678 | 703 | | |
679 | 704 | | |
680 | 705 | | |
| 706 | + | |
681 | 707 | | |
682 | 708 | | |
683 | 709 | | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
684 | 713 | | |
685 | 714 | | |
686 | 715 | | |
| 716 | + | |
687 | 717 | | |
688 | 718 | | |
689 | 719 | | |
| |||
774 | 804 | | |
775 | 805 | | |
776 | 806 | | |
| 807 | + | |
777 | 808 | | |
778 | 809 | | |
779 | 810 | | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
780 | 814 | | |
781 | 815 | | |
782 | 816 | | |
| |||
803 | 837 | | |
804 | 838 | | |
805 | 839 | | |
| 840 | + | |
806 | 841 | | |
807 | 842 | | |
808 | 843 | | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
809 | 847 | | |
810 | 848 | | |
811 | 849 | | |
| |||
828 | 866 | | |
829 | 867 | | |
830 | 868 | | |
| 869 | + | |
831 | 870 | | |
832 | 871 | | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
833 | 884 | | |
834 | 885 | | |
835 | 886 | | |
| |||
914 | 965 | | |
915 | 966 | | |
916 | 967 | | |
917 | | - | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | 968 | | |
924 | 969 | | |
925 | 970 | | |
| |||
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
127 | 132 | | |
128 | 133 | | |
129 | 134 | | |
| |||
179 | 184 | | |
180 | 185 | | |
181 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
182 | 190 | | |
183 | 191 | | |
184 | 192 | | |
| |||
Lines changed: 24 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| |||
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
62 | | - | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
72 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
73 | 79 | | |
74 | 80 | | |
75 | 81 | | |
| |||
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
83 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| |||
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
94 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
95 | 105 | | |
96 | 106 | | |
97 | 107 | | |
| |||
102 | 112 | | |
103 | 113 | | |
104 | 114 | | |
105 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
106 | 118 | | |
107 | 119 | | |
108 | 120 | | |
| |||
113 | 125 | | |
114 | 126 | | |
115 | 127 | | |
116 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
117 | 131 | | |
118 | 132 | | |
119 | 133 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | | - | |
| 32 | + | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
Lines changed: 18 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
100 | 104 | | |
101 | 105 | | |
102 | 106 | | |
| |||
114 | 118 | | |
115 | 119 | | |
116 | 120 | | |
117 | | - | |
| 121 | + | |
118 | 122 | | |
119 | 123 | | |
120 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
121 | 138 | | |
122 | 139 | | |
123 | 140 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
| 31 | + | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| |||
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
52 | | - | |
53 | | - | |
| 51 | + | |
54 | 52 | | |
55 | 53 | | |
| 54 | + | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
0 commit comments