style95 commented on code in PR #5313: URL: https://github.com/apache/openwhisk/pull/5313#discussion_r949791350
########## core/scheduler/src/main/scala/org/apache/openwhisk/core/scheduler/container/ContainerManager.scala: ########## @@ -462,32 +539,30 @@ object ContainerManager { list } - private def chooseInvokerFromCandidates( - candidates: List[InvokerHealth], - wholeInvokers: List[InvokerHealth], - pairs: List[ScheduledPair], - msg: ContainerCreationMessage)(implicit logging: Logging): (List[ScheduledPair], List[InvokerHealth]) = { - val idx = rng(mod = candidates.size) - val instance = candidates(idx) - // it must be compared to the instance unique id - val idxInWhole = wholeInvokers.indexOf(wholeInvokers.filter(p => p.id.instance == instance.id.instance).head) - val requiredMemory = msg.whiskActionMetaData.limits.memory.megabytes - val updated = - if (instance.id.userMemory.toMB - requiredMemory >= requiredMemory) { // Since ByteSize is negative, it converts to long type and compares. - wholeInvokers.updated( - idxInWhole, - instance.copy(id = instance.id.copy(userMemory = instance.id.userMemory - requiredMemory.MB))) + @tailrec + protected[container] def chooseInvokerFromCandidates(candidates: List[InvokerHealth], msg: ContainerCreationMessage)( + implicit logging: Logging): ScheduledPair = { + val requiredMemory = msg.whiskActionMetaData.limits.memory + if (candidates.isEmpty) { + ScheduledPair(msg, invokerId = None, Some(NoAvailableInvokersError), Some(s"No available invokers.")) + } else if (candidates.forall(p => p.id.userMemory.toMB < requiredMemory.megabytes)) { + ScheduledPair(msg, invokerId = None, Some(NoAvailableInvokersError), Some(s"No available invokers.")) Review Comment: So do you suggest adding a new error? -- 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: issues-unsubscr...@openwhisk.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org