Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PouchDB/CouchDB Sequence Counter on Replicate

I am live syncing a freshly minted pouchdb (3.3.1) to an established (iris) couchdb.

The initial replication happens successfully (pause event fired).

If I do info() on the Local, I get an update_seq of 362. If I do info() on the remote, it shows an update_seq of 4201.

I think this makes sense to me: the local db has no revisions - only the leaves (i.e. there are 362 leaves in the db) whereas the remote db sequence counter reflects all the historical changes that have been made since it was first created.

My question is: how can I programatically determine what the initial 'offset' in sequence counter is between the two databases? In particular I want to be able to measure the progress of the initial replication.

like image 251
simonberry Avatar asked Mar 19 '15 05:03

simonberry


1 Answers

You can't really compare the seqs across two databases. However, you can do a db.info() on the remote database, grab the update_seq, and then compare that to the last_seq that is given to you in the on('change') event during replication. This will tell you how much progress you've made.

If you would like to see an example of this, the NPM Browser does exactly this, to show the percent counter at the top. (It uses pouchdb-load as well, but the principle is the same, since the seqs are reported there as well.) The code is open-source, so feel free to check out how it works. :)

Edit: as pointed out in a comment, if you are using sync rather than replicate, you need to check the direction parameter when reading last_seq. Also for Cloudant, you will need to split the string on - to get the integer seq.

like image 140
nlawson Avatar answered Nov 15 '22 09:11

nlawson