What is the best way to be sure the replication has finished?

Before letting the user access the main content of my application, I need to be sure the full database has been replicated locally. Actually I check the status and when it goes IDLE I check if it does not goes active after a few seconds but, first it slow done the loading process, because when it has correctly terminated, it’s still waiting a few seconds before shwoing the content to the user, secondly it happens that it takes > 5 seconds between an ‘idle’ and an ‘active’ status (so not the entire database is replicated).

I was thinking of first doing a ‘one shot replication’ and then start the continuous replication once the ‘one shot’ has terminated but I don’t know if a ‘one shot replication’ ensure that all documents will be replicated? Or could it terminate with a timeout or something?

I’m using Sync Gateway 1.4 and CBLite 1.4 so I’m first interrested in a solution that works for this because this is the version that will first go in production but I’m also interessted in a solution that works on SG 1.5 and CBLite 2.0 because we will soon (I hope) switch to this.

Thank’s !

Hey @martin.hogge - which mobile platform are you on? iOS, android, or .net?

Yes, if a one-shot replication completes without errors, than you can be assured that all of the documents have been replicated.

And if you have the strict requirement of blocking/waiting until the replication has finished, then it sounds like an initial one-shot replication is a good fit for you.

In fact, if you look at the sg-replicate code (a Sync Gateway <-> Sync Gateway replicator), it implements a continuous replication as a loop of one-shot replications, with a long-poll changes listener to minimize the polling frequency. I’m not suggesting you do this approach on cblite (especially since they are entirely different codebases), but I’m just throwing it out there as something that might help you better understand how replication works.

Hi Traun ! Thanks for the information, it’s clearer now. I will go with the one shot replication as it seems a good way to go.

(I was talking about Android CBLite)

You can also check the status of initial replication by running the following command on the downstream machine. This is especially handy if the event log has been cleared.

C:\dfsr>Wmic /namespace:\root\microsoftdfs path dfsrreplicatedfolderinfo get replicationgroupname,replicatedfoldername,state
ReplicatedFolderName ReplicationGroupName State
DATA Test-RG 4
The state for each folder that has completed initial replication is 4. For all other folders that are still in the process of initial replication, the ‘State’ will be 2.
Coutesy : https://blogs.technet.microsoft.com/filecab/2008/10/27/storage-tip-how-to-check-if-the-initial-replication-was-completed-successfully/

@sansuanna That looks like something that isn’t related to Couchbase Mobile. I’ve asked @borrrden (the Couchbase Mobile Windows Guru) to take a look.