CouchDB 的 B 树数据库中实际存储了哪些数据?
我想知道 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
磁盘上的数据库文件是仅追加的;然而,B 树在概念上是就地修改的。当你更新一个文档时,
当根节点写入,即在“提交”新修订版时有效。要查找文档,您需要从文件末尾开始,获取根节点,然后找到您的文档 ID。最新版本始终可以通过这种方式访问。
The database file on disk is append-only; however the B-tree is conceptually modified in-place. When you update a document,
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.
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.