You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2020/11/10 05:41:28 UTC

[GitHub] [openwhisk] bdoyle0182 commented on a change in pull request #5024: Reset / Overwrite invokerId for unique name in zookeeper manually

bdoyle0182 commented on a change in pull request #5024:
URL: https://github.com/apache/openwhisk/pull/5024#discussion_r520299983



##########
File path: core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/InstanceIdAssigner.scala
##########
@@ -38,34 +38,41 @@ private[invoker] class InstanceIdAssigner(connectionString: String)(implicit log
     logger.info(this, "invokerReg: connected to zookeeper")
 
     val myIdPath = "/invokers/idAssignment/mapping/" + name
-    val assignedId = Option(zkClient.checkExists().forPath(myIdPath)) match {
-      case None =>
-        // path doesn't exist -> no previous mapping for this invoker
-        logger.info(this, s"invokerReg: no prior assignment of id for invoker $name")
-        val idCounter = new SharedCount(zkClient, "/invokers/idAssignment/counter", 0)
-        idCounter.start()
+    val assignedId = if (overwriteId.isEmpty) {
+      Option(zkClient.checkExists().forPath(myIdPath)) match {
+        case None =>
+          // path doesn't exist -> no previous mapping for this invoker
+          logger.info(this, s"invokerReg: no prior assignment of id for invoker $name")
+          val idCounter = new SharedCount(zkClient, "/invokers/idAssignment/counter", 0)
+          idCounter.start()
 
-        def assignId(): Int = {
-          val current = idCounter.getVersionedValue()
-          if (idCounter.trySetCount(current, current.getValue() + 1)) {
-            current.getValue()
-          } else {
-            assignId()
+          def assignId(): Int = {
+            val current = idCounter.getVersionedValue()
+            if (idCounter.trySetCount(current, current.getValue() + 1)) {
+              current.getValue()
+            } else {
+              assignId()
+            }
           }
-        }
 
-        val newId = assignId()
-        idCounter.close()
-        zkClient.create().creatingParentContainersIfNeeded().forPath(myIdPath, BigInt(newId).toByteArray)
-        logger.info(this, s"invokerReg: invoker $name was assigned invokerId $newId")
-        newId
+          val newId = assignId()
+          idCounter.close()
+          zkClient.create().creatingParentContainersIfNeeded().forPath(myIdPath, BigInt(newId).toByteArray)
+          logger.info(this, s"invokerReg: invoker $name was assigned invokerId $newId")
+          newId
 
-      case Some(_) =>
-        // path already exists -> there is a previous mapping for this invoker we should use
-        val rawOldId = zkClient.getData().forPath(myIdPath)
-        val oldId = BigInt(rawOldId).intValue
-        logger.info(this, s"invokerReg: invoker $name was assigned its previous invokerId $oldId")
-        oldId
+        case Some(_) =>
+          // path already exists -> there is a previous mapping for this invoker we should use
+          val rawOldId = zkClient.getData().forPath(myIdPath)
+          val oldId = BigInt(rawOldId).intValue
+          logger.info(this, s"invokerReg: invoker $name was assigned its previous invokerId $oldId")
+          oldId
+      }
+    } else {
+      val newId = overwriteId.get

Review comment:
       sounds good




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org