dgrove-oss commented on a change in pull request #2689: first stage of support 
for dynamic invoker id assignment
URL: 
https://github.com/apache/incubator-openwhisk/pull/2689#discussion_r141171991
 
 

 ##########
 File path: core/invoker/src/main/scala/whisk/core/invoker/Invoker.scala
 ##########
 @@ -85,6 +86,31 @@ object Invoker {
       abort()
     }
 
+    val proposedInvokerId: Option[Int] = args.headOption.map(_.toInt)
+    val assignedInvokerId = proposedInvokerId.map { id =>
+      logger.info(this, s"invokerReg: using proposedInvokerId ${id}")
+      id
+    }.getOrElse {
+      val invokerName = config.invokerName
+      val redisClient = new RedisClient(config.redisHostName, 
config.redisHostPort.toInt)
+      val assignedId = redisClient.hget("controller:registar:idAssignments", 
invokerName).map { oldId =>
+        logger.info(this, s"invokerReg: invoker ${invokerName} was assigned 
its previous invokerId ${oldId}")
+        oldId.toInt
+      }.getOrElse {
+        // If key not present, incr initializes to 0 before applying increment.
+        // Convert from 1-based to 0-based invokerIds by subtracting 1 from 
incr's result
+        val newId = redisClient.incr("controller:registrar:nextInvokerId").map 
{ id => id.toInt - 1 }.getOrElse {
 
 Review comment:
   my understanding from reading the docs is that this just wraps the Redis 
INCR command and that internally Redis is single threaded, so there cannot be a 
need to retry. (the various INCR operations will be applied sequentially by the 
single Redis thread).
 
----------------------------------------------------------------
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