raviston commented on code in PR #60383:
URL: https://github.com/apache/spark/pull/60383#discussion_r4550929489
##########
core/src/main/scala/org/apache/spark/scheduler/TaskSchedulerImpl.scala:
##########
@@ -1179,6 +1195,16 @@ private[spark] class TaskSchedulerImpl(
}
}
+ for {
+ executorsByHost <- resourceProfileIdToHostToExecutors.values
Review Comment:
This cleanup isn't covered either. If I delete this block, every test still
passes. This case fails without it, because the lost executor is still counted
as a compatible candidate, so it is "killed" and the abort timer starts:
```scala
test("SPARK-45537: a lost executor is not a recovery candidate") {
taskScheduler = setupSchedulerWithMockTaskSetExcludelist(
config.DYN_ALLOCATION_ENABLED.key -> "true",
config.UNSCHEDULABLE_TASKSET_TIMEOUT.key -> "60")
val profile = new ResourceProfile(
new ExecutorResourceRequests().cores(1).memory("2g").requests,
new TaskResourceRequests().cpus(1).requests)
sc.resourceProfileManager.addResourceProfile(profile)
val excludedOffer = WorkerOffer("excluded", "host0", 1,
resourceProfileId = profile.id)
val otherOffer = WorkerOffer("other", "host0", 1)
taskScheduler.resourceOffers(IndexedSeq(excludedOffer, otherOffer))
taskScheduler.submitTasks(FakeTask.createTaskSet(1, profile.id))
val tsm = stageToMockTaskSetManager(0)
val task =
taskScheduler.resourceOffers(IndexedSeq(excludedOffer)).flatten.head
failTask(task.taskId, TaskState.FAILED, UnknownReason, tsm)
when(tsm.taskSetExcludelistHelperOpt.get.isExecutorExcludedForTaskSet("excluded"))
.thenReturn(true)
taskScheduler.executorLost("excluded", ExecutorProcessLost())
// No compatible executor is left, so wait for one, as before any
executor registers.
assert(taskScheduler.resourceOffers(IndexedSeq(otherOffer)).flatten.isEmpty)
verify(healthTracker, never()).killExcludedIdleExecutor(any())
assert(!taskScheduler.unschedulableTaskSetToExpiryTime.contains(tsm))
assert(!tsm.isZombie)
}
```
##########
core/src/main/scala/org/apache/spark/scheduler/TaskSchedulerImpl.scala:
##########
@@ -695,8 +710,9 @@ private[spark] class TaskSchedulerImpl(
// If there are no idle executors and dynamic allocation is
enabled, then we would
// notify ExecutorAllocationManager to allocate more executors
to schedule the
// unschedulable tasks else we will abort immediately.
- executorIdToRunningTaskIds.find(x => !isExecutorBusy(x._1))
match {
- case Some ((executorId, _)) =>
+ hostToExecutorsForTaskSet.valuesIterator.flatMap(_.iterator)
Review Comment:
The new tests don't cover this change. If I put back
`executorIdToRunningTaskIds.find(x => !isExecutorBusy(x._1))`, all three new
tests still pass: in them both executors are idle, and the hash order happens
to pick `excluded`.
A case where the compatible executor is busy and only the incompatible one
is idle catches it. With the old search it kills `other`, and with this PR it
takes the no-idle-executor path:
```scala
test("SPARK-45537: do not kill an idle executor of another resource
profile") {
taskScheduler = setupSchedulerWithMockTaskSetExcludelist(
config.DYN_ALLOCATION_ENABLED.key -> "true",
config.UNSCHEDULABLE_TASKSET_TIMEOUT.key -> "60")
val profile = new ResourceProfile(
new ExecutorResourceRequests().cores(2).memory("2g").requests,
new TaskResourceRequests().cpus(1).requests)
sc.resourceProfileManager.addResourceProfile(profile)
val excludedOffer = WorkerOffer("excluded", "host0", 2,
resourceProfileId = profile.id)
val otherOffer = WorkerOffer("other", "host0", 1)
taskScheduler.resourceOffers(IndexedSeq(excludedOffer, otherOffer))
taskScheduler.submitTasks(FakeTask.createTaskSet(2, profile.id))
val tsm = stageToMockTaskSetManager(0)
val tasks =
taskScheduler.resourceOffers(IndexedSeq(excludedOffer)).flatten
assert(tasks.size === 2)
// One task fails, and the other one keeps "excluded" busy.
failTask(tasks.head.taskId, TaskState.FAILED, UnknownReason, tsm)
when(tsm.taskSetExcludelistHelperOpt.get.isExecutorExcludedForTaskSet("excluded"))
.thenReturn(true)
assert(taskScheduler.resourceOffers(IndexedSeq(otherOffer)).flatten.isEmpty)
verify(healthTracker, never()).killExcludedIdleExecutor(any())
// Dynamic allocation does not take effect with a local master, so it
aborts right away.
assert(tsm.isZombie)
assert(failedTaskSet)
}
```
I checked that it passes with this PR and fails both on master and with only
this line reverted.
##########
core/src/main/scala/org/apache/spark/scheduler/TaskSchedulerImpl.scala:
##########
@@ -679,7 +686,15 @@ private[spark] class TaskSchedulerImpl(
}
if (!launchedAnyTask) {
- taskSet.getCompletelyExcludedTaskIfAny(hostToExecutors).foreach {
taskIndex =>
+ val taskRpId = taskSet.taskSet.resourceProfileId
+ val defaultRpId = ResourceProfile.DEFAULT_RESOURCE_PROFILE_ID
+ // Task-only profiles can reuse default executors without dynamic
allocation.
+ val executorRpId =
+ if (sc.resourceProfileManager.canBeScheduled(taskRpId,
defaultRpId)) defaultRpId
Review Comment:
Optional: this picks a single executor profile by repeating the rule in
`ResourceProfileManager.canBeScheduled`. Could it instead use every profile `p`
in `resourceProfileIdToHostToExecutors.keys` with `canBeScheduled(taskRpId,
p)`? Then it can't drift from the check in `resourceOfferSingleTaskSet` if that
rule changes, for example if task-only profiles can reuse default executors
with dynamic allocation on. There are only a few profiles, so the lookup is
cheap. `getCompletelyExcludedTaskIfAny` would then need to take more than one
map, or an `Iterable[(String, HashSet[String])]`. The `forall` there stays
correct when a host shows up once per profile.
With the current rules, the two forms give the same result, so I'm fine
leaving it as is.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]