couchbase/sync_gateway

Admin/User views cannot handle both xattr and non-xattr simultaneously

mattcarabine opened this issue · 5 comments

The Sync Gateway issue tracker is reserved for bug reports and enhancement
requests. For general questions, please use the Couchbase forums:
https://forums.couchbase.com/c/mobile/sync-gateway. Thank you!

Sync Gateway version

Latest - 2.1.2 released but also affects master.

Operating system

N/A

Config file

N/A

Log output

N/A

Expected behavior

Admin or user created views are able to handle both mobile docs with extended attributes or docs with mobile metadata in the body.

Actual behavior

Admin or user created views can only handle the document types (xattr vs body) specified in the Sync Gateway config at the time that the view was created.
This is undesirable as it can cause situations where the result set of the views will be incomplete once the import process has begun and there's no way to get a consistent dataset.
Even ignoring this, it means that you would have to re-deploy your view after enabling shared_bucket_access and import.

Steps to reproduce

  1. Turn on Sync Gateway with shared_bucket_access and import disabled
  2. Add some documents to Sync Gateway
  3. Create an admin view using Sync Gateway
  4. Enable shared_bucket_access and import
  5. Begin to query your view and check the result set, notice how this is incomplete

What would be nice is if there was only a single admin/user view wrapper with logic similar to the code implemented in db39d17 for the built-in Sync Gateway views:

var sync
if (meta.xattrs === undefined || meta.xattrs.%s === undefined) {
    sync = doc._sync
} else {
    sync = meta.xattrs.%s
}

This also has the side benefit of not having to check when xattrs are enabled or not when creating the view, meaning the total amount of code to maintain is smaller.

If you think that this is the most suitable fix, I'd be happy to submit the PR for this issue myself.

I think that general approach is reasonable, but also needs to include the delete / reinsert of doc._sync in the non-xattr case. I think that should be relatively straightforward - could just set a flag when the initial check for doc._sync vs. meta.xattrs._sync is done and use that to trigger the delete/reinsert.

@adamcfraser is there a reason this additional handling of the delete/reinsert is not done by the built-in Sync Gateway views?
Just a different expectation in terms of the content of the document within the admin/user view?

@mattcarabine Right - the internal views need to interact w/ the sync metadata, and user-created views do not.

Will get a PR up on this tomorrow UK time.

bbrks commented

Issue now being tracked at CBG-221