是否可以在 MongoDB 之上实现多版本并发控制 (MVCC)?

发布于 2024-11-07 02:11:08 字数 228 浏览 0 评论 0原文

MongoDB 对我来说是一个很棒的数据库。然而,在某些情况下,我确实需要原子多文档事务。例如,在帐户之间转移事物(例如金钱或声誉),这需要完全成功或完全失败。

我想知道是否可以通过实现多版本并发控制模式的库与 MongoDB 进行交互。

表演会有多糟糕? 使用混合方法是否可能且有利可图,仅在必要时使用“mongo-mvcc”库,而仅在处理单个文档时使用传统的数据库连接,或者这会破坏 mvcc 的东西吗?

MongoDB is to me a great database. However there are cases where I really need atomic multi-document transactions. For example to transfer things (like money or reputation) between accounts and this needs to either succeed completely or fail completely.

I wonder if it would be possible to interact with MongoDB through a library implementing the MultiVersion Concurrency Control pattern.

How bad would it be concerning performances?
Would it be possible and profitable to use a hybrid approach, using the 'mongo-mvcc' library only when necessary and the traditional db connection when working only on a single document or would this break the mvcc stuff ?

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

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

发布评论

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

评论(6

旧时浪漫 2024-11-14 02:11:08

最简单的方法是使用锁(两阶段提交),尽管这在某些情况下效率不是很高。对于更高的并发性,可以在 Mongo 之上实现某种 MVCC。本文提供了很好的描述:

http://highlyscalable.wordpress .com/2012/01/07/mvcc-transactions-key-value/

The simplest way is to use locks (two-phase commit), although this is not very efficient in some cases. For higher concurrency some kind of MVCC can be implemented on the top of Mongo. This article provides a good description:

http://highlyscalable.wordpress.com/2012/01/07/mvcc-transactions-key-value/

为人所爱 2024-11-14 02:11:08

金钱交易可以通过两阶段提交来实现:http://www.mongodb。 org/display/DOCS/two-phase+commit

Money transaction can be implemented via two-phase commit : http://www.mongodb.org/display/DOCS/two-phase+commit

断舍离 2024-11-14 02:11:08

GitHub 上现在提供了 MongoDB 上的 MVCC 实现:

https://github.com/igd-geo/蒙戈姆VCC

There is an implementation of MVCC on MongoDB available now on GitHub:

https://github.com/igd-geo/mongomvcc

月竹挽风 2024-11-14 02:11:08

MongoDB 并不是真正为处理事务而设计的。关于如何实现这一点,有一个非常好的讨论:http://kylebanker.com/blog/2010/04/30/mongodb-and-ecommerce/

MongoDB isn't really designed to work with transactions. There is a really good discussion of how you might be able to implement this over at: http://kylebanker.com/blog/2010/04/30/mongodb-and-ecommerce/

哽咽笑 2024-11-14 02:11:08

您可以创建版本集合并拥有最后提交版本的文档。

使用读取时间戳 (rts) 以原子方式更新此文档,该时间戳不是基于时间的时间戳,而是当应用程序代码从集合中读取文档时单调递增的数字。

在更新集合之前,获取此版本集合文档并检查当前事务下方是否有读取时间戳,如果有,则中止读取或写入。

当您想要使用lastCommit“发布”记录的版本并使其可见时,请更新版本文档。

您应该只“查看”小于或等于最后提交的交易编号的交易数据。

我在此存储库中实现了 Java MVCC

You could create a versions collection and have a document for the last committed version.

Atomically update this document with the Read Timestamp (rts) which is not a time based timestamp but a monotonically increasing number when your application code has read a document from a collection.

Before you update a collection, fetch this versions collection document and check if there is a read timestamp below your current transaction, if there is, abort the read or write.

Update the versions document when you want to "publish" with a lastCommit the version of a record and cause it to be visible.

You should only "see" transactions data that are less than or equal to the last committed transaction number.

I implemented MVCC in Java in this repository.

勿忘初心 2024-11-14 02:11:08

那么,当您需要真正的事务时,您可以使用 RDBMS,它们旨在支持它们:) NoSQL 速度更快且更具可扩展性,主要是因为它们不支持事务。

如果您两者都需要,那么使用事务层来支持事务并将 NoSQL 层用于其他目的也许是个好主意?在某些情况下,使用 MongoDB 和 PostgreSQL 创建混合系统应该不难

Well when you need real TRANSACTIONS you use RDBMS which are designed to support them :) NoSQLs are faster and more scalable mainly because they don't support transactions.

If you need both maybe it's a good idea to have transactional layer to support transactions and NoSQL layer for other purposes? In some cases it shouldn't be difficult to create a hybrid system using for example MongoDB and PostgreSQL

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