3
votes

Where — on what level — the locking and collisions occur in transactional operations on the same entity group? At root? At some common, wide enough parent?

It's not clear to me what is an "Entity Group" for a transaction. Is it always a group originating at a root entity (without parent) or is there a mechanism that selects a group wide enough for transaction.

For example when I have a model structure like this:

- School
  - Teacher
  - Class
    - Course
      - Lesson
      - Evaluation
    - Student
      - Guardian 
      - Grade
      - PresenceMarker
    - TextBook

Do my transactional operations always refer to "Entity Group" as a group originating at a school level (regardless of the level where actual operation occur), or when I update students entities in the same class, I can only collide with with other transactional operation occurring below the same class entity.

In other words is there only one entity group staring from School or are there sub entity groups originating at every other level in the hierarchy? If there are sub entity groups, are they used in the for transaction isolation?

UPDATE:

Taking Sharding counters as an another example. Will the sharding work if all the shards have common parent? Will updating a single counter shard result in transaction collisions updates on other shards?

2
While Peter's answer correctly says that transactions among different shards won't collide, the sample code for Sharding Counters doesn't handle collisions within a shard. I created a project to verify this and measure the collision rate. Details here: github.com/hrj/gae_tx_test - HRJ

2 Answers

2
votes

Transactions in App Engine happen at the Entity Group level. (see docs here and here)

are there sub entity groups originating at every other level in the hierarchy?

There are no "sub entity groups". Every entity is in exactly one Entity Group, because it has one ultimate ancestor. In your example, all your models ultimately belong in the School's group.

Will the sharding work if all the shards have common parent?

For sharding to work as intended, each shard must be in its own Entity Group. If you look at the sample code, you can see that each shard is in its own group. You can also see that while the increment() method uses a transaction, the get_count() does not. The increment is only affecting one group, while the get_count is grabbing data from multiple groups.

Note: The latest release of App Engine allows for cross group transactions, but those are a special case, and the definition of a group has not changed.

0
votes

As far as I understood the docs GAE always uses the root of the entity group tree for its journal, which manages locks and transactions.