0

We understand that firestore transaction is based on pessimistic lock (https://firebase.google.com/docs/firestore/manage-data/transactions), which means the actual update inside transaction block may success or fail based on "whether or not the document has been changed since last time I looked at it".

That being said, can we have a callback on the transaction.update() and transaction.create()(mutation) methods on success or failures so that we can do logging more accurately?

The reason I am asking this is, with pessimistic lock, two transaction blocks can happen simultaneously, and it may create a confusion in the logging when two mutually exclusive things seem to happen concurrently.

somenickname
  • 539
  • 7
  • 19
  • "firestore transaction is based on pessimistic lock" The behavior you describe, and that Firestore uses, is actually known as an **optimistic lock**, since it assumes that the data is unmodified. Also see https://stackoverflow.com/questions/129329/optimistic-vs-pessimistic-locking – Frank van Puffelen Oct 02 '19 at 06:07
  • "two mutually exclusive things seem to happen concurrently" This cannot happen, neither with optimistic nor with pessimistic locking. – Frank van Puffelen Oct 02 '19 at 06:09
  • @FrankvanPuffelen We are using query inside the transaction, with limit 1, and I see two concurrent processes querying the same document, both calling `transaction.update` to the same documentation, before returning the promise. But after the transaction, only one process did actually get the document, meaning the other one did not actually resolve. – somenickname Oct 02 '19 at 18:52
  • It sounds like you're having a concrete problem with your code. In that case, please include the [minimal complete/standalone code that reproduces the problem](http://stackoverflow.com/help/mcve) in your question (read the link please, it's quite useful). – Frank van Puffelen Oct 02 '19 at 19:05

0 Answers0