简体   繁体   中英

App Engine NDB Transaction Collision

In the App Engine documentation ( https://cloud.google.com/appengine/docs/python/ndb/transactions ), it says: "If the transaction 'collides' with another, it fails; NDB automatically retries such failed transactions a few times."

The meaning of this sentence is not totally clear to me. If transaction A begins first, and then transaction B begins in the middle of A's operation, does that mean that both A and B will fail and retry? Or does only B fail, and A continues?

Also, a related question: are there any cases in which a transaction would be partially completed and then rolled back? Or does each transaction attempt not enter the function at all until it has the opportunity to complete the function?

Thank you!

Most likely than not, one of the transaction would succeed and the other fail (and be re-tried), but you can't tell in advance which one; it is also possible that both might fail (and be separately re-tried).

And yes, fail DOES generally mean partly progresses but then gets rolled back . It's an "optimistic concurrency" arrangement, not one based on pre-emptive locking .

Remember, potentially conflicting transactions are generally being requested on many distributed machines -- co-ordinating them by anything but "optimistic concurrency" (detect conflicts and roll back the ones that couldn't complete cleanly) would be unfeasible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM