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 2018/03/28 18:04:06 UTC

[GitHub] chetanmeh commented on issue #3500: Make attachments immutable

chetanmeh commented on issue #3500: Make attachments immutable
URL: https://github.com/apache/incubator-openwhisk/issues/3500#issuecomment-376980658
 
 
   I tried to implement this but the way CouchDB handled attachment I am not able to find a generic approach to implement the above flow. 
   
   With CouchDB following problems are seen
   
   1. Attaching attachment requires the document to be present - Its not possible to upload an attachment and then link to the document. So for initial creation we need to first create the document
   2. Updating document post attach causes the attachment to be lost - If a document with attachment is updated later then attachment gets lost. Looks like one needs to [pass in a stub][1] of attachment for such an update to work
       > When you want to update the document (e.g. through PUT) you must include the "stub", otherwise Couch will remove the attachment.
   
   Given these limitation it looks like we cannot implement proposed logic in a generic way. For now I see following option
   
   #### A - Store specific flow in DocumentFactory
   
   Use current approach when just `CouchDBRestStore` is configured and use the proposed approch when any other `AttachmentStore` is configured
   
   #### B - Introduce a new method in ArtifactStore
   
   Another option would be to be add another method in ArtifactStore
   
   ```scala
     protected[database] def putWithAttachment(d: DocumentAbstraction,
                                 attachedUpdater: (Attached, DocumentAbstraction) => DocumentAbstraction,
                                 contentType: ContentType,
                                 docStream: Source[ByteString, _],
                                 oldAttached: Option[Attached])(implicit transid: TransactionId): Future[DocInfo]
   ```
   
   where
   * `attachedUpdater` - Method which would update the `DocumentAbstraction` with new attachment details
   * `oldAttached` - Details about old attachment. We can also just accept an attachmentName string also here
   
   Such a method can then be efficiently implemented by respective `ArtifactStore`  for e.g. with
   * `CouchDBRestStore`
       1. Generate a random name
       2. Update the DocumentAbstraction and save it
       3. Now attach the passed source with generated name
       4. No need for deleting old attachment as post document update CouchDB would not remember it anyway
   * `CouchDBRestStore` + `S3AttachmentStore`
       1. Generate a random name and then upload to S3 with generated name
       2. Update the DocumentAbstraction and save it
       3. Delete the old attachment
   
   @rabbah @markusthoemmes Any thoughts on which approach to take
   [1]: https://stackoverflow.com/a/34325095/1035417

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


With regards,
Apache Git Services