views:

23

answers:

2

I want to do several operations on a user's data in a single transaction, but won't need to update multiple users' data in a single transaction. I see from http://code.google.com/appengine/docs/python/datastore/keysandentitygroups.html#Entity_Groups_Ancestors_and_Paths that "A good rule of thumb for entity groups is that [entity groups] should be about the size of a single user's worth of data or smaller," so I think the correct choice is to use a single parent key when building the keys for the other entities related to a user.

  1. Does this seem like a good idea?
  2. Is it easy to code? Something like KeyBuilder.setParent(theKeyOfMyUserEntity)?
+3  A: 

1) It is hard to comment without some addition details about the data. There are several things you should be aware of with entity groups; the biggest is that the group will be stored together. That means if you are trying to do many (separate) updates you could face contention, limiting your app's performance.

2) yes it is easy to code. The syntax is pretty close to what you posted.

There are other options for transactions. Check out Nick Johnson's article on distributed transactions. If you are wanting transactions for aggregates you should also check out Brett Slatkin's IO talk on high-throughput data pipelines.

Robert Kluin
Riley
+2  A: 
  1. Yes, it seems reasonable to store some user data as child entities of a User entity.

  2. Why do you need to manually create keys ? The db.Model() constructor already has a convenient "parent" argument which will automatically put both the parent entity and the child entity in the same entity group.

Franck
I think he is using Java, based on his reference to KeyBuilder. So he does not have a parent arg for his model constructors. But Java does support some other easy ways to define entity groups too (http://code.google.com/appengine/docs/java/datastore/relationships.html).
Robert Kluin
Do you know of equivalent code in Java? I think KeyBuilder might be the shortest way to do it.
Riley
If you will be assigning key names, then check out the section titled *Creating Entities With Entity Groups* (http://code.google.com/appengine/docs/java/datastore/transactions.html). If you will not then read over the relationships docs. The stuff on owned relationships is what you'll want. (http://code.google.com/appengine/docs/java/datastore/relationships.html)
Robert Kluin