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 2021/05/10 10:02:17 UTC

[GitHub] [openwhisk] jiangpengcheng commented on a change in pull request #4986: Implement action versioning

jiangpengcheng commented on a change in pull request #4986:
URL: https://github.com/apache/openwhisk/pull/4986#discussion_r629230749



##########
File path: common/scala/src/main/scala/org/apache/openwhisk/core/entity/WhiskAction.scala
##########
@@ -346,6 +358,74 @@ case class ExecutableWhiskActionMetaData(namespace: EntityPath,
 
 }
 
+case class WhiskActionVersion(id: String, namespace: EntityPath, name: EntityName, version: SemVer)
+
+object WhiskActionVersion {
+  val serdes = jsonFormat4(WhiskActionVersion.apply)
+}
+
+case class WhiskActionVersionList(namespace: EntityPath, name: EntityName, versions: Map[SemVer, String]) {
+  def matchedDocId(version: Option[SemVer]): Option[DocId] = {
+    version match {
+      case Some(ver) =>
+        versions.get(ver).map(DocId(_))
+      case None if versions.nonEmpty =>
+        Some(DocId(versions.maxBy(_._1.toString)._2))
+      case _ =>
+        None
+    }
+  }
+}
+
+object WhiskActionVersionList extends MultipleReadersSingleWriterCache[WhiskActionVersionList, DocInfo] {
+  lazy val viewName = WhiskQueries.entitiesView(collection = "action-versions").name
+
+  def cacheKey(action: FullyQualifiedEntityName): CacheKey = {
+    CacheKey(action.fullPath.asString)
+  }
+
+  def get(action: FullyQualifiedEntityName, datastore: EntityStore)(
+    implicit transId: TransactionId): Future[WhiskActionVersionList] = {
+    implicit val logger: Logging = datastore.logging
+    implicit val ec = datastore.executionContext
+
+    val key = List(action.fullPath.asString)
+    cacheLookup(
+      cacheKey(action),
+      datastore
+        .query(
+          viewName,
+          startKey = key,
+          endKey = key,
+          skip = 0,
+          limit = 0,
+          includeDocs = false,
+          descending = false,
+          reduce = false,
+          stale = StaleParameter.No)
+        .map { result =>
+          val values = result.map { row =>
+            row.fields("value").asJsObject()
+          }
+          val mappings = values
+            .map(WhiskActionVersion.serdes.read(_))
+            .map { actionVersion =>
+              (actionVersion.version, actionVersion.id)
+            }
+            .toMap
+          WhiskActionVersionList(action.namespace.toPath, action.name, mappings)
+        })
+  }
+
+  // delete cache
+  def deleteCache(action: FullyQualifiedEntityName)(implicit transId: TransactionId,

Review comment:
       I override the `evictionPolicy: EvictionPolicy = WriteTime`, so event there is an error in kafka while delete cache, versions data will eventually consistent 




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