Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replication Push (to CouchDB) is failing when attachments are involved #817

Closed
borrrden opened this issue Jul 21, 2015 · 4 comments
Closed

Comments

@borrrden
Copy link
Member

couchbase/couchbase-lite-net#449

There was some stuff in here that was incorrect on .NET but not on iOS that can be ignored but the crux of the problem is that CouchDB potentially sends the revpos of an attachment in a "follows" style response, but Couchbase Lite only checks for revpos in a "stub" style response.

Unit Test: https://github.com/couchbase/couchbase-lite-net/blob/master/src/Couchbase.Lite.Tests.Shared/ReplicationTest.cs#L409-L493

Solution is to add the following lines: https://github.com/couchbase/couchbase-lite-net/blob/master/src/Couchbase.Lite.Shared/Documents/AttachmentInternal.cs#L238-L245

@borrrden
Copy link
Member Author

Oh, looks like I still have the Objective-C version of the test I used lying around:

https://gist.github.com/borrrden/c581d3ee45c75ffcfe8f

@hideki
Copy link

hideki commented Jul 27, 2015

CBL java had issue of push replication with attachment. This issue was fixed by community developer. This might help CBL iOS. https://github.com/couchbase/couchbase-lite-java-core/issues/600

@pasin
Copy link
Contributor

pasin commented Jul 28, 2015

I could reproduce the issue with @borrrden's unit test. I simplified the unit test by only creating one document. I ran the unit test on both CouchDb and Sync-Gateway. CouchDB returned an error as it couldn't find the (stub) attachment as the specified revpos. Sync-Gateway on the other hand didn't report the error.

SyncGateway:

Push #1:
{"_attachments":{"myattachment":{"content_type":"text/plain; charset=utf-8","digest":"sha1-oaDsDkUDon9gAShhMF9l7cxugW8=","follows":true,"length":51200,"revpos":1}},"_id":"-mNhwBuzUfcGaF44mcOcww2","_rev":"1-119725eeb7585545cc849fda550d09b8","_revisions":{"ids":["119725eeb7585545cc849fda550d09b8"],"start":1},"foo":"bar"}

Push #2:
{"docs":[{"foo":"bar","_id":"-mNhwBuzUfcGaF44mcOcww2","_rev":"2-a48e751aa24f7c501d91460fedc6a71e","_attachments":{"myattachment":{"stub":true,"revpos":1}},"_revisions":{"ids":["a48e751aa24f7c501d91460fedc6a71e","119725eeb7585545cc849fda550d09b8"],"start":2},"extraminutes":"5"}],"new_edits":false}

Pull:
{"_attachments":{"myattachment":{"content_type":"text/plain; charset=utf-8","digest":"sha1-oaDsDkUDon9gAShhMF9l7cxugW8=","follows":true,"length":51200,"revpos":1}},"_id":"-mNhwBuzUfcGaF44mcOcww2","_rev":"2-a48e751aa24f7c501d91460fedc6a71e","_revisions":{"ids":["a48e751aa24f7c501d91460fedc6a71e","119725eeb7585545cc849fda550d09b8"],"start":2},"extraminutes":"5","foo":"bar"}

Push #3:
{"docs":[{"foo":"bar","_id":"-mNhwBuzUfcGaF44mcOcww2","_rev":"3-f2df8fff594b9fa05aead40e3439a672","_attachments":{"myattachment":{"stub":true,"revpos":2}},"_revisions":{"ids":["f2df8fff594b9fa05aead40e3439a672","a48e751aa24f7c501d91460fedc6a71e"],"start":3},"extraminutes":"10"}],"new_edits":false}

CouchDB:

Push #1:
{"_attachments":{"myattachment":{"content_type":"text/plain; charset=utf-8","digest":"sha1-oaDsDkUDon9gAShhMF9l7cxugW8=","follows":true,"length":51200,"revpos":1}},"_id":"-5n2PDOwjOteSh5EtHnRi4U","_rev":"1-119725eeb7585545cc849fda550d09b8","_revisions":{"ids":["119725eeb7585545cc849fda550d09b8"],"start":1},"foo":"bar"}

Push #2:
{"docs":[{"foo":"bar","_id":"-5n2PDOwjOteSh5EtHnRi4U","_rev":"2-a48e751aa24f7c501d91460fedc6a71e","_attachments":{"myattachment":{"stub":true,"revpos":1}},"_revisions":{"ids":["a48e751aa24f7c501d91460fedc6a71e","119725eeb7585545cc849fda550d09b8"],"start":2},"extraminutes":"5"}],"new_edits":false}

Pull:
{"_id":"-5n2PDOwjOteSh5EtHnRi4U","_rev":"2-a48e751aa24f7c501d91460fedc6a71e","foo":"bar","extraminutes":"5","_revisions":{"start":2,"ids":["a48e751aa24f7c501d91460fedc6a71e","119725eeb7585545cc849fda550d09b8"]},"_attachments":{"myattachment":{"content_type":"text/plain; charset=utf-8","revpos":1,"digest":"md5-W3qvModIgI6HVCj3N0O4IQ==","length":51200,"follows":true,"encoding":"gzip","encoded_length":85}}}

Push#3:
{"docs":[{"foo":"bar","_id":"-5n2PDOwjOteSh5EtHnRi4U","_rev":"3-4741922c82e0464341898d939d02bad7","_attachments":{"myattachment":{"stub":true,"revpos":2}},"_revisions":{"ids":["4741922c82e0464341898d939d02bad7","a48e751aa24f7c501d91460fedc6a71e"],"start":3},"extraminutes":"10"}],"new_edits":false}

Error:
{"error":"missing_stub","reason":"id:-5n2PDOwjOteSh5EtHnRi4U, name:myattachment"}

Error appeared on the client log:

18:51:07.104‖ CBLRemoteJSONRequest[POST http://localhost:5984/issue449/_bulk_docs]: Got error Error Domain=CBLHTTP Code=412 "412 file_exists" UserInfo=0x7fe89ad45770 {NSURL=http://localhost:5984/issue449/_bulk_docs, NSLocalizedFailureReason=file_exists, NSLocalizedDescription=412 file_exists}

pasin added a commit that referenced this issue Jul 29, 2015
During the pull replication, the revpos of an attachment could be set to a parent revision while the follows=true. If the revpos value doesn't get preserved, the revpos will be set to the current generation.

Later, when pushing an updated document again, the attachment info will contain a wrong revpos and result to the missing_stub error on CouchDB. SyncGateway currently ignores the issue and doesn't overwrite the revpos value on the server side.

#817
@pasin pasin added in progress and removed ready labels Jul 29, 2015
@pasin
Copy link
Contributor

pasin commented Jul 30, 2015

@zgramana I have seen the same issue was in 1.1.1 for .NET so I will move the fix to 1.1.1 iOS as well.

@pasin pasin closed this as completed Jul 30, 2015
@pasin pasin modified the milestones: 1.1.1, 1.2 Jul 30, 2015
pasin added a commit that referenced this issue Jul 30, 2015
During the pull replication, the revpos of an attachment could be set to a parent revision while the follows=true. If the revpos value doesn't get preserved, the revpos will be set to the current generation.

Later, when pushing an updated document again, the attachment info will contain a wrong revpos and result to the missing_stub error on CouchDB. SyncGateway currently ignores the issue and doesn't overwrite the revpos value on the server side.

#817
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants