Couchdb 监视集群模式下的更改提要,返回相同 since 值的随机更改

Couchdb watch changes feed in clustered mode returning random changes for the same since value

根据互联网。您请求 /_changes?since=0&limit=1 执行您想要的更改,然后使用 last_seq 值并传递给 since 并再次请求。

我的问题是,这会跳过更改。您可以不断请求 /_changes?since=0&limit=1 并一次又一次地获得不同的零钱。只是偶尔才真正获得对数据库的第一个更改。有时你会得到第 7 个更改,或第 4 个等。如果你然后重复但使用 last_seq 值,它会进一步向前跳过,据我所知,它永远不会返回并获得它跳过的更改。

在使用集群时,是否有适当的方法在不使用套接字方法的情况下定期观察 couchdb 更改提要?

我们现在拥有的是一个 php 脚本,该脚本在 cron 任务上运行并请求最后 1000 次更改,然后它通过它们工作并同步 SQL 数据库以匹配中的内容沙发数据库。随着 couchdb 跳过更改,这是一个大问题。

CouchDB 2.x 文档指出 (see):

"The results returned by _changes are partially ordered. In other words, the order is not guaranteed to be preserved for multiple calls."

因此,当您调用 /_changes?since=0&limit=1 时,您会得到不同的结果,因为无法保证顺序。

_changes 响应包含一个未决属性,其中包含响应之外的元素数。如果您从上一个请求中获取 last_seq 值并将该值用作下一个请求中的 since 属性,您将获得下一批更改并且待定值会持续减少。

此外,您应该注意下一个文档注释:

If the specified replicas of the shards in any given since value are unavailable, alternative replicas are selected, and the last known checkpoint between them is used. If this happens, you might see changes again that you have previously seen. Therefore, an application making use of the _changes feed should be ‘idempotent’, that is, able to receive the same data multiple times, safely.

批量读取更改是 CouchDB 兼容客户端用作 Cloudant Sync 的 CouchDB 复制协议 (see) 的建议,因此您描述的方法应该是正确的。

请不要使用更改序列的数值作为参考来推断存在遗漏的更改,因为此数字是根据集群状态计算得出的,这可能因调用而异。您可以查看 了解更多详情。