chetanmeh commented on a change in pull request #3453: Introduce a 
AttachmentStore SPI
URL: 
https://github.com/apache/incubator-openwhisk/pull/3453#discussion_r176368963
 
 

 ##########
 File path: 
common/scala/src/main/scala/whisk/core/database/memory/MemoryAttachmentStore.scala
 ##########
 @@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package whisk.core.database.memory
+
+import akka.actor.ActorSystem
+import akka.event.Logging.ErrorLevel
+import akka.http.scaladsl.model.ContentType
+import akka.stream.{ActorMaterializer, OverflowStrategy, QueueOfferResult}
+import akka.stream.scaladsl.{Keep, Sink, Source}
+import akka.util.{ByteString, ByteStringBuilder}
+import whisk.common.{Logging, StartMarker, TransactionId}
+import whisk.common.LoggingMarkers.DATABASE_ATT_GET
+import whisk.common.LoggingMarkers.DATABASE_ATT_SAVE
+import whisk.common.LoggingMarkers.DATABASE_ATT_DELETE
+import whisk.core.database._
+import whisk.core.entity.{DocId, DocInfo}
+
+import scala.concurrent.{ExecutionContext, Future, Promise}
+import scala.reflect.ClassTag
+
+object MemoryAttachmentStoreProvider extends AttachmentStoreProvider {
+  override def makeStore[D <: DocumentSerializer: ClassTag]()(implicit 
actorSystem: ActorSystem,
+                                                              logging: Logging,
+                                                              materializer: 
ActorMaterializer): AttachmentStore =
+    new 
MemoryAttachmentStore(implicitly[ClassTag[D]].runtimeClass.getSimpleName.toLowerCase)
+}
+
+class MemoryAttachmentStore(dbName: String)(implicit system: ActorSystem,
+                                            logging: Logging,
+                                            materializer: ActorMaterializer)
+    extends AttachmentStore {
+
+  override protected[core] implicit val executionContext: ExecutionContext = 
system.dispatcher
+
+  private sealed trait Action {
+    def doc: DocInfo
+  }
+  private case class AddAction(doc: DocInfo, name: String, attachment: 
Attachment) extends Action
+  private case class DelAction(doc: DocInfo) extends Action
+  private case class Attachment(bytes: ByteString, contentType: ContentType)
+
+  @volatile
+  private var attachments: Map[String, Attachment] = Map()
 
 Review comment:
   Did not knew about `TrieMap`. Thanks for the tip!. Now the 
`MemoryAttachmentStore` implementation is much simpler. 
   
   > Second, attachments can be large. This Map has no bound on its size and 
can grow to OOM the controller
   
   Purpose of memory store is to facilitate testing and there also each test 
would have its own instance. So we can keep it simple with assumption that 
tests would not be storing very large binaries in it.
   
   To make it more explicit (i.e. it is meant for test) I have moved the logic 
to tests module

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to