upgle commented on code in PR #5313: URL: https://github.com/apache/openwhisk/pull/5313#discussion_r950009854
########## core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/FPCInvokerReactive.scala: ########## @@ -376,34 +376,21 @@ class FPCInvokerReactive(config: WhiskConfig, override def enable(): Route = { invokerHealthManager ! Enable pool ! Enable - // re-enable consumer - if (consumer.isEmpty) - consumer = Some( - new ContainerMessageConsumer( - instance, - pool, - entityStore, - cfg, - msgProvider, - longPollDuration = 1.second, - maxPeek, - sendAckToScheduler)) warmUp() complete("Success enable invoker") } override def disable(): Route = { invokerHealthManager ! GracefulShutdown pool ! GracefulShutdown - consumer.foreach(_.close()) - consumer = None Review Comment: Even if the invoker is disabled, it handles messages that may come in for a while. 👍 ########## core/scheduler/src/main/scala/org/apache/openwhisk/core/scheduler/container/ContainerManager.scala: ########## @@ -157,43 +139,66 @@ class ContainerManager(jobManagerFactory: ActorRefFactory => ActorRef, case _ => } - private def createContainer(msgs: List[ContainerCreationMessage], - memory: ByteSize, - invocationNamespace: String): Unit = { + private def createContainer(msgs: List[ContainerCreationMessage], memory: ByteSize, invocationNamespace: String)( + implicit logging: Logging): Unit = { logging.info(this, s"received ${msgs.size} creation message [${msgs.head.invocationNamespace}:${msgs.head.action}]") - val coldCreations = filterWarmedCreations(msgs) - if (coldCreations.nonEmpty) - ContainerManager - .getAvailableInvokers(etcdClient, memory, invocationNamespace) - .flatMap { invokers => - if (invokers.isEmpty) { - coldCreations.foreach { msg => - ContainerManager.sendState( - FailedCreationJob( - msg.creationId, - msg.invocationNamespace, - msg.action, - msg.revision, - NoAvailableInvokersError, - s"No available invokers.")) - } - Future.failed(NoCapacityException("No available invokers.")) - } else { - coldCreations.foreach { msg => - creationJobManager ! RegisterCreationJob(msg) - } + ContainerManager + .getAvailableInvokers(etcdClient, memory, invocationNamespace) + .foreach { invokers => + if (invokers.isEmpty) { + msgs.foreach(ContainerManager.sendState(_, NoAvailableInvokersError, s"No available invokers.")) + } else { + val (coldCreations, warmedCreations) = + ContainerManager.filterWarmedCreations(warmedContainers, inProgressWarmedContainers, invokers, msgs) + + // handle warmed creation + val chosenInvokers: immutable.Seq[Option[(Int, ContainerCreationMessage)]] = warmedCreations.map { + warmedCreation => + // update the in-progress map for warmed containers + // even if it is done in the filterWarmedCreations method, it is still necessary to apply the change to the original map + warmedCreation._3.foreach(inProgressWarmedContainers.update(warmedCreation._1.creationId.asString, _)) + + // send creation message to the target invoker + warmedCreation._2 map { chosenInvoker => + val msg = warmedCreation._1 + creationJobManager ! RegisterCreationJob(msg) + sendCreationContainerToInvoker(messagingProducer, chosenInvoker, msg) + (chosenInvoker, msg) + } + } - Future { - ContainerManager - .schedule(invokers, coldCreations, memory) - .map { pair => - sendCreationContainerToInvoker(messagingProducer, pair.invokerId.toInt, pair.msg) - } + // update the resource usage of invokers to apply changes from warmed creations. + val updatedInvokers = chosenInvokers.foldLeft(invokers) { (invokers, chosenInvoker) => + chosenInvoker match { + case Some((chosenInvoker, msg)) => + updateInvokerMemory(chosenInvoker, msg.whiskActionMetaData.limits.memory.megabytes, invokers) + case _ => + invokers } - }.andThen { - case Failure(t) => logging.warn(this, s"Failed to create container caused by: $t") Review Comment: Shouldn't we need a warning log for failure cases like "No available invokers"? -- 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