Timing Issue - Couchbase Lite Pull Replication Timing with Sync Gateway update of documents


#1

I created a service that its purpose is to periodically update a Couchbase bucket (via the Sync Gateway) that mobile devices will synchronise with.
It also creates/updates a local Couchbase Lite file with updated documents of the above. The purpose of this step is to capture an updated Couchbase Lite DB file that can be downloaded by new devices, so new devices don’t have to sync all the data from scratch.

The flow of information is as follows:
A - Data export of updated documents to Couchbase using the Sync Gateway API.
B- Open a local Couchbase Lite DB using the Java SDK , start a one off Pull Replication, wait for the completion and close the CBL file
C – Capture the Couchbase Lite DB file so it can be downloaded by new mobile devices.
Everything works as expected but I need to insert a delay (of a few seconds) between steps A and step B, otherwise the changes applied to the bucket in step A are not reflected in step B pull replication (as shown by the ‘event listener’);
I also validated at the end of step A using the Sync Gateway bucket changes endpoint that the last updated document version is the new version (of the same document).
Is there an API that I can use on the Sync Gateway to indicate when a new pull replication will receive the latest changes?

Some more details on steps A and B
Part A

On the Sync Gateway side

Using put Document Put API’ to create or update the exported documents (only updating Documents that changed).

Part B

On the Couchbase Lite side

getDatabase
createPullReplication
setContinuous(false)
setChannels(channels)
start()
addChangeListener()
#wait for replication completion and close the local Lite DB

Part C
Save the DB file so it can be downloaded by multiple mobile clients


#2

Is there an API that I can use on the Sync Gateway to indicate when a new pull replication will receive the latest changes?

Not on the server side. But you can detect that on the client side (Couchbase Lite) http://developer.couchbase.com/documentation/mobile/1.3/develop/guides/couchbase-lite/native-api/replication/index.html#observing-and-monitoring-replications

James


#3

My event listener was checking the ‘replicator.isRunning()’ to determine when replication has finished but since we are not starting a continues replication we might be better of checking for Stopped status on the ‘client’ side.

The sequence of our process (triggered by a Restful service) is:
1 - Update the Couchbase ‘Sync’ bucket with documents from another system; this is done using the Sync Gateway API.
2- Trigger a pull replication (with continues = false) on a local Couchbase Lite that connects to the same Couchbase ‘Sync’ bucket via the Sync Gateway (and using the Java SDK). We then stop the Couchbase Lite database and capture the Couchbase lite file.

Note that Step 1 and 2 were executed by the same process.
The all idea is to capture an updated Couchbase Lite file that other mobile devices can download (initial loading or bulk update of the mobile devices)

It looks like we need to allow for a reasonable delay between step 1 and step 2 to let the changes applied on step 1 to settle down (Couchbase and Sync Gateway) before triggering step 2.

Avi