-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-13642][Yarn][1.6-backport] Properly handle signal kill in ApplicationMaster #11690
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 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
Properly handle signal kill in ApplicationMaster
- Loading branch information
commit 6c0ef0c75698c74da794a8bb27e92987f8d2907b
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,17 +17,19 @@ | |
|
|
||
| package org.apache.spark.deploy.yarn | ||
|
|
||
| import scala.util.control.NonFatal | ||
|
|
||
| import java.io.{File, IOException} | ||
| import java.lang.reflect.InvocationTargetException | ||
| import java.net.{Socket, URL} | ||
| import java.util.concurrent.atomic.AtomicReference | ||
|
|
||
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.commons.lang3.SystemUtils | ||
| import org.apache.hadoop.fs.{FileSystem, Path} | ||
| import org.apache.hadoop.yarn.api._ | ||
| import org.apache.hadoop.yarn.api.records._ | ||
| import org.apache.hadoop.yarn.conf.YarnConfiguration | ||
| import sun.misc.{Signal, SignalHandler} | ||
|
|
||
| import org.apache.spark.rpc._ | ||
| import org.apache.spark.{Logging, SecurityManager, SparkConf, SparkContext, SparkEnv, | ||
|
|
@@ -117,6 +119,25 @@ private[spark] class ApplicationMaster( | |
|
|
||
| private var delegationTokenRenewerOption: Option[AMDelegationTokenRenewer] = None | ||
|
|
||
| if (SystemUtils.IS_OS_UNIX) { | ||
| // Register signal handler for signal "TERM", "INT" and "HUP". For the cases where AM receive a | ||
| // signal and stop, from RM's aspect this application needs to be reattempted, rather than mark | ||
| // as success. | ||
| // Replace this signal handler with SignalLogger in AM side. | ||
| val signalHandler = new SignalHandler() { | ||
| override def handle(sig: Signal): Unit = { | ||
|
|
||
| logInfo(s"received signal: ${sig.getName}") | ||
| finish(FinalApplicationStatus.FAILED, ApplicationMaster.EXIT_SIGNAL) | ||
| } | ||
| } | ||
| Seq("TERM", "INT", "HUP").foreach { sig => Signal.handle(new Signal(sig), signalHandler) } | ||
| } | ||
|
|
||
| def getAttemptId(): ApplicationAttemptId = { | ||
|
||
| client.getAttemptId() | ||
| } | ||
|
|
||
| final def run(): Int = { | ||
| try { | ||
| val appAttemptId = client.getAttemptId() | ||
|
|
@@ -642,11 +663,11 @@ object ApplicationMaster extends Logging { | |
| private val EXIT_SC_NOT_INITED = 13 | ||
| private val EXIT_SECURITY = 14 | ||
| private val EXIT_EXCEPTION_USER_CLASS = 15 | ||
| private val EXIT_SIGNAL = 16 | ||
|
|
||
| private var master: ApplicationMaster = _ | ||
|
|
||
| def main(args: Array[String]): Unit = { | ||
| SignalLogger.register(log) | ||
| val amArgs = new ApplicationMasterArguments(args) | ||
| SparkHadoopUtil.get.runAsSparkUser { () => | ||
| master = new ApplicationMaster(amArgs, new YarnRMClient(amArgs)) | ||
|
|
||
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.
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.
remove extra blank line, you can add one above handle if it makes that easier to read