Commit db714bb
[SPARK-38270][SQL] Spark SQL CLI's AM should keep same exit code with client side
### What changes were proposed in this pull request?
Current Spark SQL CLI alway use shutdown hook to stop SparkSQLEnv
```
// Clean up after we exit
ShutdownHookManager.addShutdownHook { () => SparkSQLEnv.stop() }
```
but use process ret to close client side jvm
```
while (line != null) {
if (!line.startsWith("--")) {
if (prefix.nonEmpty) {
prefix += '\n'
}
if (line.trim().endsWith(";") && !line.trim().endsWith("\\;")) {
line = prefix + line
ret = cli.processLine(line, true)
prefix = ""
currentPrompt = promptWithCurrentDB
} else {
prefix = prefix + line
currentPrompt = continuedPromptWithDBSpaces
}
}
line = reader.readLine(currentPrompt + "> ")
}
sessionState.close()
System.exit(ret)
}
```
```
if (sessionState.execString != null) {
exitCode = cli.processLine(sessionState.execString)
System.exit(exitCode)
}
try {
if (sessionState.fileName != null) {
exitCode = cli.processFile(sessionState.fileName)
System.exit(exitCode)
}
} catch {
case e: FileNotFoundException =>
logError(s"Could not open input file for reading. (${e.getMessage})")
exitCode = 3
System.exit(exitCode)
}
```
This always cause client side exit code not consistent with AM.
IN this pr I prefer to pass the exit code to `SparkContext.stop()` method to pass a clear client side status to AM side in client mode.
In this pr, I add a new `stop` method in `SchedulerBackend`
```
def stop(exitCode: Int): Unit = stop()
```
So we don't need to implement it for all kinds of scheduler backend.
In this pr, we only handle the case me meet for `YarnClientSchedulerBackend`, then we can only implement `stop(exitCode: Int)` for this class, then for yarn client mode, it can work now.
I think this can benefit many similar case in future.
### Why are the changes needed?
Keep client side status consistent with AM side
### Does this PR introduce _any_ user-facing change?
With this pr, client side status will be same with am side
### How was this patch tested?
MT
Closes apache#35594 from AngersZhuuuu/SPARK-38270.
Lead-authored-by: Angerszhuuuu <[email protected]>
Co-authored-by: AngersZhuuuu <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>1 parent 393a767 commit db714bb
File tree
14 files changed
+68
-31
lines changed- core/src
- main/scala/org/apache/spark
- scheduler
- cluster
- test/scala/org/apache/spark/scheduler
- project
- resource-managers/yarn/src/main/scala/org/apache/spark
- deploy/yarn
- scheduler/cluster
- sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver
14 files changed
+68
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2068 | 2068 | | |
2069 | 2069 | | |
2070 | 2070 | | |
2071 | | - | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
2072 | 2085 | | |
2073 | 2086 | | |
2074 | 2087 | | |
| |||
2101 | 2114 | | |
2102 | 2115 | | |
2103 | 2116 | | |
2104 | | - | |
| 2117 | + | |
2105 | 2118 | | |
2106 | 2119 | | |
2107 | 2120 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2889 | 2889 | | |
2890 | 2890 | | |
2891 | 2891 | | |
2892 | | - | |
| 2892 | + | |
2893 | 2893 | | |
2894 | 2894 | | |
2895 | 2895 | | |
| |||
2900 | 2900 | | |
2901 | 2901 | | |
2902 | 2902 | | |
2903 | | - | |
| 2903 | + | |
2904 | 2904 | | |
2905 | 2905 | | |
2906 | 2906 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
971 | 971 | | |
972 | 972 | | |
973 | 973 | | |
974 | | - | |
| 974 | + | |
975 | 975 | | |
976 | 976 | | |
977 | 977 | | |
978 | 978 | | |
979 | 979 | | |
980 | | - | |
| 980 | + | |
981 | 981 | | |
982 | 982 | | |
983 | 983 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| |||
846 | 846 | | |
847 | 847 | | |
848 | 848 | | |
849 | | - | |
| 849 | + | |
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
104 | 112 | | |
105 | 113 | | |
106 | 114 | | |
| |||
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
790 | 790 | | |
791 | 791 | | |
792 | 792 | | |
| 793 | + | |
| 794 | + | |
793 | 795 | | |
794 | 796 | | |
795 | 797 | | |
| |||
810 | 812 | | |
811 | 813 | | |
812 | 814 | | |
813 | | - | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
814 | 818 | | |
815 | 819 | | |
816 | 820 | | |
| |||
854 | 858 | | |
855 | 859 | | |
856 | 860 | | |
857 | | - | |
858 | | - | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
859 | 868 | | |
860 | 869 | | |
861 | 870 | | |
| |||
0 commit comments