简体   繁体   English

为什么 CouchDB 在同步一个 _rev 差异高于修订限制的 PouchDB 文档时会产生冲突?

[英]Why CouchDB generates a conflict when syncing a PouchDB document with a _rev difference higher than the limit of revisions?

This is a strange behavior.这是一种奇怪的行为。 First, we sync CouchDB and PouchDB databases.首先,我们同步 CouchDB 和 PouchDB 数据库。 Second, the PouchDB database goes offline.其次,PouchDB 数据库下线。 After many modifications to a document, it goes online and sync with CouchDB.在对文档进行多次修改后,它会上线并与 CouchDB 同步。 If PouchDB document _rev number is higher than CouchDB _rev number plus the revs limit, CouchDB generates a 409 "Document update conflict".如果 PouchDB 文档 _rev 编号高于 CouchDB _rev 编号加上 revs 限制,CouchDB 会生成 409“文档更新冲突”。 Why?为什么? And what can we do to avoid it?我们能做些什么来避免它? 在此处输入图像描述

Unfortunately, this is the expected behaviour for the revs_limit option in PouchDB.不幸的是,这是 PouchDB 中revs_limit选项的预期行为。 The documentation says文件

revs_limit: Specify how many old revisions we keep track (not a copy) of. revs_limit:指定我们跟踪(不是副本)的旧修订的数量。 Specifying a low value means Pouch may not be able to figure out whether a new revision received via replication is related to any it currently has which could result in a conflict.指定一个低值意味着 Pouch 可能无法确定通过复制接收到的新修订是否与它当前拥有的任何可能导致冲突的修订相关。 Defaults to 1000.默认为 1000。

If your PouchDB revs_limit is too low, it cannot be determined whether your local revision actually has the server revision in its history and therefore throws a conflict.如果您的 PouchDB revs_limit太低,则无法确定您的本地版本是否在其历史记录中确实有服务器版本,因此会引发冲突。

The straighforward way would be to increase the local revision limit.直截了当的方法是增加本地修订限制。 But if you're generating over 1000 revisions between syncs, you should consider changing your data model, splitting up large JSONs and storing the modifications in a new document and merging the data in the app instead of modifying the full document.但是,如果您在同步之间生成超过 1000 个修订,您应该考虑更改您的数据 model,拆分大型 JSON 并将修改存储在新文档中并将数据合并到应用程序中,而不是修改整个文档。

If that's not an option, simply check for conflicts and resolve them by deleting the server version whenever they occur.如果这不是一个选项,只需检查冲突并通过在发生冲突时删除服务器版本来解决它们。

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

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