2
votes

In Google App Engine, all datastore operations in a transaction must operate on entities within the same group.

I don't understand why this is a useful constraint for transactions. It seems unnecessary since the datastore could know which entities to lock based on what happens in the transaction.

How does grouping entities together improve datastore's operations during transactions?

1

1 Answers

3
votes

It's useful to think of App Engine's datastore as a giant hashmap. All you can do is put, get & delete key-value pairs. Often the key is auto-created, and usually the value is a serialized object, but it's still all a humungous key-value pair store. A hashmap.

Now this big hashmap has one (and only one) option for transactions: you can atomically manipulate one key-value pair at a time. No choices, ifs or buts - a transaction is something that applies to a single pair.

Of course, your value can be anything. It doesn't have to be a single object. It could be a hierarchical tree of objects. That's an entity group. It's a trick that says, "I have to manipulate these objects in a transaction, so I'll have to make them look like a single value. I'll just stick them into a parent object and store that."

So entity groups aren't created as a useful way of doing transactions. Entities are grouped because it's the only way to put them in a transaction.