markusthoemmes commented on a change in pull request #2531: Share bookkeeping 
data across controllers
URL: 
https://github.com/apache/incubator-openwhisk/pull/2531#discussion_r138258821
 
 

 ##########
 File path: 
core/controller/src/main/scala/whisk/core/loadBalancer/LoadBalancerData.scala
 ##########
 @@ -17,107 +17,130 @@
 
 package whisk.core.loadBalancer
 
-import java.util.concurrent.atomic.AtomicInteger
-
+import akka.actor.ActorSystem
+import akka.util.Timeout
+import akka.pattern.ask
+import akka.event.Logging
+import whisk.core.entity.{ActivationId, UUID}
 import scala.collection.concurrent.TrieMap
-import scala.concurrent.Promise
-
-import whisk.core.entity.{ActivationId, UUID, WhiskActivation}
-import whisk.core.entity.InstanceId
+import scala.concurrent.Future
+import scala.concurrent.duration._
+import scala.concurrent.ExecutionContext.Implicits.global
 
-/** Encapsulates data relevant for a single activation */
-case class ActivationEntry(id: ActivationId,
-                           namespaceId: UUID,
-                           invokerName: InstanceId,
-                           promise: Promise[Either[ActivationId, 
WhiskActivation]])
-
-/**
- * Encapsulates data used for loadbalancer and active-ack bookkeeping.
- *
- * Note: The state keeping is backed by concurrent data-structures. As such,
- * concurrent reads can return stale values (especially the counters returned).
- */
-class LoadBalancerData() {
-
-  private val activationByInvoker = TrieMap[InstanceId, AtomicInteger]()
-  private val activationByNamespaceId = TrieMap[UUID, AtomicInteger]()
-  private val activationsById = TrieMap[ActivationId, ActivationEntry]()
-  private val totalActivations = new AtomicInteger(0)
+trait BookkeepingData {
 
   /** Get the number of activations across all namespaces. */
-  def totalActivationCount = totalActivations.get
+  def totalActivationCount: Future[Int]
 
   /**
    * Get the number of activations for a specific namespace.
    *
    * @param namespace The namespace to get the activation count for
    * @return a map (namespace -> number of activations in the system)
    */
-  def activationCountOn(namespace: UUID) = {
-    activationByNamespaceId.get(namespace).map(_.get).getOrElse(0)
-  }
+  def activationCountOn(namespace: UUID): Future[Int]
 
   /**
-   * Get the number of activations for a specific invoker.
+   * Get the number of activations for each invoker.
    *
-   * @param invoker The invoker to get the activation count for
    * @return a map (invoker -> number of activations queued for the invoker)
    */
-  def activationCountOn(invoker: InstanceId): Int = {
-    activationByInvoker.get(invoker).map(_.get).getOrElse(0)
-  }
+  def activationCountPerInvoker: Future[Map[String, Int]]
 
 Review comment:
   I'd rather keep the interface strictly typed to `InstanceId`. Can we hide 
the underlying `String`?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Reply via email to