CouchDB 的 B 树数据库中实际存储了哪些数据?

发布于 2024-08-29 13:57:05 字数 707 浏览 2 评论 0原文

我想知道 CouchDB 数据库 B 树中实际存储了什么? CouchDB:权威指南 告诉我们数据库 B 树用于仅追加操作,并且数据库存储在单个 B 树中(除了每个视图的 B 树)。

所以我猜想附加到数据库文件的数据项是文档的修订,而不是整个文档:

            +---------|### ...  
            |           |
   +------|###|------+     ... ---+
   |        |        |            |
+------+ +------+ +------+     +------+
| doc1 | | doc2 | | doc1 | ... | doc1 |
| rev1 | | rev1 | | rev2 |     | rev7 |
+------+ +------+ +------+     +------+

这是真的吗?

如果这是真的,那么如何根据这样的 B 树确定文档的当前修订版本?

这是否意味着 CouchDB 需要一个单独的“视图”数据库来索引文档的当前修订以保留 O(log n) 访问权限?在建立这样的索引时不会导致竞争条件吗? (据我所知,CouchDB不使用写锁)。

I'm wondering what is actually stored in a CouchDB database B-tree? The CouchDB: The Definitive Guide tells that a database B-tree is used for append-only operations and that a database is stored in a single B-tree (besides per-view B-trees).

So I guess the data items that are appended to the database file are revisions of documents, not the whole documents:

            +---------|### ...  
            |           |
   +------|###|------+     ... ---+
   |        |        |            |
+------+ +------+ +------+     +------+
| doc1 | | doc2 | | doc1 | ... | doc1 |
| rev1 | | rev1 | | rev2 |     | rev7 |
+------+ +------+ +------+     +------+

Is it true?

If it is true, then how the current revision of a document is determined based on such a B-tree?

Doesn't it mean, that CouchDB needs a separate "view" database for indexing current revisions of documents to preserve O(log n) access? Wouldn't it lead to race conditions while building such an index? (as far as I know, CouchDB uses no write locks).

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

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

发布评论

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

评论(2

只是我以为 2024-09-05 13:57:05

磁盘上的数据库文件是仅追加的;然而,B 树在概念上是就地修改的。当你更新一个文档时,

  1. 它的叶子节点被写入(通过追加到数据库文件)
  2. 它的父节点被重写以引用新的叶子(当然通过追加)
  3. 重复步骤2,直到更新根节点

当根节点写入,即在“提交”新修订版时有效。要查找文档,您需要从文件末尾开始,获取根节点,然后找到您的文档 ID。最新版本始终可以通过这种方式访问​​。

The database file on disk is append-only; however the B-tree is conceptually modified in-place. When you update a document,

  1. Its leaf node is written (via append to the DB file)
  2. Its parent node is re-written to reference the new leaf (via append of course)
  3. Repeat step 2 until you update the root node

When the root node is written, that is effectively when the newer revision is "committed." To find a document, you start at the end of the file, get the root node, and work down to your doc id. The latest revision will always be accessible this way.

酒儿 2024-09-05 13:57:05

CouchDB 不存储差异。当您更新文档时,它会在整个新文档中附加新的 _rev 和与旧版本相同的 _id。旧版本在压缩期间被删除。

CouchDB does not store diffs. When you update a document, it appends the whole new document with a new _rev and the same _id as the old version. The old version is removed during compaction.

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