RLH RLH - 2 months ago 25
Python Question

Cross Group (XG) Transactions and Further Explanation of use

The most recent release of the GAE states the following changes:


Cross Group (XG) Transactions: For those who need transactional writes
to entities in multiple entity groups (and that's everyone, right?),
XG Transactions are just the thing. This feature uses two phase commit
to make cross group writes atomic just like single group writes.

I think I could use this change within the code of a project I created a while ago but I would like further information regarding this update to the App Engine. I can't seem to find any additional information. So...

How has coding transactions changed, in regards to this update? In layman's terms, how can I implement a cross-group transaction and are there still some limitations to data store transactions that I need to be aware of?

I know this is a rather vague question. My problem is that this sounds very useful, but I'm not sure how to correctly (and effectively) use this change.


Have you read any of the docs? It sounds like you haven't (based on you saying "I can't seem to find any additional information"). In that case, check out the links below and see if still have any questions.

Conceptually, doing a cross group transaction is pretty similar to a typical GAE transaction, just slower, and only available in the HRD. Note that in general, GAE transactions, both "normal" and XG have different isolation characteristics than what you may be used to coming from a SQL database. The second link discusses this immediately after the XG section.

Here is an excerpt from the first link showing how simple using XG can be.

from google.appengine.ext import db

xg_on = db.create_transaction_options(xg=True)

def my_txn():
    x = MyModel(a=3)
    y = MyModel(a=7)

db.run_in_transaction_options(xg_on, my_txn)