-
Notifications
You must be signed in to change notification settings - Fork 138
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
Attachments fail to sync if revpos ancestor on server has been compacted #1706
Comments
Related to issue #1034 |
Its somewhat related to #1034, however the solution for that, walking up the ancestor tree, will not work here. There is no ancestor revision available. |
Well, In fact SG should be able to look at the current revision on the branch (the latest common ancestor) and find that same attachment, with the same “revpos”:2. If it can’t, then something’s wrong with the request. |
@snej Makes sense - will make that change in the SG handling. |
@snej We're already handling the first case you described - we're checking the revpos on the immediate parent for a non-conflicting update, and don't require the revpos revision to still exist. I'm only able to reproduce the filer's issue if the caller doesn't include the revision id corresponding to revpos in the _revisions property on the bulk_docs request. In this case the client is pushing a revision that doesn't have a common ancestor on the server (that ancestor has been pruned away). |
I was able to reproduce by doing a PUT to /db/doc?new_edits=false with both of these payloads, where the doc already exists on the server, and rev 1-c325a14e17ef08fb34c37b965d0ca3a0 has been pruned away.
So the scenario appears to be:
The active revision has the same revpos, but since we don't have the history back to that generation on the server, I don't think the server can validate that the revision at revpos=1 that it knows about is actually the same revision at revpos=1 that the request is referencing (i.e. the server could be referencing an attachment added at 1-foo, and the client referencing an attachment on a conflicting branch at 1-bar). @snej, @pasin Based on this, I feel like Sync Gateway is doing the right thing, and the client needs to resubmit the conflicting revision with the full attachment. Let me know what you think. |
@alex7egli Can you let us know what platform of Couchbase Lite you're using? |
I don't think the scenario you describe can happen, unless there's a bug somewhere. Since the server doesn't have revision 1-c325 anymore, the |
Its iOS 1.1.1. Given the number of reports, I think its reasonable to suggest there is a bug. The POST request would need to be scrubbed to upload fully, but the relevant snippets are:
"new_edits":false |
@jprosevear Are you able to provide a scrubbed version of the same document as viewed through the Couchbase Server Admin Console (i.e. showing the _sync metadata)? |
@alex7egli should be able to |
Here is the current _sync object for that document:
|
Thanks @alex7egli that's very helpful. It looks like the server and the client doc share a common ancestor that hasn't been pruned (15-d9c7eefd468c6d932a44bf92f8c67fb0), so Sync Gateway should be able to recognize the attachment. I'll look into this today and try to work out what's going on. |
Fixed by #1725. |
If a document with an attachment in it gets out of sync so that the client is a revision or two behind the server, and before it resyncs the ancestor that is the revpos of the attachment is compacted away on the server, then the document will not be able to sync again. Newer revisions from the server are not synced to the client and the newer revisions from the client are not synced to the server. Only solution is to delete client DB and resync completely, losing any data in the db since the last successful sync. Error shown in the logs is:
BulkDocs: Doc "[DOC ID]" --> 400 Missing digest in stub attachment "[attachment name]" (400 Missing digest in stub attachment "[attachment name]")
Steps to Reproduce:
RESULTS: You see a 400 Missing Digest error for the document in the sync gateway logs. The document does not sync the client updates to the server.
CAUSE:
The client does not send the digest of the attachment to the server in a _bulk_docs POST. It just sends the revpos and stub=true. E.g. In the doc on the server the attachment metadata object looks like:
"_attachments" : {"name":{"content_type":"image/jpg","digest":"sha1-RD3Ax1G1gPfqWrCnMmh/OzNLVDY=","length":134124,"revpos":2,"stub":true}}
But in the _bulk_docs POST request it just has:
"_attachments":{"name":{"stub":true,"revpos":2}}
Since the client and the server are out of sync Sync gateway tries to walk up the tree of the document to the revision that the attachment came from to get the full _attachment object and insert the client revisions into the tree, but since the original attachment revision is gone it fails.
Walking up the tree:
sync_gateway/db/crud.go
Line 308 in 3aa3c25
Called in here, which actually generates the 400 error because digest is missing because it failed to find the parent revision when walking up the tree:
sync_gateway/db/attachment.go
Line 40 in 3aa3c25
Tries to integrate the attachment:
sync_gateway/db/crud.go
Line 409 in 3aa3c25
The text was updated successfully, but these errors were encountered: