删除 Cosmos DB 容器会消耗 RUs 吗?

huangapple go评论63阅读模式
英文:

Does deleting Cosmos DB container consume RUs?

问题

在Cosmos DB容器中有大量无用文档。批量删除文档更好还是删除容器并重新创建它更好?批量删除会消耗RUs,但删除容器呢?删除容器之前删除文档会消耗RUs吗?

英文:

There are lot of junk documents in a Cosmos DB container. Is it better to bulk delete documents or drop the container and re-create it? Bulk delete consumes RUs, but what about deleting container? Does it consumes the RU to delete documents before dropping the container?

答案1

得分: 3

真的没有一个“正确”的答案 - 只有你能决定哪种方法更“好”,但... 从客观的角度来看:

  • 删除容器的成本微乎其微,而且这是一次性的成本(也就是说...只有一个“删除”成本)。关于采取“删除集合”路线时删除所有文档的成本的问题:不,这只是一个集合删除 - 在删除集合时不会为删除的每个文档收取RU。
  • 批量删除文档将消耗每个删除的文档的RU - 它绝对会花费RU,并且根据删除活动的侵略性,可能会出现限流的风险
  • 删除所有文档需要考虑删除可能发生在分区之间 - 请相应地进行规划
  • 如果删除集合,可能会有一个时间段,你的应用现在会因为集合不存在而抛出异常(直到重新创建集合,这可能需要几秒钟)
  • 重新创建集合时,请确保重新创建集合的任何相关属性(自定义索引、存储过程等)。

作为批量删除的替代方案,你还可以利用ttl让旧文档过期

英文:

There's really no "right" answer - only you can decide which approach is "better" but... from an objective perspective:

  • Deletion of a container has negligible cost, and it's a one-time cost (that is... it's one single "delete" cost). And to your question regarding cost of deleting all the documents when taking the "delete collection" route: nope - it's just a collection-drop - you aren't charged RU for every document being removed, when dropping a collection.
  • Deleting documents, in bulk, would consume RU for every document deleted - it would absolutely cost RU, and runs the risk of throttling, depending on how aggressive your deletion activity is
  • Deleting all documents requires you to consider that deletes could occur across partitions - plan accordingly
  • If you delete the collection, there could be a time period where your app is now throwing exceptions due to the collection not existing (until you re-create the collection, which could take several seconds)
  • When re-creating a collection, be sure to re-create any related attributes of the collection as well (custom indexing, stored procedures, etc)

As an alternative to bulk-deleting, you can also take advantage of ttl to let old documents expire.

huangapple
  • 本文由 发表于 2023年2月9日 00:42:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75388974.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定