Github user piaozhexiu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5343#discussion_r27756532
  
    --- Diff: yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala ---
    @@ -105,6 +102,16 @@ private[spark] class Client(
         // Finally, submit and monitor the application
         logInfo(s"Submitting application ${appId.getId} to ResourceManager")
         yarnClient.submitApplication(appContext)
    +
    +    // In YARN Cluster mode, AM is not killed when the client is 
terminated by default.
    +    // But if spark.yarn.force.shutdown.am is set true, AM is force 
shutdown.
    +    if (isClusterMode && 
sparkConf.getBoolean("spark.yarn.am.force.shutdown", false)) {
    +      val shutdownHook = new Runnable {
    +        override def run() { yarnClient.killApplication(appId) }
    +      }
    +      ShutdownHookManager.get().addShutdownHook(shutdownHook, 0)
    --- End diff --
    
    Hi, @srowen , thank you for the question.
    
    Unfortunately, it won't work. `Client.stop()` is invoked in the client mode 
by Yarn**Client**SchedulerBackend.stop() while it is not in the cluster mode. 
Furthermore, I can't call it from Yarn**Cluster**SchedulerBackend.stop() 
because Yarn**Cluster**SchedulerBackend runs in AM not in the client.
    
    In addition, to handle all possible interruption points, shutdown hook 
seems like the most effective way. Imagine that the client can be killed at any 
time among [a], [b], and [c]:
    
    1. Client starts.
       * [a] <---- Kill here
    2. Client submits the application.
       * [b] <---- Kill here / AM is ACCEPTED
    3. Client waits for the application to be accepted.
       * [c] <---- Kill here / AM is RUNNING
    4. Client waits for the application to be finished.
    
    If the client is killed at [b], shutdown hook is the best way to catch it.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to