Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
code clean
  • Loading branch information
CodingCat committed Mar 4, 2014
commit f6bf93f425ce71f8d73805a6106f433fc1db15ef
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ package org.apache.spark.scheduler
* Represents free resources available on an executor.
*/
private[spark]
case class WorkerOffer(executorId: String, host: String, cores: Int);
case class WorkerOffer(executorId: String, host: String, cores: Int)
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, actorSystem: A

class DriverActor(sparkProperties: Seq[(String, String)]) extends Actor {
private val executorActor = new HashMap[String, ActorRef]
private val workerOffers = new HashMap[String, WorkerOffer]
private val executorAddress = new HashMap[String, Address]
private val executorHost = new HashMap[String, String]
private val freeCores = new HashMap[String, Int]
private val totalCores = new HashMap[String, Int]
private val addressToExecutorId = new HashMap[Address, String]
Expand All @@ -75,10 +76,10 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, actorSystem: A
logInfo("Registered executor: " + sender + " with ID " + executorId)
sender ! RegisteredExecutor(sparkProperties)
executorActor(executorId) = sender
workerOffers += (executorId ->
new WorkerOffer(executorId, Utils.parseHostPort(hostPort)._1, cores))
totalCores += (executorId -> cores)
freeCores += (executorId -> cores)
executorHost(executorId) = Utils.parseHostPort(hostPort)._1
totalCores(executorId) = cores
freeCores(executorId) = cores
executorAddress(executorId) = sender.path.address
addressToExecutorId(sender.path.address) = executorId
totalCoreCount.addAndGet(cores)
makeOffers()
Expand Down Expand Up @@ -126,18 +127,14 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, actorSystem: A

// Make fake resource offers on all executors
def makeOffers() {
// reconstruct workerOffers
workerOffers.keys.foreach { executorId =>
workerOffers(executorId) = workerOffers(executorId).copy(cores = freeCores(executorId))
}
launchTasks(scheduler.resourceOffers(workerOffers.values.toSeq))
launchTasks(scheduler.resourceOffers(
executorHost.toArray.map {case (id, host) => new WorkerOffer(id, host, freeCores(id))}))
}

// Make fake resource offers on just one executor
def makeOffers(executorId: String) {
// update the workerOffer
workerOffers(executorId) = workerOffers(executorId).copy(cores = freeCores(executorId))
launchTasks(scheduler.resourceOffers(Seq(workerOffers(executorId))))
launchTasks(scheduler.resourceOffers(
Seq(new WorkerOffer(executorId, executorHost(executorId), freeCores(executorId)))))
}

// Launch tasks returned by a set of resource offers
Expand All @@ -154,7 +151,9 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, actorSystem: A
logInfo("Executor " + executorId + " disconnected, so removing it")
val numCores = totalCores(executorId)
executorActor -= executorId
workerOffers -= executorId
executorHost -= executorId
addressToExecutorId -= executorAddress(executorId)
executorAddress -= executorId
totalCores -= executorId
freeCores -= executorId
totalCoreCount.addAndGet(-numCores)
Expand Down