ningyougang commented on code in PR #5313:
URL: https://github.com/apache/openwhisk/pull/5313#discussion_r949738931


##########
core/scheduler/src/main/scala/org/apache/openwhisk/core/scheduler/container/ContainerManager.scala:
##########
@@ -360,6 +337,100 @@ object ContainerManager {
    */
   def rng(mod: Int): Int = ThreadLocalRandom.current().nextInt(mod)
 
+  // Partition messages that can use warmed containers.
+  // return: (list of messages that cannot use warmed containers, list of 
messages that can take advantage of warmed containers)
+  protected[container] def filterWarmedCreations(warmedContainers: Set[String],
+                                                 inProgressWarmedContainers: 
TrieMap[String, String],
+                                                 invokers: List[InvokerHealth],
+                                                 msgs: 
List[ContainerCreationMessage])(
+    implicit logging: Logging): (List[(ContainerCreationMessage, Option[Int], 
Option[String])],
+                                 List[(ContainerCreationMessage, Option[Int], 
Option[String])]) = {
+    val warmedApplied = msgs.map { msg =>
+      val warmedPrefix =
+        containerPrefix(ContainerKeys.warmedPrefix, msg.invocationNamespace, 
msg.action, Some(msg.revision))
+      val container = warmedContainers
+        .filter(!inProgressWarmedContainers.values.toSeq.contains(_))
+        .flatMap { container =>
+          if (container.startsWith(warmedPrefix)) {
+            logging.info(this, s"Choose a warmed container $container")
+
+            // this is required to exclude already chosen invokers
+            inProgressWarmedContainers.update(msg.creationId.asString, 
container)
+            Some(container)
+          } else
+            None
+        }
+
+      // chosenInvoker is supposed to have only one item
+      val chosenInvoker = container
+        .map(_.split("/").takeRight(3).apply(0))
+        // filter warmed containers in disabled invokers
+        .filter(
+          invoker =>
+            invokers
+            // filterWarmedCreations method is supposed to receive healthy 
invokers only but this will make sure again only healthy invokers are used.
+              .filter(invoker => invoker.status.isUsable)

Review Comment:
   For 99% situations, i think it  would be ok.
   
   But in some extreme case, i am not sue what will happen. e. g.
   
   Due to time difference
   * time1, here, the invoker is usable.
   * time2 CreationMessage is send to that invoker via kafka
   * time3, user sends /disable to that invoker but invoker received the 
message from kafka
   
   Then, what will happen?



-- 
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

Reply via email to