e-oj / Fawn

Transactions for MongoDB (See the README)
https://www.npmjs.com/package/fawn
MIT License
486 stars 54 forks source link

Does the package support concurrent operations? #12

Closed gxsjtu closed 7 years ago

gxsjtu commented 7 years ago

the package is great, but I want to know does the package support concurrent operations? not like this one

e-oj commented 7 years ago

What do you mean by "concurrent operations"?

gxsjtu commented 7 years ago

for example, two transactions which include some same documents are started concurrently, does each transaction lock the documents?

发自我的 iPhone

在 2017年7月14日,下午6:07,Emmanuel Olaojo notifications@github.com<mailto:notifications@github.com> 写道:

What do you mean by concurrent operations?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/e-oj/Fawn/issues/12#issuecomment-315323255, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AE4cVo-ugnz4CODtMfTXFZBXAt7rahtaks5sNz28gaJpZM4OX8ym.

e-oj commented 7 years ago

Oh, ok. So, two phase commits in MongoDB do not involve locks; it's just a way to ensure data consistency in multi-document transactions. As stated in the MongoDB docs, intermediate data can be returned at intermediate points during the transaction. It's possible to implement a system where a transaction which affects a document that's already being modified by another transaction, has to wait for the other transaction to complete but that won't really work because the documents can still be accessed by other means (you could use still use node-mongodb-native to access documents mid-transaction). It's really up to the developer to look out for, and potentially avoid situations like that.