Ngone51 commented on code in PR #36716: URL: https://github.com/apache/spark/pull/36716#discussion_r890949860
########## core/src/main/scala/org/apache/spark/deploy/master/ApplicationInfo.scala: ########## @@ -65,7 +66,70 @@ private[spark] class ApplicationInfo( appSource = new ApplicationSource(this) nextExecutorId = 0 removedExecutors = new ArrayBuffer[ExecutorDesc] - executorLimit = desc.initialExecutorLimit.getOrElse(Integer.MAX_VALUE) + val initialExecutorLimit = desc.initialExecutorLimit.getOrElse(Integer.MAX_VALUE) + + rpIdToResourceProfile = new mutable.HashMap[Int, ResourceProfile]() + rpIdToResourceProfile(DEFAULT_RESOURCE_PROFILE_ID) = desc.defaultProfile + rpIdToResourceDesc = new mutable.HashMap[Int, ExecutorResourceDescription]() + createResourceDescForResourceProfile(desc.defaultProfile) + + targetNumExecutorsPerResourceProfileId = new mutable.HashMap[Int, Int]() + targetNumExecutorsPerResourceProfileId(DEFAULT_RESOURCE_PROFILE_ID) = initialExecutorLimit + + executorsPerResourceProfileId = new mutable.HashMap[Int, mutable.Set[Int]]() + } + + private[deploy] def getOrUpdateExecutorsForRPId(rpId: Int): mutable.Set[Int] = { + executorsPerResourceProfileId.getOrElseUpdate(rpId, mutable.HashSet[Int]()) + } + + private[deploy] def getTargetExecutorNumForRPId(rpId: Int): Int = { + targetNumExecutorsPerResourceProfileId.getOrElse(rpId, 0) + } + + private[deploy] def getRequestedRPIds(): Seq[Int] = { + rpIdToResourceProfile.keys.toSeq.sorted + } + + private def createResourceDescForResourceProfile(resourceProfile: ResourceProfile): Unit = { + if (!rpIdToResourceDesc.contains(resourceProfile.id)) { + val defaultMemoryMbPerExecutor = desc.memoryPerExecutorMB + val defaultCoresPerExecutor = desc.coresPerExecutor + val coresPerExecutor = resourceProfile.getExecutorCores + .orElse(defaultCoresPerExecutor) + val memoryMbPerExecutor = resourceProfile.getExecutorMemory + .map(_.toInt) + .getOrElse(defaultMemoryMbPerExecutor) + val customResources = ResourceUtils.executorResourceRequestToRequirement( + getCustomExecutorResources(resourceProfile).values.toSeq) + + rpIdToResourceDesc(resourceProfile.id) = + ExecutorResourceDescription(coresPerExecutor, memoryMbPerExecutor, customResources) + } + } + + // Get resources required for schedule. + private[deploy] def getResourceDescriptionForRpId(rpId: Int): ExecutorResourceDescription = { + rpIdToResourceDesc(rpId) + } + + private[deploy] def requestExecutors( + resourceProfileToTotalExecs: Map[ResourceProfile, Int]): Unit = { + resourceProfileToTotalExecs.foreach { case (rp, num) => + createResourceDescForResourceProfile(rp) + + if (!rpIdToResourceProfile.contains(rp.id)) { + rpIdToResourceProfile(rp.id) = rp + } + + if (!targetNumExecutorsPerResourceProfileId.get(rp.id).contains(num)) { + targetNumExecutorsPerResourceProfileId(rp.id) = num + } Review Comment: How about: ```suggestion targetNumExecutorsPerResourceProfileId(rp.id) = num ``` -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org