Sync Function / Resync questions / Kubernetes

The documentation states:

If the Sync Function is changed, Sync Gateway needs to reprocess all existing documents in the bucket to recalculate the routing and access assignments.

This whole section of the docs scares me a bit, tbh. Want to make sure I fully understand all the caveats and corner cases. First question: if I have sgw running in a kubernetes cluster behind a load balancer, I ought to be able to drop the # replicas down by one, and redeploy a new one with the new sync function configuration – however, there’s a period where there will be a mix of old sync-function and new sync function. What is the recommendation on handling this situation properly?

Also, if we’re writing documents to the same bucket and have one of the sync gateways with enabled-shared-bucket feature on (so it replicates changes from the database outside of sync gateway up to the mobile clients)…what happens if we modify a document’s channel list directly using, e.g. the Golang SDK?

Is that kind of change propagated to each sync gateway automatically, or does something like that require a resync as well?

I thought a document’s channel membership was actually stored in the meta-info – is that even possible to manipulate outside of a sync function using something like the Go SDK?

That’s correct - channel membership is stored as metadata (in a ‘_sync’ extended attribute when enable_shared_bucket_access is true). That metadata shouldn’t be modified by anyone but Sync Gateway (via the sync function).

Changes to the sync function only require a resync if you want the changes to be applied to existing documents. i.e. if you’re just making an additive change (handling for a new document type), or only want the change to apply to future mutations, it’s not necessary to run resync.

However, if you want your sync function changes to trigger recalculation of the channel assignment for existing documents, resync would be required.

Thanks @adamf – if I post a doc to the database direct through the Go SDK (i.e. not through the sync gateway), will that document still run through my sync function on the sync gateway node that has enable-shared-bucket-access, import-documents enabled?

Yes - that’s the motivation behind enabling shared bucket access - documents written directly to the bucket get imported by Sync Gateway, and the _sync metadata is generated at import time.

1 Like