简体   繁体   English

复制时的PouchDB / CouchDB序列计数器

[英]PouchDB/CouchDB Sequence Counter on Replicate

I am live syncing a freshly minted pouchdb (3.3.1) to an established (iris) couchdb. 我在现场同步一个刚毕业的pouchdb(3.3.1)已建立的(IRIS)的CouchDB。

The initial replication happens successfully ( pause event fired). 初始复制成功发生( 暂停事件触发)。

If I do info() on the Local, I get an update_seq of 362 . 如果我在Local上执行info() ,我会得到一个362的update_seq。 If I do info() on the remote, it shows an update_seq of 4201 . 如果我在遥控器上执行info() ,则会显示update_seq为4201

I think this makes sense to me: the local db has no revisions - only the leaves (ie 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. 我认为这对我有意义:本地数据库没有修订版 - 只有叶子(即数据库中有362个叶子),而远程数据库序列计数器反映了自首次创建以来所做的所有历史更改。

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. 特别是我希望能够衡量初始复制的进度。

You can't really compare the seqs across two databases. 您无法真正比​​较两个数据库中的seq。 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. 但是,您可以在远程数据库上执行db.info() ,获取update_seq ,然后将其与复制期间on('change')事件中为您提供的last_seq进行比较。 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. 如果您希望看到一个这样的示例, NPM浏览器就是这样做的,以显示顶部的百分比计数器。 (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. (它也使用pouchdb-load,但原理是一样的,因为seqs也在那里报告。)代码是开源的,所以请随时查看它是如何工作的。 :) :)

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 . 编辑:正如注释中所指出的,如果您使用的是sync而不是replicate ,则需要在读取last_seq时检查direction参数。 Also for Cloudant, you will need to split the string on - to get the integer seq. 同样对于Cloudant,您需要将字符串拆分为-以获取整数seq。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM