Search code examples
google-cloud-platformgoogle-cloud-firestoregoogle-cloud-datastore

Has the transaction behavior changed when a conflict occurred in firestore datastore?


I created new Google Cloud Platform project and Datastore.

Datastore was created as "Firestore in Datastore mode".

But, I think Firestore Datastore and Old Datastore behave differently if Conflict occurred.

e.g Following case.

procA: -> enter transaction -> get -> put -----------------> exit transaction
procB: -----> enter transaction -> get -> put -> exit transaction

Old Datastore;

  • procB is Completed and data is updated.
  • procA Conflict occured and data is rollbacked.

Firestore in Datastore mode;

  • procB is waited before exit transaction until procA is completed.Then Conflict occured.
  • procA Completed and data is updated.

Is it spec? I cannot find document on Google Cloud Platform documentation.


Solution

  • I've been giving it some thought and I think the change may actually be intentional.

    In the old behaviour that you describe basically the shorter transaction, even if it starts after the longer does, is successful, preempting the longer one and causing it to fail and be re-tried. Effectively this give priority to the shorter transactions.

    But imagine that you have a peak of activity with a bunch of shorter transactions - they will keep preempting the longer one(s) which will keep being re-tried until eventually reaching the maximum retries limit and failing permanently. Also increasing the datastore contention in the process, due to the retries. I actually hit such scenario in my transaction-heavy app, I had to adjust my algorithms to work around it.

    By contrast the new behaviour gives all transactions a fair chance of success, regardless of their duration or the level of activity - no priority handling. It's true, at a price - the shorter transactions started after the longer ones and overlapping them will take overall longer. IMHO the new behaviour is preferable to the older one.