在没有持久性(mongo)的情况下有哪些操作顺序保证?

发布于 2024-12-14 02:02:34 字数 646 浏览 1 评论 0原文

假设您有一个 ACID 数据库。如果没有关于操作顺序的明确保证,您仍然可以根据持久性来推断顺序。

例如,

  1. 我将 x 插入数据库,语句返回
  2. 现在我插入 y
  3. 因为持久性保证,我知道 x 在 <代码>y。

因此,如果发生崩溃,我要么:

  1. 数据库中没有 xy
  2. 只有 x
  3. 都有 x和<代码>y。

现在假设数据库具有宽松的持久性保证。例如,没有安全模式或 getlasterror 的 MongoDB。

我如何保证第一个操作在第二个操作持久之前就已持久?
请指出文档中声称这一点的部分或适当的测试。
如果发生故障,我的数据库可以包含 y 但不包含 x 吗?

编辑:
似乎默认(唯一?)存储机制是内存映射文件引擎。如果不启用日志记录(现在默认启用),服务器崩溃似乎会导致不一致且无法修复的状态。我想答案就在日记里。

Suppose you have an ACID database. Without an explicit guarantee about operation ordering, you can still infer ordering as a result of durability.

e.g.

  1. I insert x into a database and the statement returns
  2. Now I insert y
  3. because of a Durability guarantee, I know x was made durable before y.

Thus, in event of a crash, I either have:

  1. none of x or y in the database
  2. only x
  3. both x and y.

Now assume a database with a relaxed durability guarantee. e.g. MongoDB without safemode or getlasterror.

What guarantee do I have that the first operation is made durable before the second operation is made durable?
Please point me to the part of documentation that claims this, or the appropriate test.
In event of failure can my database contain y but not x?

EDIT:
It seems the default (only?) storage mechanism is memory-mapped files engine. Without journaling enabled (now enabled by default), it seems a server crash can result in an inconsistent and irreparable state. I guess the answer lies within the journaling.

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

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

发布评论

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

评论(2

久夏青 2024-12-21 02:02:34

回答我自己的问题:

日记有保证。具体来说,日志是预写式重做日志。

启用日记功能后,将在日记/中创建日记文件
您选择的数据库路径下的子目录。这些文件是预写的
重做日志。此外,最后一个序列号文件,journal/lsn,将
被创建。干净的关闭会删除journal/下的所有文件。

资料来源: http://www.mongodb.org/display/DOCS/Journaling#Journaling -JournalFiles

没有日记就没有任何保证(我可以找到或理解)。 MongoDB 使用内存映射文件作为其主要存储引擎。对内存的写入不会立即反映在文件系统中。例如,在操作系统崩溃的情况下,文件可能处于不一致且不可恢复的状态。

To answer my own question:

There is a guarantee with journaling. Specifically, the journals are write-ahead redo logs.

With journaling enabled, journal files will be created in a journal/
subdirectory under your chosen db path. These files are write-ahead
redo logs. In addition, a last sequence number file, journal/lsn, will
be created. A clean shutdown removes all files under journal/.

Source: http://www.mongodb.org/display/DOCS/Journaling#Journaling-JournalFiles

There is no guarantee (I can find or comprehend) without journaling. MongoDB uses memory-mapped files as it's primary storage engine. Writes to memory are not immediately reflected in the filesystem. In the case of an OS crash (for example), the files might be in an inconsistent and unrecoverable state.

玻璃人 2024-12-21 02:02:34

根据您的用例,您可以使用 Mongo 的 Capped Collections 来维护以下内容的插入顺序集合中的对象。但有一些限制,请查看文档。

您还可以从排序和自然排序中获得更多见解:

< em>对于标准表,自然顺序并不是特别有用,因为尽管顺序通常接近插入顺序,但不能保证如此。但是,对于 Capped Collections,自然顺序保证是插入顺序。

Depending on your use case, you can use Mongo's Capped Collections that maintain insertion order for the objects in the collection. With some restrictions though, check the docs.

You can also get more insight from Sorting and Natural Ordering:

For standard tables, natural order is not particularly useful because, although the order is often close to insertion order, it is not guaranteed to be. However, for Capped Collections, natural order is guaranteed to be the insertion order.

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