我应该从 Cloudant 数据库中删除逻辑删除吗?

发布于 2025-01-16 11:33:54 字数 89 浏览 1 评论 0原文

我有一个 Cloudant 数据库,其中包含 400 万个文档和 2700 万个已删除文档(“逻辑删除”)。有这么多墓碑是一个问题吗?如果是的话,我该如何摆脱它们?

I have a Cloudant database with 4 million documents and 27 million deleted documents ("tombstones"). Is having so many tombstones a problem and, if so, how do I get rid of them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白况 2025-01-23 11:33:54

“墓碑”占据空间,因此会增加您的账单。它们还增加了完成新复制或构建新索引的时间。
因此,一般来说,定期移除这些墓碑是一个很好的做法。
最好的方法是使用过滤器复制数据库,留下已删除的文档。

复制是通过在 _replicator 数据库中创建一个文档来开始的,如下所示:

{
  "_id": "myfirstreplication",
  "source" : "http://<username1>:<password1>@<account1>.cloudant.com/<sourcedb>",
  "target" : "http://<username2:<password2>@<account2>.cloudant.com/<targetdb>",
  "selector": {
    "_deleted": {
      "$exists": false
    }
  }
}

其中源是原始数据库,目标是新的空数据库。选择器是在复制之前检查每个文档的过滤器 - 在本例中我们只需要没有已删除属性的文档(尚未删除的文档)。

此复制将生成一个没有逻辑删除的全新数据库。将您的应用程序指向这个新数据库,然后删除带有逻辑删除的旧数据库。

这篇博文中还有其他更复杂的场景您可能需要考虑。

"Tombstones" occupy space and so contribute to your bill. They also increase the time for new replications to complete or new indexes to build.
So in general it is good practice to periodically remove these tombstones.
The best way to do it is to replicate your database with a filter that leaves deleted documents behind.

Replications are started by creating a document in the _replicator database like so:

{
  "_id": "myfirstreplication",
  "source" : "http://<username1>:<password1>@<account1>.cloudant.com/<sourcedb>",
  "target" : "http://<username2:<password2>@<account2>.cloudant.com/<targetdb>",
  "selector": {
    "_deleted": {
      "$exists": false
    }
  }
}

where the source is the original database and the target is the new empty database. The selector is the filter that checks each document before replicating - in this case we only want documents without a deleted attribute (a document that hasn’t been deleted).

This replication will result in a brand new database with no tombstones. Point your application to this new database and then delete the old one with the tombstones.

In this blog post there are other, more complex, scenarios that you may want to consider.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文