Skip to content

Commit ce6487a

Browse files
author
Andrew Or
committed
Allow requesting / killing executors only in YARN mode
1 parent 15cf3b0 commit ce6487a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

core/src/main/scala/org/apache/spark/SparkContext.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,12 @@ class SparkContext(config: SparkConf) extends Logging {
357357
}
358358

359359
// Optionally scale number of executors dynamically based on workload. Exposed for testing.
360+
private val dynamicAllocationEnabled = conf.getBoolean("spark.dynamicAllocation.enabled", false)
361+
private val dynamicAllocationTesting = conf.getBoolean("spark.dynamicAllocation.testing", false)
360362
private[spark] val executorAllocationManager: Option[ExecutorAllocationManager] =
361-
if (conf.getBoolean("spark.dynamicAllocation.enabled", false)) {
363+
if (dynamicAllocationEnabled) {
364+
assert(master.contains("yarn") || dynamicAllocationTesting,
365+
"Dynamic allocation of executors is currently only supported in YARN mode")
362366
Some(new ExecutorAllocationManager(this))
363367
} else {
364368
None
@@ -989,6 +993,8 @@ class SparkContext(config: SparkConf) extends Logging {
989993
*/
990994
@DeveloperApi
991995
def requestExecutors(numAdditionalExecutors: Int): Boolean = {
996+
assert(master.contains("yarn") || dynamicAllocationTesting,
997+
"Requesting executors is currently only supported in YARN mode")
992998
schedulerBackend match {
993999
case b: CoarseGrainedSchedulerBackend =>
9941000
b.requestExecutors(numAdditionalExecutors)
@@ -1005,6 +1011,8 @@ class SparkContext(config: SparkConf) extends Logging {
10051011
*/
10061012
@DeveloperApi
10071013
def killExecutors(executorIds: Seq[String]): Boolean = {
1014+
assert(master.contains("yarn") || dynamicAllocationTesting,
1015+
"Killing executors is currently only supported in YARN mode")
10081016
schedulerBackend match {
10091017
case b: CoarseGrainedSchedulerBackend =>
10101018
b.killExecutors(executorIds)

core/src/test/scala/org/apache/spark/ExecutorAllocationManagerSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ExecutorAllocationManagerSuite extends FunSuite with LocalSparkContext {
3535
.setMaster("local")
3636
.setAppName("test-executor-allocation-manager")
3737
.set("spark.dynamicAllocation.enabled", "true")
38+
.set("spark.dynamicAllocation.testing", "true")
3839
intercept[SparkException] { new SparkContext(conf) }
3940
SparkEnv.get.stop() // cleanup the created environment
4041
SparkContext.clearActiveContext()

0 commit comments

Comments
 (0)