runzhiwang commented on a change in pull request #242: [LIVY-336] Livy should 
not spawn one thread per job to track the job on Yarn
URL: https://github.com/apache/incubator-livy/pull/242#discussion_r333381184
 
 

 ##########
 File path: server/src/main/scala/org/apache/livy/utils/SparkYarnApp.scala
 ##########
 @@ -122,31 +162,53 @@ class SparkYarnApp private[utils] (
   with Logging {
   import SparkYarnApp._
 
+  appList += this
+
   private var killed = false
-  private val appIdPromise: Promise[ApplicationId] = Promise()
   private[utils] var state: SparkApp.State = SparkApp.State.STARTING
   private var yarnDiagnostics: IndexedSeq[String] = IndexedSeq.empty[String]
+  private var appInfo = AppInfo()
+  private var appId: Option[ApplicationId] = None
 
   override def log(): IndexedSeq[String] =
     ("stdout: " +: 
process.map(_.inputLines).getOrElse(ArrayBuffer.empty[String])) ++
     ("\nstderr: " +: 
process.map(_.errorLines).getOrElse(ArrayBuffer.empty[String])) ++
     ("\nYARN Diagnostics: " +: yarnDiagnostics)
 
+  private def getAppTag = appTag
+
   override def kill(): Unit = synchronized {
     killed = true
-    if (isRunning) {
-      try {
-        val timeout = SparkYarnApp.getYarnTagToAppIdTimeout(livyConf)
-        yarnClient.killApplication(Await.result(appIdPromise.future, timeout))
-      } catch {
-        // We cannot kill the YARN app without the app id.
-        // There's a chance the YARN app hasn't been submitted during a 
livy-server failure.
-        // We don't want a stuck session that can't be deleted. Emit a warning 
and move on.
-        case _: TimeoutException | _: InterruptedException =>
-          warn("Deleting a session while its YARN application is not found.")
-          yarnAppMonitorThread.interrupt()
-      } finally {
-        process.foreach(_.destroy())
+
+    if (!isRunning) {
+      return
+    }
+
+    process.foreach(_.destroy())
+
+    if (!appId.isEmpty) {
+      yarnClient.killApplication(appId.get)
+      return
+    } else {
+      Future {
 
 Review comment:
   Because the code in `Future` may cost a lot of time.  Use `Future` can avoid 
blocking the main thread.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to