views:

124

answers:

2

in my google app application, whenever a user purchases a number of contracts, these events are executed (simplified for clarity):

  • user.cash is decreased
  • user.contracts is increased by the number
  • contracts.current_price is updated.
  • market.no_of_transactions is increased by 1.

in a rdms, these would be placed within the same transaction. I conceive that google datastore does not allow entities of more than one model to be in the same transaction.

what is the correct approach to this issue? how can I ensure that if a write fails, all preceding writes are rolled back?

edit: I have obviously missed entity groups. Now I'd appreciate some further information regarding how they are used. Another point to clarify is google says "Only use entity groups when they are needed for transactions. For other relationships between entities, use ReferenceProperty properties and Key values, which can be used in queries". does it mean I have to define both a reference property (since I need queriying them) and a parent-child relationship (for transactions)?

edit 2: and finally, how do I define two parents for an entity if the entity is being created to establish an n-to-n relationship between 2 parents?

A: 

After a through research, I have found that a distributed transaction layer that provides a solution to the single entity group restriction has been developed in userland with the help of some google people. But so far, it is not released and is only available in java.

shanyu
A: 

Let me add a quote from the Datastore documentation:

A good rule of thumb for entity groups is that they should be about the size of a single user's worth of data or smaller.

You could create a pseudo root entity and put everything below this. Then, you execute everything in a transaction.

Manuel