feat(driver): track and report driver exit state to AppMaster#480
Open
my-vegetable-has-exploded wants to merge 4 commits into
Open
feat(driver): track and report driver exit state to AppMaster#480my-vegetable-has-exploded wants to merge 4 commits into
my-vegetable-has-exploded wants to merge 4 commits into
Conversation
- Add DriverExitState: thread-safe state machine tracking FINISHED/FAILED/KILLED with exit codes and diagnostics - Add DriverAppMasterReporter: reports terminal state to RayAppMaster via FinishApplication RPC, idempotent with CAS-based once-only reporting - Replace UnregisterApplication with FinishApplication containing state/exitCode/diagnostics - Add ApplicationInfo.finish() method and exitCode/diagnostics fields - Add RayAppMaster.finishApplication() and RayAppMasterUtils Java accessor - Track driver exit in SparkSubmit: wrap main with try/catch, report state on exit - Wire DriverAppMasterReporter.bind/bindMasterHandle in scheduler backend - Handle KILLED state in RayCoarseGrainedSchedulerBackend.stop() - Make shuffle service actors named and idempotent - Remove obsolete TestRayCoarseGrainedSchedulerBackend tests Signed-off-by: epsilonwang <epsilonwang@didiglobal.com>
Revert ExternalShuffleServiceUtils.java and RayExternalShuffleService.scala to their base (bde8b06) versions, removing changes that belong to the idempotent-ess-fork branch: - Remove named actor pattern (getShuffleServiceActorName, Ray.getActor, setName, setMaxRestarts, setMaxTaskRetries) from ExternalShuffleServiceUtils - Restore startShuffleService() method in ExternalShuffleServiceUtils - Remove auto-start call in RayExternalShuffleService constructor - Restore semicolon in import statement
There was a problem hiding this comment.
Pull request overview
This PR adds driver terminal-state reporting for RayDP applications so the RayAppMaster can distinguish FINISHED, FAILED, and KILLED outcomes instead of always treating unregister as successful completion.
Changes:
- Adds driver exit-state tracking and an AppMaster reporting/cleanup helper.
- Replaces
UnregisterApplicationwithFinishApplicationcarrying state, exit code, and diagnostics. - Wires SparkSubmit and scheduler-backend lifecycle paths into the new reporting flow.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
core/raydp-main/src/main/scala/org/apache/spark/scheduler/cluster/raydp/RayCoarseGrainedSchedulerBackend.scala |
Binds AppMaster reporting handles and reports cleanup on KILLED stop paths. |
core/raydp-main/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala |
Wraps submit lifecycle and exit handling to set/report driver terminal state. |
core/raydp-main/src/main/scala/org/apache/spark/deploy/raydp/RayAppMaster.scala |
Adds AppMaster-side finish RPC handling. |
core/raydp-main/src/main/scala/org/apache/spark/deploy/raydp/Messages.scala |
Replaces unregister message with finish message carrying terminal metadata. |
core/raydp-main/src/main/scala/org/apache/spark/deploy/raydp/DriverExitState.scala |
Adds global synchronized driver exit-state snapshot/state machine. |
core/raydp-main/src/main/scala/org/apache/spark/deploy/raydp/DriverAppMasterReporter.scala |
Adds exactly-once terminal state reporting and AppMaster cleanup helper. |
core/raydp-main/src/main/scala/org/apache/spark/deploy/raydp/ApplicationInfo.scala |
Stores exit code/diagnostics and adds idempotent finish handling. |
core/raydp-main/src/main/java/org/apache/spark/deploy/raydp/RayAppMasterUtils.java |
Adds Java helper for invoking AppMaster finish RPC. |
Comments suppressed due to low confidence (1)
core/raydp-main/src/main/scala/org/apache/spark/scheduler/cluster/raydp/RayCoarseGrainedSchedulerBackend.scala:312
- Reporting is now only triggered from the backend for the KILLED path. Since the previous stopAppMaster call was removed from stop(), in-process SparkSubmit and direct SparkContext users that do not go through SparkSubmit.main's new finalizer will stop the SparkContext without reporting FINISHED or cleaning up the AppMaster. This regresses the existing backend-owned cleanup path; normal stop should still report/cleanup or share the same finalization path.
if (finalState == SparkAppHandle.State.KILLED) {
DriverAppMasterReporter.tryReportAndCleanup()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collaborator
|
can we add some tests? |
added 2 commits
June 2, 2026 03:20
Signed-off-by: epsilonwang <epsilonwang@didiglobal.com>
Signed-off-by: epsilonwang <epsilonwang@didiglobal.com>
Contributor
Author
|
@copilot review |
Comment on lines
+59
to
+62
| val binding = synchronized { | ||
| if (reported.get()) None | ||
| else Some((appId, masterHandle)) | ||
| } |
Comment on lines
+66
to
+69
| if (currentAppId == null || currentMasterHandle == null) { | ||
| logWarning("Skip reporting terminal application state because AppMaster binding " + | ||
| "is incomplete.") | ||
| false |
Comment on lines
309
to
+313
| try { | ||
| super.stop() // this will stop all executors | ||
| appMasterRef.get.send(UnregisterApplication(appId.get)) | ||
| if (finalState == SparkAppHandle.State.KILLED) { | ||
| DriverAppMasterReporter.tryReportAndCleanup() | ||
| } |
Comment on lines
+165
to
+168
| # The driver sleeps for 300s after the Spark action; waiting here keeps | ||
| # the test simple while still killing raydp-submit during driver runtime. | ||
| time.sleep(KILL_AFTER_SECONDS) | ||
| log = output_path.read_text(encoding="utf-8") |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
RayDP currently has no mechanism for the driver to communicate its exit state (FINISHED / FAILED / KILLED) to the
RayAppMaster. The originalUnregisterApplicationmessage carries only anappId, so the AppMaster always records the application asFINISHED— even on failure or kill. This makes it impossible for upstream consumers (e.g. KubeRay RayJob status, monitoring dashboards) to determine the real outcome of a Spark application.Approach
DriverExitState— a thread-safe state machine that tracksUNKNOWN → FINISHED / FAILED / KILLED, carryingexitCodeanddiagnostics. Once a terminal state is set it is immutable.DriverAppMasterReporter— reports the terminal state toRayAppMastervia a newFinishApplicationRPC. UsesAtomicBoolean.compareAndSetto guarantee exactly-once reporting (idempotent). After reporting, it also stops the AppMaster to ensure cleanup.FinishApplicationmessage — replaces the originalUnregisterApplication, addingstate,exitCode, anddiagnosticsfields. Routed viareceiveAndReplyso the AppMaster can return whether the finish was accepted.SparkSubmit.main()refactor:exitFn: non-zero exit code →trySetFailed, zero →trySetFinisheddoSubmit()intry/catch: exception →trySetFailedfinalizeDriverTermination()→tryReportAndCleanup()before exitRayCoarseGrainedSchedulerBackend:onStopRequest(), setDriverExitState.trySetKilled(143, "Spark launcher requested application stop.")stop(KILLED)path, callDriverAppMasterReporter.tryReportAndCleanup()RayAppMasterUtils.stopAppMaster()instop()— the Reporter now handles thisApplicationInfo— addfinish()method (synchronized, idempotent — returnsfalseif already finished) andexitCode/diagnosticsfields.