markusthoemmes closed pull request #3771: Disable inlining logic if 
maxInlineSize is zero
URL: https://github.com/apache/incubator-openwhisk/pull/3771
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/common/scala/src/main/resources/application.conf 
b/common/scala/src/main/resources/application.conf
index dbc70c5fd3..233423b2e7 100644
--- a/common/scala/src/main/resources/application.conf
+++ b/common/scala/src/main/resources/application.conf
@@ -117,7 +117,7 @@ whisk {
 
         # Size limit for inlined attachments. Attachments having size less 
than this would
         # be inlined with there content encoded in attachmentName
-        max-inline-size = 16 k
+        max-inline-size = 0 k
 
         # Chunk sized for converting source of bytes to ByteString as part of 
attachment
         # upload flow
diff --git 
a/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala 
b/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala
index 44579d3bc2..853adea9c6 100644
--- a/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala
+++ b/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala
@@ -372,24 +372,34 @@ class CouchDbRestStore[DocumentAbstraction <: 
DocumentSerializer](dbProtocol: St
     update: (A, Attached) => A,
     contentType: ContentType,
     docStream: Source[ByteString, _])(implicit transid: TransactionId) = {
-    for {
-      (bytes, tailSource) <- inlineAndTail(docStream)
-      uri <- Future.successful(uriOf(bytes, UUID().asString))
-      attached <- {
-        val a = if (isInlined(uri)) {
-          Attached(uri.toString, contentType, Some(bytes.size), 
Some(digest(bytes)))
+
+    if (maxInlineSize.toBytes == 0) {
+      val uri = Uri.from(scheme = attachmentScheme, path = UUID().asString)
+      for {
+        attached <- Future.successful(Attached(uri.toString, contentType))
+        i1 <- put(update(doc, attached))
+        i2 <- attach(i1, uri.path.toString, attached.attachmentType, docStream)
+      } yield (i2, attached)
+    } else {
+      for {
+        (bytes, tailSource) <- inlineAndTail(docStream)
+        uri <- Future.successful(uriOf(bytes, UUID().asString))
+        attached <- {
+          val a = if (isInlined(uri)) {
+            Attached(uri.toString, contentType, Some(bytes.size), 
Some(digest(bytes)))
+          } else {
+            Attached(uri.toString, contentType)
+          }
+          Future.successful(a)
+        }
+        i1 <- put(update(doc, attached))
+        i2 <- if (isInlined(uri)) {
+          Future.successful(i1)
         } else {
-          Attached(uri.toString, contentType)
+          attach(i1, uri.path.toString, attached.attachmentType, 
combinedSource(bytes, tailSource))
         }
-        Future.successful(a)
-      }
-      i1 <- put(update(doc, attached))
-      i2 <- if (isInlined(uri)) {
-        Future.successful(i1)
-      } else {
-        attach(i1, uri.path.toString, attached.attachmentType, 
combinedSource(bytes, tailSource))
-      }
-    } yield (i2, attached)
+      } yield (i2, attached)
+    }
   }
 
   private def attachToExternalStore[A <: DocumentAbstraction](
diff --git 
a/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala 
b/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala
index 18fc1250f0..ce6529e197 100644
--- a/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala
@@ -859,6 +859,7 @@ class ActionsApiTests extends ControllerTestCommon with 
WhiskActionsApi {
   }
 
   it should "put and then get an action with inlined attachment" in {
+    assumeAttachmentInliningEnabled(entityStore)
     val action =
       WhiskAction(
         namespace,
diff --git a/tests/src/test/scala/whisk/core/database/test/DbUtils.scala 
b/tests/src/test/scala/whisk/core/database/test/DbUtils.scala
index 2b39fd311b..47c884a3a1 100644
--- a/tests/src/test/scala/whisk/core/database/test/DbUtils.scala
+++ b/tests/src/test/scala/whisk/core/database/test/DbUtils.scala
@@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger
 import akka.http.scaladsl.model.ContentType
 import akka.stream.scaladsl.Source
 import akka.util.ByteString
+import org.scalatest.Assertions
 import spray.json.DefaultJsonProtocol._
 import spray.json._
 import whisk.common.TransactionId
@@ -45,7 +46,7 @@ import scala.util.{Failure, Random, Success, Try}
  * operations with those that flow through the cache. To mitigate this, use 
unique asset
  * names in tests, and defer all cleanup to the end of a test suite.
  */
-trait DbUtils {
+trait DbUtils extends Assertions {
   implicit val dbOpTimeout = 15 seconds
   val instance = InstanceId(0)
   val docsToDelete = ListBuffer[(ArtifactStore[_], DocInfo)]()
@@ -316,6 +317,10 @@ trait DbUtils {
     }
   }
 
+  def assumeAttachmentInliningEnabled(db: ArtifactStore[_]): Unit = {
+    assume(inlinedAttachmentSize(db) > 0, "Attachment inlining is disabled")
+  }
+
   protected def encodedRandomBytes(size: Int): String = 
Base64.getEncoder.encodeToString(randomBytes(size))
 
   def isMemoryStore(store: ArtifactStore[_]): Boolean = 
store.isInstanceOf[MemoryArtifactStore[_]]
diff --git 
a/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreAttachmentBehaviors.scala
 
b/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreAttachmentBehaviors.scala
index de7a7a860f..a32eb282dc 100644
--- 
a/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreAttachmentBehaviors.scala
+++ 
b/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreAttachmentBehaviors.scala
@@ -90,6 +90,7 @@ trait ArtifactStoreAttachmentBehaviors extends 
ArtifactStoreBehaviorBase with Ex
    * if attachment is inlined
    */
   it should "work on reading with old inlined attachment" in {
+    assumeAttachmentInliningEnabled(entityStore)
     implicit val tid: TransactionId = transid()
     val code1 = encodedRandomBytes(inlinedAttachmentSize(entityStore))
     val exec = javaDefault(code1, Some("hello"))
@@ -140,6 +141,7 @@ trait ArtifactStoreAttachmentBehaviors extends 
ArtifactStoreBehaviorBase with Ex
   }
 
   it should "inline small attachments" in {
+    assumeAttachmentInliningEnabled(entityStore)
     implicit val tid: TransactionId = transid()
     val attachmentSize = inlinedAttachmentSize(entityStore) - 1
     val base64 = encodedRandomBytes(attachmentSize)


 

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