wolfboys commented on code in PR #3908:
URL:
https://github.com/apache/incubator-streampark/pull/3908#discussion_r1686730199
##########
streampark-spark/streampark-spark-client/streampark-spark-client-core/src/main/scala/org/apache/streampark/spark/client/impl/YarnClient.scala:
##########
@@ -26,15 +26,26 @@ import org.apache.streampark.spark.client.bean._
import org.apache.hadoop.yarn.api.records.ApplicationId
import org.apache.spark.launcher.{SparkAppHandle, SparkLauncher}
-import java.util.concurrent.CountDownLatch
+import java.util.concurrent.{ConcurrentHashMap, CountDownLatch}
import scala.util.{Failure, Success, Try}
/** yarn application mode submit */
object YarnClient extends SparkClientTrait {
+ private lazy val sparkHandles = new ConcurrentHashMap[String,
SparkAppHandle]()
+
override def doStop(stopRequest: StopRequest): StopResponse = {
Review Comment:
You need to consider what to do if an exception occurs. What happens if the
SparkAppHandle kill fails?
```
override def doStop(stopRequest: StopRequest): StopResponse = {
val sparkAppHandle = sparkHandles.remove(stopRequest.jobId)
if (sparkAppHandle != null) {
Try(sparkAppHandle.kill()) match {
case Success(_) =>
logger.warn(s"[StreamPark][Spark][YarnClient] spark job:
${stopRequest.jobId} is stopped successfully.")
StopResponse(null)
case Failure(e) =>
logger.error("sparkAppHandle kill failed. Try kill by yarn", e)
yarnKill(stopRequest.jobId)
StopResponse(null)
}
} else {
yarnKill(stopRequest.jobId)
StopResponse(null)
}
}
private def yarnKill(appId: String): Unit = {
Try(HadoopUtils.yarnClient.killApplication(ApplicationId.fromString(appId)))
match {
case Failure(e) => throw e
case _ =>
}
}
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]