-
Notifications
You must be signed in to change notification settings - Fork 972
[KYUUBI #5136][Bug] Spark App may hang forever if FinalStageResourceManager killed all executors #5141
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
[KYUUBI #5136][Bug] Spark App may hang forever if FinalStageResourceManager killed all executors #5141
Changes from 4 commits
9dcbc78
12687ee
5f3ca1d
ea8f247
c4403ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import scala.collection.mutable | |
| import scala.collection.mutable.ArrayBuffer | ||
|
|
||
| import org.apache.spark.{ExecutorAllocationClient, MapOutputTrackerMaster, SparkContext, SparkEnv} | ||
| import org.apache.spark.resource.ResourceProfile | ||
| import org.apache.spark.scheduler.cluster.CoarseGrainedSchedulerBackend | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.execution.{FilterExec, ProjectExec, SortExec, SparkPlan} | ||
|
|
@@ -185,7 +186,12 @@ case class FinalStageResourceManager(session: SparkSession) | |
| numReduce: Int): Unit = { | ||
| val executorAllocationClient = sc.schedulerBackend.asInstanceOf[ExecutorAllocationClient] | ||
|
|
||
| val executorsToKill = findExecutorToKill(sc, targetExecutors, shuffleId, numReduce) | ||
| val executorsToKill = | ||
| if (conf.getConf(KyuubiSQLConf.FINAL_WRITE_STAGE_EAGERLY_KILL_EXECUTORS_KILL_ALL)) { | ||
| executorAllocationClient.getExecutorIds() | ||
| } else { | ||
| findExecutorToKill(sc, targetExecutors, shuffleId, numReduce) | ||
| } | ||
| logInfo(s"Request to kill executors, total count ${executorsToKill.size}, " + | ||
| s"[${executorsToKill.mkString(", ")}].") | ||
| if (executorsToKill.isEmpty) { | ||
|
|
@@ -210,6 +216,38 @@ case class FinalStageResourceManager(session: SparkSession) | |
| adjustTargetNumExecutors = true, | ||
| countFailures = false, | ||
| force = false) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we call We might face a issue similar with apache/spark#19048
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, we just need to tune adjustTargetNumExecutors from true to false and call client.requestTotalExecutors to ensure the final target executor is expected.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. But build parameters of As long as we did not call |
||
|
|
||
| getAdjustedTargetExecutors(sc, executorAllocationClient) | ||
| .filter(_ < targetExecutors).foreach { adjustedExecutors => | ||
| val delta = targetExecutors - adjustedExecutors | ||
| logInfo(s"Target executors after kill ($adjustedExecutors) is lower than required " + | ||
| s"($targetExecutors). Requesting $delta additional executor(s).") | ||
| executorAllocationClient.requestExecutors(delta) | ||
| } | ||
| } | ||
|
|
||
| private def getAdjustedTargetExecutors( | ||
| sc: SparkContext, | ||
| executorAllocationClient: ExecutorAllocationClient): Option[Int] = { | ||
| executorAllocationClient match { | ||
| case schedulerBackend: CoarseGrainedSchedulerBackend => | ||
| try { | ||
| val field = classOf[CoarseGrainedSchedulerBackend] | ||
| .getDeclaredField("requestedTotalExecutorsPerResourceProfile") | ||
| field.setAccessible(true) | ||
| schedulerBackend.synchronized { | ||
| val requestedTotalExecutorsPerResourceProfile = | ||
| field.get(schedulerBackend).asInstanceOf[mutable.HashMap[ResourceProfile, Int]] | ||
| val defaultRp = sc.resourceProfileManager.defaultResourceProfile | ||
| requestedTotalExecutorsPerResourceProfile.get(defaultRp) | ||
| } | ||
| } catch { | ||
| case e: Exception => | ||
| logWarning("Failed to get requestedTotalExecutors of Default ResourceProfile", e) | ||
| None | ||
| } | ||
| case _ => None | ||
| } | ||
| } | ||
|
|
||
| @transient private val queryStageOptimizerRules: Seq[Rule[SparkPlan]] = Seq( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql | ||
|
|
||
| import org.apache.spark.SparkConf | ||
| import org.scalatest.time.{Minutes, Span} | ||
|
|
||
| import org.apache.kyuubi.sql.KyuubiSQLConf | ||
| import org.apache.kyuubi.tags.SparkLocalClusterTest | ||
|
|
||
| @SparkLocalClusterTest | ||
| class FinalStageResourceManagerSuite extends KyuubiSparkSQLExtensionTest { | ||
|
|
||
| override def sparkConf(): SparkConf = { | ||
| // It is difficult to run spark in local-cluster mode when spark.testing is set. | ||
| sys.props.remove("spark.testing") | ||
|
|
||
| super.sparkConf().set("spark.master", "local-cluster[3, 1, 1024]") | ||
| .set("spark.dynamicAllocation.enabled", "true") | ||
| .set("spark.dynamicAllocation.initialExecutors", "3") | ||
| .set("spark.dynamicAllocation.minExecutors", "1") | ||
| .set("spark.dynamicAllocation.shuffleTracking.enabled", "true") | ||
| .set(KyuubiSQLConf.FINAL_STAGE_CONFIG_ISOLATION.key, "true") | ||
| .set(KyuubiSQLConf.FINAL_WRITE_STAGE_EAGERLY_KILL_EXECUTORS_ENABLED.key, "true") | ||
| } | ||
|
|
||
| test("[KYUUBI #5136][Bug] Final Stage hangs forever") { | ||
| // Prerequisite to reproduce the bug: | ||
| // 1. Dynamic allocation is enabled. | ||
| // 2. Dynamic allocation min executors is 1. | ||
| // 3. target executors < active executors. | ||
| // 4. No active executor is left after FinalStageResourceManager killed executors. | ||
| // This is possible because FinalStageResourceManager retained executors may already be | ||
| // requested to be killed but not died yet. | ||
| // 5. Final Stage required executors is 1. | ||
| withSQLConf( | ||
| (KyuubiSQLConf.FINAL_WRITE_STAGE_EAGERLY_KILL_EXECUTORS_KILL_ALL.key, "true")) { | ||
| withTable("final_stage") { | ||
| eventually(timeout(Span(10, Minutes))) { | ||
| sql( | ||
| "CREATE TABLE final_stage AS SELECT id, count(*) as num FROM (SELECT 0 id) GROUP BY id") | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| } | ||
| } | ||
| } | ||
| } | ||
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.
Task serialized by Spark 3.3 Driver can not be deserialized by Spark 3.1.3 Executor