Skip to content

Commit 4e51e35

Browse files
committed
Modified Master to prevent from 0 divide
1 parent 4817ecd commit 4e51e35

File tree

1 file changed

+20
-16
lines changed
  • core/src/main/scala/org/apache/spark/deploy/master

1 file changed

+20
-16
lines changed

core/src/main/scala/org/apache/spark/deploy/master/Master.scala

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -490,24 +490,28 @@ private[spark] class Master(
490490
// Randomization helps balance drivers
491491
val shuffledAliveWorkers = Random.shuffle(workers.toSeq.filter(_.state == WorkerState.ALIVE))
492492
val aliveWorkerNum = shuffledAliveWorkers.size
493-
var curPos = 0
494-
var stopPos = aliveWorkerNum
495-
for (driver <- waitingDrivers.toList) { // iterate over a copy of waitingDrivers
496-
// We assign workers to each waiting driver in a round-robin fashion. For each driver, we
497-
// start from the last worker that was assigned a driver, and continue onwards until we have
498-
// explored all alive workers.
499-
var launched = false
500-
while (curPos != stopPos && !launched) {
501-
val worker = shuffledAliveWorkers(curPos)
502-
if (worker.memoryFree >= driver.desc.mem && worker.coresFree >= driver.desc.cores) {
503-
launchDriver(worker, driver)
504-
waitingDrivers -= driver
505-
launched = true
493+
494+
if (aliveWorkerNum > 0) {
495+
var curPos = 0
496+
var stopPos = aliveWorkerNum
497+
for (driver <- waitingDrivers.toList) {
498+
// iterate over a copy of waitingDrivers
499+
// We assign workers to each waiting driver in a round-robin fashion. For each driver, we
500+
// start from the last worker that was assigned a driver, and continue onwards until we have
501+
// explored all alive workers.
502+
var launched = false
503+
while (curPos != stopPos && !launched) {
504+
val worker = shuffledAliveWorkers(curPos)
505+
if (worker.memoryFree >= driver.desc.mem && worker.coresFree >= driver.desc.cores) {
506+
launchDriver(worker, driver)
507+
waitingDrivers -= driver
508+
launched = true
509+
}
510+
curPos = (curPos + 1) % aliveWorkerNum
506511
}
507-
curPos = (curPos + 1) % aliveWorkerNum
512+
curPos = (stopPos + 1) % aliveWorkerNum
513+
stopPos = curPos + aliveWorkerNum
508514
}
509-
curPos = (stopPos + 1) % aliveWorkerNum
510-
stopPos = curPos + aliveWorkerNum
511515
}
512516

513517
// Right now this is a very simple FIFO scheduler. We keep trying to fit in the first app

0 commit comments

Comments
 (0)