squito commented on a change in pull request #24817: [SPARK-27963][core] Allow
dynamic allocation without a shuffle service.
URL: https://github.com/apache/spark/pull/24817#discussion_r298261108
##########
File path:
core/src/main/scala/org/apache/spark/scheduler/dynalloc/ExecutorMonitor.scala
##########
@@ -124,6 +149,98 @@ private[spark] class ExecutorMonitor(
def pendingRemovalCount: Int = executors.asScala.count { case (_, exec) =>
exec.pendingRemoval }
+ override def onJobStart(event: SparkListenerJobStart): Unit = {
+ if (!shuffleTrackingEnabled) {
+ return
+ }
+
+ val shuffleStages = event.stageInfos.flatMap { s =>
+ s.shuffleDepId.toSeq.map { shuffleId =>
+ s.stageId -> shuffleId
+ }
+ }
+
+ var updateExecutors = false
+ shuffleStages.foreach { case (stageId, shuffle) =>
+ val jobIDs = shuffleToActiveJobs.get(shuffle) match {
+ case Some(jobs) =>
+ // If a shuffle is being re-used, we need to re-scan the executors
and update their
+ // tracker with the information that the shuffle data they're
storing is in use.
+ logDebug(s"Reusing shuffle $shuffle in job ${event.jobId}.")
+ updateExecutors = true
+ jobs
+
+ case _ =>
+ logDebug(s"Registered new shuffle $shuffle (from stage $stageId).")
+ val jobs = new mutable.ArrayBuffer[Int]()
+ shuffleToActiveJobs(shuffle) = jobs
+ jobs
+ }
+ jobIDs += event.jobId
+ }
+
+ if (updateExecutors) {
+ val activeShuffleIds = shuffleStages.map(_._2).toSeq
+ var needTimeoutUpdate = false
+ executors.asScala.foreach { case (id, exec) =>
+ if (!exec.hasActiveShuffle) {
+ exec.updateActiveShuffles(activeShuffleIds)
+ if (exec.hasActiveShuffle) {
+ logDebug(s"Executor $id has data needed by new active job.")
+ needTimeoutUpdate = true
+ }
+ }
+ }
+
+ if (needTimeoutUpdate) {
+ nextTimeout.set(Long.MinValue)
+ }
+ }
+
+ stageToShuffleID ++= shuffleStages
+ jobToStageIDs(event.jobId) = shuffleStages.map(_._1).toSeq
+ }
+
+ override def onJobEnd(event: SparkListenerJobEnd): Unit = {
+ if (!shuffleTrackingEnabled) {
+ return
+ }
+
+ var updateExecutors = false
+ val activeShuffles = new mutable.ArrayBuffer[Int]()
+ shuffleToActiveJobs.foreach { case (shuffleId, jobs) =>
+ jobs -= event.jobId
+ if (jobs.nonEmpty) {
+ activeShuffles += shuffleId
+ } else {
+ // If a shuffle went idle we need to update all executors to make sure
they're correctly
+ // tracking active shuffles.
+ updateExecutors = true
+ }
+ }
+
+ if (updateExecutors) {
+ if (log.isDebugEnabled()) {
+ if (activeShuffles.nonEmpty) {
+ logDebug(
+ s"Job ${event.jobId} ended, shuffles
${activeShuffles.mkString(",")} still active.")
+ } else {
+ logDebug(s"Job ${event.jobId} ended, no active shuffles remain.")
+ }
+ }
+
+ executors.asScala.foreach { case (id, exec) =>
+ if (exec.hasActiveShuffle) {
+ exec.updateActiveShuffles(activeShuffles)
Review comment:
is it worthwhile to logdebug here too? (with similar comment to above for
combining them)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]